Skip to content

Commit

Permalink
- Updated to match the requested changes, but the new crafting needs …
Browse files Browse the repository at this point in the history
…a revisit
  • Loading branch information
CtrlAltDavid01 committed Jul 4, 2019
1 parent 31bb9da commit 8b58fe0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
7 changes: 1 addition & 6 deletions src/main/java/net/dries007/tfc/api/recipes/BarrelRecipe.java
Expand Up @@ -125,12 +125,7 @@ private int getMultiplier(FluidStack inputFluid, ItemStack inputStack)
return 0;
}

public boolean shouldRepeat()
{
return false;
}

public void onRecipeComplete(World world, BlockPos pos, int tickCounter)
public void onRecipeComplete(World world, BlockPos pos)
{

}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;

import net.dries007.tfc.Constants;
import net.dries007.tfc.api.capability.heat.CapabilityItemHeat;
import net.dries007.tfc.api.capability.heat.IItemHeat;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;
Expand Down Expand Up @@ -52,15 +53,9 @@ public FluidStack getOutputFluid(FluidStack inputFluid, ItemStack inputStack)
}

@Override
public boolean shouldRepeat()
public void onRecipeComplete(World world, BlockPos pos)
{
return true;
}

@Override
public void onRecipeComplete(World world, BlockPos pos, int tickCounter)
{
if (tickCounter % 4 == 0)
world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
if (world.getTotalWorldTime() % 4 == 0)
world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 0.8f, 0.8f + Constants.RNG.nextFloat() * 0.4f);
}
}
Expand Up @@ -41,6 +41,8 @@
import net.dries007.tfc.util.Helpers;
import net.dries007.tfc.world.classic.CalendarTFC;

import static net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;

public class ItemMold extends ItemFiredPottery
{
private static final EnumMap<Metal.ItemType, ItemMold> MAP = new EnumMap<>(Metal.ItemType.class);
Expand Down Expand Up @@ -98,6 +100,13 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCom
return new FilledMoldCapability(nbt);
}

@Override
public int getItemStackLimit(ItemStack stack)
{
IMoldHandler moldHandler = (IMoldHandler) stack.getCapability(FLUID_HANDLER_CAPABILITY, null);
return (moldHandler.getMetal() == null) ? super.getItemStackLimit(stack) : 1;
}

// Extends ItemHeatHandler for ease of use
private class FilledMoldCapability extends ItemHeatHandler implements ICapabilityProvider, IMoldHandler
{
Expand Down
30 changes: 11 additions & 19 deletions src/main/java/net/dries007/tfc/objects/recipes/UnmoldRecipe.java
Expand Up @@ -9,7 +9,6 @@
import javax.annotation.ParametersAreNonnullByDefault;

import com.google.gson.JsonObject;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
Expand Down Expand Up @@ -51,7 +50,8 @@ public UnmoldRecipe(ResourceLocation group, NonNullList<Ingredient> input, @Nonn
@Nonnull
public NonNullList<ItemStack> getRemainingItems(final InventoryCrafting inv)
{
ItemStack moldStack = null;
final NonNullList<ItemStack> remainingItems = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

for (int slot = 0; slot < inv.getSizeInventory(); slot++)
{
ItemStack stack = inv.getStackInSlot(slot);
Expand All @@ -60,34 +60,26 @@ public NonNullList<ItemStack> getRemainingItems(final InventoryCrafting inv)
if (stack.getItem() instanceof ItemMold)
{
ItemMold tmp = ((ItemMold) stack.getItem());
if (tmp.type.equals(this.type) && moldStack == null)
if (tmp.type.equals(this.type))
{
moldStack = stack;
//Only perform random on server side so it doesn't cause desync with the remeaning item
if (Constants.RNG.nextFloat() <= chance && !ForgeHooks.getCraftingPlayer().world.isRemote)
{
remainingItems.set(slot, new ItemStack(stack.getItem()));
}
}
else
{
return super.getRemainingItems(inv);
return remainingItems;
}
}
else
{
return super.getRemainingItems(inv);
}
}
}
if (moldStack != null)
{
if (Constants.RNG.nextFloat() <= chance)
{
EntityPlayer player = ForgeHooks.getCraftingPlayer();
if (player != null)
{
player.addItemStackToInventory(new ItemStack(moldStack.getItem()));
return remainingItems;
}
}
}

return super.getRemainingItems(inv);
return remainingItems;
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/dries007/tfc/objects/te/TEBarrel.java
Expand Up @@ -186,9 +186,9 @@ public void update()
{
tickCounter++;

if (tickCounter % 10 == 0)
if (tickCounter == 10)
{
if (tickCounter == 20) tickCounter = 0;
tickCounter = 0;

ItemStack fluidContainerIn = inventory.getStackInSlot(SLOT_FLUID_CONTAINER_IN);
FluidActionResult result = FluidTransferHelper.emptyContainerIntoTank(fluidContainerIn, tank, inventory, SLOT_FLUID_CONTAINER_OUT, TANK_CAPACITY, world, pos);
Expand Down Expand Up @@ -245,12 +245,10 @@ public void update()
{
tank.setFluid(instantRecipe.getOutputFluid(inputFluid, inputStack));
inventory.setStackInSlot(SLOT_ITEM, instantRecipe.getOutputItem(inputFluid, inputStack));
instantRecipe.onRecipeComplete(world, pos, tickCounter);
instantRecipe.onRecipeComplete(world, pos);

IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);

if (!instantRecipe.shouldRepeat()) checkInstantRecipe = false;
}
else checkInstantRecipe = false;
}
Expand Down

0 comments on commit 8b58fe0

Please sign in to comment.