Add deployer feeding

This commit is contained in:
Snownee 2020-05-19 02:06:22 +08:00
parent 282445d2ac
commit f08a574653
2 changed files with 15 additions and 0 deletions

View file

@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -87,6 +88,11 @@ public class DeployerFakePlayer extends FakePlayer {
return false; return false;
} }
@Override
public ItemStack onFoodEaten(World world, ItemStack stack) {
return stack;
}
@SubscribeEvent @SubscribeEvent
public static void deployerHasEyesOnHisFeet(EntityEvent.EyeHeight event) { public static void deployerHasEyesOnHisFeet(EntityEvent.EyeHeight event) {
if (event.getEntity() instanceof DeployerFakePlayer) if (event.getEntity() instanceof DeployerFakePlayer)

View file

@ -20,6 +20,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
@ -137,6 +138,14 @@ public class DeployerHandler {
&& stack.interactWithEntity(player, (LivingEntity) entity, hand)) && stack.interactWithEntity(player, (LivingEntity) entity, hand))
success = true; success = true;
} }
if (!success && stack.isFood() && entity instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) entity;
if (playerEntity.canEat(item.getFood().canEatWhenFull())) {
playerEntity.onFoodEaten(world, stack);
player.spawnedItemEffects = stack.copy();
success = true;
}
}
} }
// Punch entity // Punch entity