Skip to content

Commit

Permalink
Add TAN Cauldron recipes to fill the canteen from a cauldron
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Jun 14, 2018
1 parent a6cbe0f commit b0347e5
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.oredict.OreDictionary;
import slimeknights.mantle.util.RecipeMatch;

public class InspirationsRegistry {
Expand Down Expand Up @@ -270,6 +271,7 @@ public static List<Map.Entry<Block,IBlockState>> getAllAnvilBlockSmashing() {
* Cauldron recipes
*/
private static List<ICauldronRecipe> cauldronRecipes = new ArrayList<>();
private static Set<ItemMetaKey> cauldronBlacklist = new HashSet<>();
private static Set<Fluid> cauldronWater = new HashSet<>();

/**
Expand Down Expand Up @@ -369,4 +371,24 @@ public static void addCauldronWater(Fluid fluid) {
public static boolean isCauldronWater(Fluid fluid) {
return fluid != null && cauldronWater.contains(fluid);
}

/**
* Adds an item to the cauldron blacklist, preventing its normal cauldron interaction
* @param item Item to add
* @param meta Metadata to use, supports wildcard
*/
public static void addCauldronBlacklist(Item item, int meta) {
cauldronBlacklist.add(new ItemMetaKey(item, meta));
}

/**
* Checks if an item is blacklisted from its normal cauldron interaction
* @param stack ItemStack to check
* @return True if the item is blacklisted
*/
public static boolean isCauldronBlacklist(ItemStack stack) {
// check both the item with its current meta and with wildcard meta
return cauldronBlacklist.contains(new ItemMetaKey(stack))
|| cauldronBlacklist.contains(new ItemMetaKey(stack.getItem(), OreDictionary.WILDCARD_VALUE));
}
}
Expand Up @@ -6,6 +6,7 @@
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.PulseBase;
import knightminer.inspirations.library.InspirationsRegistry;
import knightminer.inspirations.plugins.tan.recipes.FillCanteenRecipe;
import knightminer.inspirations.recipes.InspirationsRecipes;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
Expand All @@ -16,6 +17,7 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraftforge.oredict.OreDictionary;
import slimeknights.mantle.pulsar.pulse.Pulse;

@Pulse(
Expand All @@ -32,6 +34,8 @@ public class ToughAsNailsPlugin extends PulseBase {
public static final Item charcoalFilter = null;
@ObjectHolder(value = "toughasnails:fruit_juice")
public static final Item fruitJuice = null;
@ObjectHolder(value = "toughasnails:canteen")
public static final Item canteen = null;

// fluids
public static Fluid sweetenedWater;
Expand Down Expand Up @@ -83,6 +87,17 @@ public void init(FMLInitializationEvent event) {
InspirationsRegistry.addCauldronScaledTransformRecipe(new ItemStack(charcoalFilter), FluidRegistry.WATER, purifiedWater, null);
}

// fill canteen from a cauldron
if(canteen != null) {
for(int i = 0; i < 3; i++) {
// normal water canteen starts at 1
InspirationsRegistry.addCauldronRecipe(new FillCanteenRecipe(canteen, i, 1, FluidRegistry.WATER));
// purified water starts at 2
InspirationsRegistry.addCauldronRecipe(new FillCanteenRecipe(canteen, i, 2, purifiedWater));
}
InspirationsRegistry.addCauldronBlacklist(canteen, OreDictionary.WILDCARD_VALUE);
}

// make juice in the cauldron
if(Config.tanJuiceInCauldron && fruitJuice != null) {
InspirationsRegistry.addCauldronScaledTransformRecipe(new ItemStack(Items.SUGAR), purifiedWater, sweetenedWater, null);
Expand Down
@@ -0,0 +1,76 @@
package knightminer.inspirations.plugins.tan.recipes;

import java.util.List;

import com.google.common.collect.ImmutableList;

import knightminer.inspirations.library.recipe.cauldron.ISimpleCauldronRecipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;

public class FillCanteenRecipe implements ISimpleCauldronRecipe {

private Item canteen;
private int meta, current, type;
private CauldronState fluid;
// JEI data
private List<ItemStack> input;
private ItemStack result;

public FillCanteenRecipe(Item canteen, int current, int type, Fluid fluid) {
this.canteen = canteen;
// canteen level
this.current = current;
// meta offset for canteen
this.type = type;
// detemine the metadata for the input, easier than calculating it two places
this.meta = current == 0 ? 0 : (3 - current) * 4 + type;
this.fluid = CauldronState.fluid(fluid);

// JEI data
this.input = ImmutableList.of(new ItemStack(canteen, 1, meta));
this.result = new ItemStack(canteen, 1, type);
}

@Override
public boolean matches(ItemStack stack, boolean boiling, int level, CauldronState state) {
return level >= 1 && fluid.matches(state)
&& stack.getItem() == canteen && stack.getMetadata() == meta;
}

@Override
public ItemStack getResult(ItemStack stack, boolean boiling, int level, CauldronState state) {
if(level + current >= 3) {
return new ItemStack(canteen, 1, type);
}
return new ItemStack(canteen, 1, ((3 - (level + current)) * 4) + type);
}

@Override
public int getInputLevel() {
return 3 - current;
}

@Override
public int getLevel(int level) {
int total = level + current;
return total <= 3 ? 0 : total - 3;
}

/* JEI */
@Override
public List<ItemStack> getInput() {
return input;
}

@Override
public ItemStack getResult() {
return result;
}

@Override
public Object getInputState() {
return fluid.getFluid();
}
}
@@ -1,6 +1,7 @@
package knightminer.inspirations.recipes;

import knightminer.inspirations.common.Config;
import knightminer.inspirations.library.InspirationsRegistry;
import knightminer.inspirations.recipes.tileentity.TileCauldron;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static void clickCauldron(RightClickBlock event) {
}

boolean result = TileCauldron.interact(world, pos, state, player, event.getHand());
if(result) {
if(result || InspirationsRegistry.isCauldronBlacklist(stack)) {
event.setCanceled(true);
event.setCancellationResult(EnumActionResult.SUCCESS);
}
Expand Down

0 comments on commit b0347e5

Please sign in to comment.