Fix #476 - Calming iron golom with rose doesnt consume item

This commit is contained in:
William Blake Galbreath
2021-07-05 20:40:24 -05:00
parent 9ea44be118
commit a0fae1b779

View File

@@ -38,14 +38,15 @@ index 2c790011043065158a1ab092aa417fd8df45f246..1ca8fe623c69d5149d22902087be6a08
public boolean llamaRidable = false;
diff --git a/src/main/java/net/pl3x/purpur/entity/ai/ReceiveFlower.java b/src/main/java/net/pl3x/purpur/entity/ai/ReceiveFlower.java
new file mode 100644
index 0000000000000000000000000000000000000000..f2f04547509b48c4c13b21e35d77c0ed36086f6b
index 0000000000000000000000000000000000000000..efbf2775558e61310dff900a0321964c63f4551d
--- /dev/null
+++ b/src/main/java/net/pl3x/purpur/entity/ai/ReceiveFlower.java
@@ -0,0 +1,78 @@
@@ -0,0 +1,91 @@
+package net.pl3x.purpur.entity.ai;
+
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.ai.goal.Goal;
+import net.minecraft.world.entity.animal.IronGolem;
@@ -81,9 +82,11 @@ index 0000000000000000000000000000000000000000..f2f04547509b48c4c13b21e35d77c0ed
+ if (!(target instanceof ServerPlayer player)) {
+ return false;
+ }
+ if (!isOfferingFlower(player)) {
+ InteractionHand hand = getPoppyHand(player);
+ if (hand == null) {
+ return false;
+ }
+ removeFlower(player, hand);
+ this.target = player;
+ return true;
+ }
@@ -112,8 +115,18 @@ index 0000000000000000000000000000000000000000..f2f04547509b48c4c13b21e35d77c0ed
+ --this.cooldown;
+ }
+
+ private boolean isOfferingFlower(ServerPlayer player) {
+ return isPoppy(player.getMainHandItem()) || isPoppy(player.getOffhandItem());
+ private InteractionHand getPoppyHand(ServerPlayer player) {
+ if (isPoppy(player.getMainHandItem())) {
+ return InteractionHand.MAIN_HAND;
+ }
+ if (isPoppy(player.getOffhandItem())) {
+ return InteractionHand.OFF_HAND;
+ }
+ return null;
+ }
+
+ private void removeFlower(ServerPlayer player, InteractionHand hand) {
+ player.setItemInHand(hand, ItemStack.EMPTY);
+ }
+
+ private boolean isPoppy(ItemStack item) {