Skip to content

Commit

Permalink
Make Sifter use real items as meshes (ldtteam#6687)
Browse files Browse the repository at this point in the history
Create new "mesh" items with durability for the sifter to use, updating and adding recipes to support it
Fix tool damage to work when the tool isn't in the citizen's inventory.
Make custom recipes add at the top of the list, so later levels take precedence
Make the prestock code ignore damage, to not request new meshes as soon as the current one is damaged
Add Achievements tree to University, for hidden/autostart/instant researches to unlock things like recipes
Wire up meshes to block on new "Achievements" in the university
The meshes are made by other crafters as such:

String Mesh at the Fletcher with 500 durability
Flint Mesh at the Stonemason with 1000 durability
Iron Mesh at the Blacksmith with 1500 durability
Diamond Mesh at the Mechanic with 2000 durability
  • Loading branch information
Mekle001 authored Mar 13, 2021
1 parent 3bd7c3e commit ac57ddd
Show file tree
Hide file tree
Showing 66 changed files with 884 additions and 337 deletions.
12 changes: 11 additions & 1 deletion src/api/java/com/minecolonies/api/crafting/RecipeStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,17 @@ public boolean fullfillRecipe(final LootContext context, final List<IItemHandler
{
if(citizen != null && ItemStackUtils.compareItemStackListIgnoreStackSize(tools, stack, false, true) && ItemStackUtils.getDurability(handler.getStackInSlot(slotOfStack)) > 0 )
{
citizen.getInventoryCitizen().damageInventoryItem(slotOfStack, 1, citizen, item -> item.sendBreakAnimation(Hand.MAIN_HAND));
ItemStack toDamage = handler.extractItem(slotOfStack,1, false);
if (!ItemStackUtils.isEmpty(toDamage))
{
// The 4 parameter inner call from forge is for adding a callback to alter the damage caused,
// but unlike its description does not actually damage the item(despite the same function name). So used to just calculate the damage.
toDamage.damageItem(toDamage.getItem().damageItem(stack, 1, citizen, item -> item.sendBreakAnimation(Hand.MAIN_HAND)), citizen, item -> item.sendBreakAnimation(Hand.MAIN_HAND));
}
if (!ItemStackUtils.isEmpty(toDamage))
{
handler.insertItem(slotOfStack, toDamage, false);
}
amountNeeded -= stack.getCount();
}
else
Expand Down
5 changes: 5 additions & 0 deletions src/api/java/com/minecolonies/api/items/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public final class ModItems
public static Item scrollGuardHelp;
public static Item scrollHighLight;

public static Item sifterMeshString;
public static Item sifterMeshFlint;
public static Item sifterMeshIron;
public static Item sifterMeshDiamond;

/**
* Private constructor to hide the implicit public one.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/api/java/com/minecolonies/api/items/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ModTags

public static ITag<Item> fungi;

public static ITag<Item> meshes;

public static ITag<Item> floristFlowersExcluded;


Expand Down
2 changes: 1 addition & 1 deletion src/api/java/com/minecolonies/api/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ public static int hasBuildingEnoughElseCount(@NotNull final IBuilding provider,
}
else if (entity instanceof ChestTileEntity)
{
totalCount += getItemCountInProvider(entity, itemStack -> itemStack.isItemEqual(stack.getItemStack()));
totalCount += getItemCountInProvider(entity, itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack.getItemStack(), !stack.ignoreDamageValue(), !stack.ignoreNBT() ));
}

if (totalCount > count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"com.minecolonies.research.civilian.name": "Civilian",
"com.minecolonies.research.combat.name": "Combat",
"com.minecolonies.research.technology.name": "Technology",
"com.minecolonies.research.unlockable.name": "Unlockables",
"com.minecolonies.research.effects.archerarmormultiplier.description": "Archer Armor +%3$s%%",
"com.minecolonies.research.effects.archerdamageaddition.description": "Archer Damage +%s",
"com.minecolonies.research.effects.armordurabilitymultiplier.description": "Guard Armor +%3$s%% Durability",
Expand Down Expand Up @@ -68,6 +69,10 @@
"com.minecolonies.research.effects.knowledgeoftheendunlock.description": "Stonemasons Learn Endstone Recipe and Bakers Learn Chorus Bread Recipe",
"com.minecolonies.research.effects.morescrollsunlock.description": "Enchanter Learns Scroll Recipes to Locate Workers and Summon Guards",
"com.minecolonies.research.effects.platearmorunlock.description": "Blacksmith Learns Plate Armor Recipes",
"com.minecolonies.research.effects.sifterstringunlock.description": "Fletcher Learns How to Make String Meshes for the Sifter",
"com.minecolonies.research.effects.sifterflintunlock.description": "Stonemason Learns How to Make Flint Meshes for the Sifter",
"com.minecolonies.research.effects.sifterironunlock.description": "Blacksmith Learns How to Make Iron Meshes for the Sifter",
"com.minecolonies.research.effects.sifterdiamondunlock.description": "Mechanic Learns How to Make Diamond Meshes for the Sifter",
"com.minecolonies.research.civilian.stamina.name": "Stamina",
"com.minecolonies.research.civilian.bandaid.name": "Band Aid",
"com.minecolonies.research.civilian.healingcream.name": "Healing Cream",
Expand Down Expand Up @@ -311,5 +316,9 @@
"com.minecolonies.research.technology.whatyaneed.name": "What ya Need?",
"com.minecolonies.research.technology.whatyaneed.subtitle": "It's not a rhetorical question...",
"com.minecolonies.research.technology.enhanced_gates1.name": "Enhanced Gates I",
"com.minecolonies.research.technology.enhanced_gates2.name": "Enhanced Gates II"
"com.minecolonies.research.technology.enhanced_gates2.name": "Enhanced Gates II",
"com.minecolonies.research.unlockable.stringmesh.name": "String Mesh",
"com.minecolonies.research.unlockable.flintmesh.name": "Flint Mesh",
"com.minecolonies.research.unlockable.ironmesh.name": "Iron Mesh",
"com.minecolonies.research.unlockable.diamondmesh.name": "Diamond Mesh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"effect": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"effect": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"effect": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"effect": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"branch-name": "com.minecolonies.research.unlockable.name",
"base-time": 0.0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"branch": "minecolonies:unlockable",
"researchLevel": 1,
"icon": "minecolonies:sifter_mesh_string",
"requirements": [
{
"mandatory-building": "sifter",
"level": 5
}
],
"hidden": true,
"autostart": true,
"instant": true,
"effects": [
{
"minecolonies:effects/sifterdiamondunlock": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"branch": "minecolonies:unlockable",
"researchLevel": 1,
"icon": "minecolonies:sifter_mesh_string",
"requirements": [
{
"mandatory-building": "sifter",
"level": 3
}
],
"hidden": true,
"autostart": true,
"instant": true,
"effects": [
{
"minecolonies:effects/sifterflintunlock": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"branch": "minecolonies:unlockable",
"researchLevel": 1,
"icon": "minecolonies:sifter_mesh_string",
"requirements": [
{
"mandatory-building": "sifter",
"level": 4
}
],
"hidden": true,
"autostart": true,
"instant": true,
"effects": [
{
"minecolonies:effects/sifterironunlock": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"branch": "minecolonies:unlockable",
"researchLevel": 1,
"icon": "minecolonies:sifter_mesh_string",
"requirements": [
{
"mandatory-building": "sifter",
"level": 1
}
],
"hidden": true,
"autostart": true,
"instant": true,
"effects": [
{
"minecolonies:effects/sifterstringunlock": 1
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public static void init(final IForgeRegistry<Item> registry)
ModItems.plateArmorLegs = new ItemPlateArmor("plate_armor_legs", ModCreativeTabs.MINECOLONIES, ItemPlateArmor.PLATE_ARMOR, EquipmentSlotType.LEGS, new Item.Properties());
ModItems.plateArmorBoots = new ItemPlateArmor("plate_armor_boots", ModCreativeTabs.MINECOLONIES, ItemPlateArmor.PLATE_ARMOR, EquipmentSlotType.FEET, new Item.Properties());

ModItems.sifterMeshString = new ItemSifterMesh("sifter_mesh_string", new Item.Properties().maxDamage(500).setNoRepair());
ModItems.sifterMeshFlint = new ItemSifterMesh("sifter_mesh_flint", new Item.Properties().maxDamage(1000).setNoRepair());
ModItems.sifterMeshIron = new ItemSifterMesh("sifter_mesh_iron", new Item.Properties().maxDamage(1500).setNoRepair());
ModItems.sifterMeshDiamond = new ItemSifterMesh("sifter_mesh_diamond", new Item.Properties().maxDamage(2000).setNoRepair());

registry.register(ModItems.supplyChest);
registry.register(ModItems.permTool);
registry.register(ModItems.scepterGuard);
Expand Down Expand Up @@ -163,6 +168,11 @@ public static void init(final IForgeRegistry<Item> registry)
registry.register(ModItems.woodgate);
registry.register(ModItems.flagBanner);

registry.register(ModItems.sifterMeshString);
registry.register(ModItems.sifterMeshFlint);
registry.register(ModItems.sifterMeshIron);
registry.register(ModItems.sifterMeshDiamond);

registry.register(new SpawnEggItem(ModEntities.BARBARIAN,
PRIMARY_COLOR_BARBARIAN,
SECONDARY_COLOR_BARBARIAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ModTagsInitializer
private static final ResourceLocation COLONYPROTECTIONEXCEPTION = new ResourceLocation(MOD_ID, "protectionexception");
private static final ResourceLocation FUNGI = new ResourceLocation(MOD_ID, "fungi");
private static final ResourceLocation INDESTRUCTIBLE = new ResourceLocation(MOD_ID, "indestructible");
private static final ResourceLocation MESHES = new ResourceLocation(MOD_ID, "meshes");

private static boolean loaded = false;

Expand All @@ -66,6 +67,7 @@ public static void init()
ModTags.compostables = getItemTags(COMPOSTABLES);
ModTags.floristFlowersExcluded = getItemTags(FLORIST_FLOWERS_EXCLUDED);
ModTags.fungi = getItemTags(FUNGI);
ModTags.meshes = getItemTags(MESHES);
ModTags.oreChanceBlocks = getBlockTags(ORECHANCEBLOCKS);
ModTags.colonyProtectionException = getBlockTags(COLONYPROTECTIONEXCEPTION);
ModTags.indestructible = getBlockTags(INDESTRUCTIBLE);
Expand Down
117 changes: 7 additions & 110 deletions src/main/java/com/minecolonies/coremod/client/gui/WindowHutSifter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
*/
public class WindowHutSifter extends AbstractWindowWorkerBuilding<BuildingSifter.View>
{
/**
* The mode button id.
*/
private static final String MESH_BUTTON = "buyMesh";

/**
* The save button id.
*/
Expand All @@ -54,16 +49,6 @@ public class WindowHutSifter extends AbstractWindowWorkerBuilding<BuildingSifter
*/
private static final String LABEL_LIMIT_REACHED = "com.minecolonies.coremod.gui.warehouse.limitreached";

/**
* The list of meshes.
*/
private final ScrollingList meshList;

/**
* The current sifter mesh.
*/
private ItemStorage mesh;

/**
* Resource scrolling list.
*/
Expand All @@ -78,12 +63,12 @@ public WindowHutSifter(final BuildingSifter.View building)
{
super(building, Constants.MOD_ID + SIFTER_RESOURCE_SUFFIX);
final TextField sifterSettingsInput = findPaneOfTypeByID(QTY_INPUT, TextField.class);
meshList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
resourceList = findPaneOfTypeByID("resourcesstock", ScrollingList.class);

registerButton(MESH_BUTTON, this::switchMesh);
registerButton(BUTTON_SAVE, this::save);
mesh = building.getMesh();

final ButtonImage saveButton = findPaneOfTypeByID(BUTTON_SAVE, ButtonImage.class);
saveButton.setVisible(false);

final Text label = findPaneOfTypeByID("maxSifted", Text.class);
if (building.getMaxDailyQuantity() == Integer.MAX_VALUE)
Expand All @@ -95,9 +80,8 @@ public WindowHutSifter(final BuildingSifter.View building)
label.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.workerhuts.sifterinfo", building.getMaxDailyQuantity()));
}

sifterSettingsInput.setText(String.valueOf(building.getDailyQuantity()));

updateResourceList();
sifterSettingsInput.setText(String.valueOf(building.getCurrentDailyQuantity()));
sifterSettingsInput.setEnabled(false);

registerButton(STOCK_ADD, this::addStock);
if (building.hasReachedLimit())
Expand All @@ -112,102 +96,15 @@ public WindowHutSifter(final BuildingSifter.View building)
}

/**
* Updates the resource list in the GUI with the info we need.
*/
private void updateResourceList()
{
meshList.enable();
meshList.show();

final int size = building.getBuildingLevel() - building.getMeshes().size() + 3;

//Creates a dataProvider for the unemployed resourceList.
meshList.setDataProvider(new ScrollingList.DataProvider()
{
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount()
{
return Math.max(Math.min(size, building.getMeshes().size()), 1);
}

/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane)
{
final ItemStack resource = building.getMeshes().get(index).getItemStack();
final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);

boolean isSet = false;
if (resource.isItemEqual(mesh.getItemStack()))
{
resourceLabel.setColors(Color.getByName("green", 0));
resourceLabel.setText(resource.getDisplayName());
isSet = true;
}
else
{
resourceLabel.setColors(Color.getByName("black", 0));
resourceLabel.setText(resource.getDisplayName());
}

rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(resource);

final Button switchButton = rowPane.findPaneOfTypeByID(MESH_BUTTON, Button.class);

final boolean isCreative = Minecraft.getInstance().player.isCreative();

if (isSet || (!isCreative && !InventoryUtils.hasItemInItemHandler(new InvWrapper(Minecraft.getInstance().player.inventory), stack -> stack.isItemEqual(resource))))
{
switchButton.hide();
}
else
{
switchButton.show();
}
}
});
}

/**
* Switch the mesh to a new one.
*
* @param button the clicked button.
*/
private void switchMesh(final Button button)
{
final int row = meshList.getListElementIndexByPane(button);
mesh = building.getMeshes().get(row);

final TextField crushingSettingsInput = findPaneOfTypeByID(QTY_INPUT, TextField.class);
try
{
final int qty = Integer.parseInt(crushingSettingsInput.getText());
building.save(mesh, qty, true);
}
catch (final NumberFormatException ex)
{
Log.getLogger().warn("Wrong input!");
}
}

/**
* Save the crushing mode.
* Save the sifting mode.
*/
private void save()
{
final TextField crushingSettingsInput = findPaneOfTypeByID(QTY_INPUT, TextField.class);
try
{
final int qty = Integer.parseInt(crushingSettingsInput.getText());
building.save(mesh, qty, false);
building.save(qty);
}
catch (final NumberFormatException ex)
{
Expand Down
Loading

0 comments on commit ac57ddd

Please sign in to comment.