Skip to content

Commit

Permalink
Enable datapack-based loading of worker specific recipes (ldtteam#5644)
Browse files Browse the repository at this point in the history
Enable loading of embedded recipes for workers from datapacks
Update Crusher to load from data
Update Dyer to load from data
Update Farmer to load from data
Update Fletcher to load from data
Update Lumberjack to load from data
Update Stonemason to load from data
Fix A pathing error
Fix pickup messup error
  • Loading branch information
Mekle001 authored Aug 24, 2020
1 parent 0593c1c commit 909affd
Show file tree
Hide file tree
Showing 43 changed files with 898 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder;
import com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.coremod.colony.crafting.CustomRecipe;
import com.minecolonies.coremod.colony.crafting.CustomRecipeManager;
import com.minecolonies.coremod.colony.requestsystem.resolvers.BuildingRequestResolver;
import com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingProductionResolver;
import com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingRequestResolver;
Expand Down Expand Up @@ -222,7 +224,7 @@ public IRecipeStorage getFirstRecipe(final Predicate<ItemStack> stackPredicate)
/**
* Get the count of items in all the warehouses
*/
private int getWarehouseCount(ItemStorage item)
protected int getWarehouseCount(ItemStorage item)
{
int count = 0;
final Set<IBuilding> wareHouses = colony.getBuildingManager().getBuildings().values().stream()
Expand Down Expand Up @@ -787,7 +789,72 @@ public boolean canEat(final ItemStack stack)
*/
public void checkForWorkerSpecificRecipes()
{
// Override if necessary.
final Set<CustomRecipe> staticRecipes = CustomRecipeManager.getInstance().getRecipes(getJobName());

for(final CustomRecipe newRecipe : staticRecipes)
{
final IRecipeStorage recipeStorage = newRecipe.getRecipeStorage();
final IToken<?> recipeToken = IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(recipeStorage);

if(newRecipe.isValidForColony(colony))
{
boolean duplicateFound = false;
for(IToken<?> token : recipes)
{
if(token == recipeToken)
{
duplicateFound = true;
break;
}
final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token);

//Let's verify that this recipe doesn't exist in an improved form
if(storage != null && storage.getPrimaryOutput().equals(recipeStorage.getPrimaryOutput(), true))
{
List<ItemStorage> recipeInput1 = storage.getCleanedInput();
List<ItemStorage> recipeInput2 = recipeStorage.getCleanedInput();

if(recipeInput1.size() != recipeInput2.size())
{
continue;
}

if(recipeInput1.size() > 1)
{
recipeInput1.sort(Comparator.comparing(item -> item.toString()));
recipeInput2.sort(Comparator.comparing(item -> item.toString()));
}

boolean allMatch = true;
for(int i=0; i<recipeInput1.size(); i++)
{
if(!recipeInput1.get(i).getItem().equals(recipeInput2.get(i).getItem()))
{
allMatch = false;
break;
}
}
if(allMatch)
{
duplicateFound = true;
break;
}
}
}
if(!duplicateFound)
{
addRecipeToList(recipeToken);
}
}
else
{
if(recipes.contains(recipeToken))
{
removeRecipe(recipeToken);
}
}
}
markDirty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,6 @@ private void loadCrusherMode()
}
}

@Override
public void checkForWorkerSpecificRecipes()
{
loadCurrentRecipes();
}

/**
* Reload all of the current crusher recipes
*/
private void loadCurrentRecipes()
{
for (final IRecipeStorage recipe : crusherRecipes.values())
{
final IToken<?> token = IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(recipe);
final IRecipeStorage oldRecipe = getFirstRecipe(recipe.getPrimaryOutput());
if(oldRecipe != null && !oldRecipe.getToken().equals(token))
{
replaceRecipe(oldRecipe.getToken(), token);
}
else
{
addRecipe(token);
}
}

final IRecipeStorage clayballStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.CLAY, 1)),
1,
new ItemStack(Items.CLAY_BALL, 4),
Blocks.AIR);

addRecipe(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(clayballStorage));
}

/**
* Get the recipe storage of the current mode.
*
Expand Down Expand Up @@ -297,11 +261,6 @@ public void deserializeNBT(final CompoundNBT compound)
}

this.oneByOne = compound.getBoolean(CRUSHING_11);

if (super.recipes.isEmpty())
{
loadCurrentRecipes();
}
}

@Override
Expand Down Expand Up @@ -331,8 +290,6 @@ public void serializeToView(@NotNull final PacketBuffer buf)
if (crusherRecipes.isEmpty() || oneOne && !oneByOne)
{
loadCrusherMode();

loadCurrentRecipes();
}

if (crusherMode == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,6 @@ public BuildingDyer(final IColony c, final BlockPos l)
super(c, l);
}

@Override
public void checkForWorkerSpecificRecipes()
{
final IRecipeStorage cactusStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.CACTUS, 1)),
1,
new ItemStack(Items.GREEN_DYE, 1),
Blocks.FURNACE);

final IRecipeStorage redsandStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.SAND, 4), new ItemStack(Items.RED_DYE)),
1,
new ItemStack(Blocks.RED_SAND, 4),
Blocks.AIR);

final IRecipeStorage darkPrismarineStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.PRISMARINE, 4), new ItemStack(Items.BLACK_DYE)),
1,
new ItemStack(Blocks.DARK_PRISMARINE, 4),
Blocks.AIR);

addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(cactusStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(redsandStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(darkPrismarineStorage));
}

@NotNull
@Override
public String getSchematicName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,6 @@ public Skill getSecondarySkill()
return Skill.Athletics;
}

@Override
public void checkForWorkerSpecificRecipes()
{
final IRecipeStorage carvedPumpkinStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.PUMPKIN, 1)),
1,
new ItemStack(Blocks.CARVED_PUMPKIN, 1),
Blocks.AIR);

addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(carvedPumpkinStorage));
}

@Override
public boolean canRecipeBeAdded(final IToken<?> token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,6 @@ public boolean canRecipeBeAdded(final IToken<?> token)
}
}

@Override
public void checkForWorkerSpecificRecipes()
{
final IRecipeStorage stringStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Items.WHITE_WOOL, 1)),
1,
new ItemStack(Items.STRING, 4),
Blocks.AIR);

final IRecipeStorage flintStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.GRAVEL, 3)),
1,
new ItemStack(Items.FLINT, 4),
Blocks.AIR);

addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(stringStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(flintStorage));
}

@Override
public BuildingEntry getBuildingRegistryEntry()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,6 @@ public BuildingLumberjack(final IColony c, final BlockPos l)
keepX.put(itemStack -> ItemStackUtils.hasToolLevel(itemStack, ToolType.AXE, TOOL_LEVEL_WOOD_OR_GOLD, getMaxToolLevel()), new Tuple<>(1, true));
}

@Override
public void checkForWorkerSpecificRecipes()
{
if (recipes.isEmpty())
{
addStrippedWoodRecipe(Items.OAK_LOG, Items.STRIPPED_OAK_LOG);
addStrippedWoodRecipe(Items.SPRUCE_LOG, Items.STRIPPED_SPRUCE_LOG);
addStrippedWoodRecipe(Items.BIRCH_LOG, Items.STRIPPED_BIRCH_LOG);
addStrippedWoodRecipe(Items.JUNGLE_LOG, Items.STRIPPED_JUNGLE_LOG);
addStrippedWoodRecipe(Items.ACACIA_LOG, Items.STRIPPED_ACACIA_LOG);
addStrippedWoodRecipe(Items.DARK_OAK_LOG, Items.STRIPPED_DARK_OAK_LOG);
addStrippedWoodRecipe(Items.OAK_WOOD, Items.STRIPPED_OAK_WOOD);
addStrippedWoodRecipe(Items.SPRUCE_WOOD, Items.STRIPPED_SPRUCE_WOOD);
addStrippedWoodRecipe(Items.BIRCH_WOOD, Items.STRIPPED_BIRCH_WOOD);
addStrippedWoodRecipe(Items.JUNGLE_WOOD, Items.STRIPPED_JUNGLE_WOOD);
addStrippedWoodRecipe(Items.ACACIA_WOOD, Items.STRIPPED_ACACIA_WOOD);
addStrippedWoodRecipe(Items.DARK_OAK_WOOD, Items.STRIPPED_DARK_OAK_WOOD);
markDirty();
}
}

public final void addStrippedWoodRecipe(final Item baseVariant, final Item strippedVariant)
{
final IRecipeStorage storage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(baseVariant, 1)),
1,
new ItemStack(strippedVariant, 1),
Blocks.AIR);

addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(storage));
}

@Override
public boolean canBeGathered()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,6 @@ public BuildingStonemason(final IColony c, final BlockPos l)
super(c, l);
}

@Override
public void checkForWorkerSpecificRecipes()
{
final IRecipeStorage sandstoneStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.COBBLESTONE, 1), new ItemStack(Blocks.SAND, 1)),
1,
new ItemStack(Blocks.SANDSTONE, 1),
Blocks.AIR);

final IRecipeStorage redsandstoneStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.COBBLESTONE, 1), new ItemStack(Blocks.RED_SAND, 1)),
1,
new ItemStack(Blocks.RED_SANDSTONE, 1),
Blocks.AIR);

final IRecipeStorage prismarineBlockStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.COBBLESTONE, 1), new ItemStack(Items.PRISMARINE_SHARD, 1)),
1,
new ItemStack(Blocks.PRISMARINE, 1),
Blocks.AIR);

final IRecipeStorage prismarineBrickStorage = StandardFactoryController.getInstance().getNewInstance(
TypeConstants.RECIPE,
StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN),
ImmutableList.of(new ItemStack(Blocks.STONE_BRICKS, 1), new ItemStack(Items.PRISMARINE_SHARD, 1)),
1,
new ItemStack(Blocks.PRISMARINE_BRICKS, 1),
Blocks.AIR);

addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(sandstoneStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(redsandstoneStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(prismarineBlockStorage));
addRecipeToList(IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(prismarineBrickStorage));

}

@NotNull
@Override
public String getSchematicName()
Expand Down
Loading

0 comments on commit 909affd

Please sign in to comment.