From b26a5a95617256e284b19e5f36363fe9343cdaab Mon Sep 17 00:00:00 2001 From: Globox1997 Date: Sat, 5 Oct 2024 17:28:07 +0200 Subject: [PATCH] moved to central method --- .../villager/task/BuilderBreakTask.java | 9 +-------- .../villager/task/BuilderBuildTask.java | 9 ++------- .../villager/task/BuilderCollectTask.java | 19 +++++------------- .../entity/villager/task/BuilderDumpTask.java | 9 +-------- .../mayor/util/TaskHelper.java | 20 +++++++++++++++++++ 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBreakTask.java b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBreakTask.java index 1a4d795..ef57699 100644 --- a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBreakTask.java +++ b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBreakTask.java @@ -100,14 +100,7 @@ protected void finishRunning(ServerWorld serverWorld, VillagerEntity villagerEnt if (villagerEntity instanceof Builder builder) { builder.setTaskValue(0); - if (!builder.getBuilderInventory().isEmpty() && builder.getCarryItemStack().isEmpty()) { - for (ItemStack stack : builder.getBuilderInventory().getHeldStacks()) { - if (!stack.isEmpty() && stack.getItem() instanceof BlockItem && stack.isIn(TagProvider.ItemTags.CARRIABLE)) { - builder.setCarryItemStack(stack); - break; - } - } - } + TaskHelper.updateCarryItemStack(villagerEntity); } System.out.println("FINISH BUILDER BREAK"); } diff --git a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBuildTask.java b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBuildTask.java index e9bf92f..8f932f2 100644 --- a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBuildTask.java +++ b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderBuildTask.java @@ -97,13 +97,8 @@ protected void finishRunning(ServerWorld serverWorld, VillagerEntity villagerEnt this.currentTarget = null; this.constructionData = null; - if (villagerEntity instanceof Builder builder) { - if (builder.getBuilderInventory().isEmpty()) { - builder.setCarryItemStack(ItemStack.EMPTY); - } else { - System.out.println("SHOULD BE EMPTY: " + builder.getBuilderInventory() + " : " + builder.getCarryItemStack() + " : " + builder.getBuilderInventory().isEmpty()); - } - } + TaskHelper.updateCarryItemStack(villagerEntity); + villagerEntity.getBrain().forget(MayorVillagerUtilities.BUSY); System.out.println("END BUILDER BUILD"); } diff --git a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderCollectTask.java b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderCollectTask.java index 66c767b..47d534e 100644 --- a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderCollectTask.java +++ b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderCollectTask.java @@ -173,16 +173,7 @@ protected void finishRunning(ServerWorld serverWorld, VillagerEntity villagerEnt villagerEntity.getBrain().forget(MayorVillagerUtilities.BUSY); - if (villagerEntity instanceof Builder builder && !builder.getBuilderInventory().isEmpty() && builder.getCarryItemStack().isEmpty()) { - for (ItemStack stack : builder.getBuilderInventory().getHeldStacks()) { - if (!stack.isEmpty() && stack.getItem() instanceof BlockItem && stack.isIn(TagProvider.ItemTags.CARRIABLE)) { - builder.setCarryItemStack(stack); - System.out.println("CARRY LOL " + stack); - break; - } - } - System.out.println("SET COLLECT CARRY: " + builder.getCarryItemStack()); - } + TaskHelper.updateCarryItemStack(villagerEntity); System.out.println("FINISH BUILDER COLLECT"); } @@ -228,8 +219,8 @@ protected void keepRunning(ServerWorld serverWorld, VillagerEntity villagerEntit //// break; //// } // } - System.out.println("REAL MISSING?: "+missingItemStacks); - System.out.println("CONTAINER: "+villageContainerBlockEntity.getItems()); + System.out.println("REAL MISSING?: " + missingItemStacks); + System.out.println("CONTAINER: " + villageContainerBlockEntity.getItems()); // builder.getBuilderInventory(). List requiredStacks = InventoryUtil.getRequiredItems(villageContainerBlockEntity.getItems(), missingItemStacks); @@ -242,9 +233,9 @@ protected void keepRunning(ServerWorld serverWorld, VillagerEntity villagerEntit builder.getBuilderInventory().addStack(requiredStack.copy()); villageContainerBlockEntity.removeStack(requiredStack); - System.out.println("REMOVE STACK FROM VILLAGE CONTAINER BLOCK: "+requiredStack); + System.out.println("REMOVE STACK FROM VILLAGE CONTAINER BLOCK: " + requiredStack); } else { - System.out.println("AFTER FILLING VIL INV: "+villageContainerBlockEntity.getItems()); + System.out.println("AFTER FILLING VIL INV: " + villageContainerBlockEntity.getItems()); break; } } diff --git a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderDumpTask.java b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderDumpTask.java index 8561806..3a21dcf 100644 --- a/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderDumpTask.java +++ b/src/main/java/io/fabricatedatelier/mayor/entity/villager/task/BuilderDumpTask.java @@ -123,20 +123,13 @@ protected void finishRunning(ServerWorld serverWorld, VillagerEntity villagerEnt villagerEntity.getBrain().forget(MemoryModuleType.LOOK_TARGET); villagerEntity.getBrain().forget(MemoryModuleType.WALK_TARGET); -// if (villagerEntity instanceof Builder builder && builder.getBuilderInventory().isEmpty()) { -// villagerEntity.getBrain().forget(MayorVillagerUtilities.SHOULD_DUMP); -// } this.ticksRan = 0; this.currentTarget = null; this.nextResponseTime = time + 60L; villagerEntity.getBrain().forget(MayorVillagerUtilities.BUSY); System.out.println("FINISH BUILDER DUMP"); - if (villagerEntity instanceof Builder builder) { - if (builder.getBuilderInventory().isEmpty()) { - builder.setCarryItemStack(ItemStack.EMPTY); - } - } + TaskHelper.updateCarryItemStack(villagerEntity); } @Override diff --git a/src/main/java/io/fabricatedatelier/mayor/util/TaskHelper.java b/src/main/java/io/fabricatedatelier/mayor/util/TaskHelper.java index b3d1cd7..9e29b43 100644 --- a/src/main/java/io/fabricatedatelier/mayor/util/TaskHelper.java +++ b/src/main/java/io/fabricatedatelier/mayor/util/TaskHelper.java @@ -1,9 +1,13 @@ package io.fabricatedatelier.mayor.util; +import io.fabricatedatelier.mayor.datagen.TagProvider; +import io.fabricatedatelier.mayor.entity.villager.access.Builder; import io.fabricatedatelier.mayor.state.ConstructionData; import net.minecraft.entity.ai.pathing.Path; import net.minecraft.entity.mob.PathAwareEntity; import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockBox; import net.minecraft.util.math.BlockPos; @@ -80,4 +84,20 @@ public static BlockPos findClosestTarget(ServerWorld serverWorld, VillagerEntity return null; } + public static void updateCarryItemStack(VillagerEntity villagerEntity) { + if (villagerEntity instanceof Builder builder) { + if (builder.getBuilderInventory().isEmpty()) { + builder.setCarryItemStack(ItemStack.EMPTY); + } else { + for (ItemStack stack : builder.getBuilderInventory().getHeldStacks()) { + if (!stack.isEmpty() && stack.getItem() instanceof BlockItem && stack.isIn(TagProvider.ItemTags.CARRIABLE)) { + builder.setCarryItemStack(stack); + System.out.println("CARRY LOL " + stack); + break; + } + } + } + } + } + }