From f08a5746534a810dac22d1aa7fb4b53723d613ab Mon Sep 17 00:00:00 2001 From: Snownee <1850986885@qq.com> Date: Tue, 19 May 2020 02:06:22 +0800 Subject: [PATCH] Add deployer feeding --- .../components/deployer/DeployerFakePlayer.java | 6 ++++++ .../components/deployer/DeployerHandler.java | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java index ec3768403..bd8fd3288 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java @@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; +import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -87,6 +88,11 @@ public class DeployerFakePlayer extends FakePlayer { return false; } + @Override + public ItemStack onFoodEaten(World world, ItemStack stack) { + return stack; + } + @SubscribeEvent public static void deployerHasEyesOnHisFeet(EntityEvent.EyeHeight event) { if (event.getEntity() instanceof DeployerFakePlayer) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java index 5c6b9a069..d19f330a0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java @@ -20,6 +20,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.inventory.EquipmentSlotType; @@ -137,6 +138,14 @@ public class DeployerHandler { && stack.interactWithEntity(player, (LivingEntity) entity, hand)) 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