Initial commit
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
package com.kasetoatz.hungryfrog.mixin;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.brain.Activity;
|
||||
import net.minecraft.entity.ai.brain.Brain;
|
||||
import net.minecraft.entity.ai.brain.sensor.Sensor;
|
||||
import net.minecraft.entity.ai.brain.sensor.SensorType;
|
||||
import net.minecraft.entity.ai.brain.task.Task;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Mixin(Brain.class)
|
||||
public interface BrainAccessor<E extends LivingEntity>
|
||||
{
|
||||
@Accessor("sensors")
|
||||
Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> getSensors();
|
||||
|
||||
@Accessor("tasks")
|
||||
Map<Integer, Map<Activity, Set<Task<? super E>>>> getTasks();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.kasetoatz.hungryfrog.mixin;
|
||||
|
||||
import com.kasetoatz.hungryfrog.HungryFrog;
|
||||
import com.kasetoatz.hungryfrog.sensor.NearestBlockSensor;
|
||||
import com.kasetoatz.hungryfrog.task.FrogEatBlockTask;
|
||||
import net.minecraft.entity.ai.brain.Activity;
|
||||
import net.minecraft.entity.ai.brain.Brain;
|
||||
import net.minecraft.entity.passive.FrogBrain;
|
||||
import net.minecraft.entity.passive.FrogEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
@Mixin(FrogBrain.class)
|
||||
public class FrogBrainMixin
|
||||
{
|
||||
@Inject(method = "create", at = @At("RETURN"), cancellable = true)
|
||||
private static void create(Brain<FrogEntity> brain, CallbackInfoReturnable<Brain<?>> cir)
|
||||
{
|
||||
Brain<?> frog = cir.getReturnValue();
|
||||
@SuppressWarnings("unchecked")
|
||||
BrainAccessor<FrogEntity> accessor = (BrainAccessor<FrogEntity>) frog;
|
||||
accessor.getSensors().put(HungryFrog.NEAREST_BLOCK_SENSOR, new NearestBlockSensor());
|
||||
accessor.getTasks().computeIfAbsent(1, p -> new HashMap<>()).computeIfAbsent(Activity.IDLE, a -> new LinkedHashSet<>()).add(new FrogEatBlockTask());
|
||||
cir.setReturnValue(frog);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.kasetoatz.hungryfrog.mixin;
|
||||
|
||||
import com.kasetoatz.hungryfrog.HungryFrog;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.brain.Brain;
|
||||
import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||
import net.minecraft.entity.ai.brain.sensor.Sensor;
|
||||
import net.minecraft.entity.ai.brain.sensor.SensorType;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.passive.FrogEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Mixin(FrogEntity.class)
|
||||
public class FrogEntityMixin
|
||||
{
|
||||
@Inject(method = "isValidFrogFood", at = @At("HEAD"), cancellable = true)
|
||||
private static void isValidFrogFood(LivingEntity entity, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
cir.setReturnValue(!(entity instanceof FrogEntity));
|
||||
}
|
||||
|
||||
@Inject(method = "createFrogAttributes", at = @At("RETURN"), cancellable = true)
|
||||
private static void createFrogAttributes(CallbackInfoReturnable<DefaultAttributeContainer.Builder> cir)
|
||||
{
|
||||
DefaultAttributeContainer.Builder attr = cir.getReturnValue();
|
||||
attr.add(EntityAttributes.ATTACK_DAMAGE, Double.MAX_VALUE);
|
||||
cir.setReturnValue(attr);
|
||||
}
|
||||
|
||||
@Inject(method = "createBrainProfile", at = @At("RETURN"), cancellable = true)
|
||||
private void createBrainProfile(CallbackInfoReturnable<Brain.Profile<FrogEntity>> cir)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
ProfileAccessor<FrogEntity> profile = (ProfileAccessor<FrogEntity>)(Object)cir.getReturnValue();
|
||||
if (profile != null)
|
||||
{
|
||||
ArrayList<MemoryModuleType<?>> memories = new ArrayList<>(profile.getMemoryModules());
|
||||
ArrayList<SensorType<? extends Sensor<? super FrogEntity>>> sensors = new ArrayList<>(profile.getSensors());
|
||||
memories.add(HungryFrog.BLOCK_TO_EAT);
|
||||
memories.add(HungryFrog.UNREACHABLE_BLOCK_TARGETS);
|
||||
sensors.add(HungryFrog.NEAREST_BLOCK_SENSOR);
|
||||
cir.setReturnValue(Brain.createProfile(memories, sensors));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.kasetoatz.hungryfrog.mixin;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.passive.FrogEntity;
|
||||
import net.minecraft.registry.tag.DamageTypeTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin {
|
||||
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
|
||||
private void damage(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
if ((LivingEntity)(Object)this instanceof FrogEntity && source.isIn(DamageTypeTags.IS_FIRE)) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.kasetoatz.hungryfrog.mixin;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.brain.Brain;
|
||||
import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||
import net.minecraft.entity.ai.brain.sensor.Sensor;
|
||||
import net.minecraft.entity.ai.brain.sensor.SensorType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import java.util.Collection;
|
||||
|
||||
@Mixin(Brain.Profile.class)
|
||||
public interface ProfileAccessor<E extends LivingEntity>
|
||||
{
|
||||
@Accessor("memoryModules")
|
||||
Collection<? extends MemoryModuleType<?>> getMemoryModules();
|
||||
|
||||
@Accessor("sensors")
|
||||
Collection<? extends SensorType<? extends Sensor<? super E>>> getSensors();
|
||||
}
|
Reference in New Issue
Block a user