Skip to content

Commit

Permalink
moved to central method
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Oct 5, 2024
1 parent cf18b50 commit b26a5a9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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<ItemStack> requiredStacks = InventoryUtil.getRequiredItems(villageContainerBlockEntity.getItems(), missingItemStacks);

Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/fabricatedatelier/mayor/util/TaskHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
}
}
}

}

0 comments on commit b26a5a9

Please sign in to comment.