Skip to content

Commit

Permalink
Also fire cast-events for CastingBasin. Add separate events for Casti…
Browse files Browse the repository at this point in the history
…ngBasin and CastingTable.
  • Loading branch information
bonii-xx committed Aug 6, 2014
1 parent 3cab9c0 commit 0821f9f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/main/java/tconstruct/library/event/SmelteryCastEvent.java
Expand Up @@ -9,12 +9,24 @@
*
* Set result to DENY to prevent casting.
*/
public class SmelteryCastEvent extends Event {
public abstract class SmelteryCastEvent extends Event {
public final CastingRecipe recipe;
public final FluidStack fluid;

public SmelteryCastEvent(CastingRecipe recipe, FluidStack fluid) {
this.recipe = recipe;
this.fluid = fluid;
}

public static class CastingTable extends SmelteryCastEvent {
public CastingTable(CastingRecipe recipe, FluidStack fluid) {
super(recipe, fluid);
}
}

public static class CastingBasin extends SmelteryCastEvent {
public CastingBasin(CastingRecipe recipe, FluidStack fluid) {
super(recipe, fluid);
}
}
}
13 changes: 12 additions & 1 deletion src/main/java/tconstruct/library/event/SmelteryCastedEvent.java
Expand Up @@ -8,7 +8,7 @@
* Fired when an item is cast in the casting table.
* If consumeCast is set to true, the cast will be destroyed.
*/
public class SmelteryCastedEvent extends Event {
public abstract class SmelteryCastedEvent extends Event {
public final CastingRecipe recipe;
public ItemStack output;
public boolean consumeCast;
Expand All @@ -20,4 +20,15 @@ public SmelteryCastedEvent(CastingRecipe recipe, ItemStack output) {
}


public static class CastingTable extends SmelteryCastedEvent {
public CastingTable(CastingRecipe recipe, ItemStack output) {
super(recipe, output);
}
}

public static class CastingBasin extends SmelteryCastedEvent {
public CastingBasin(CastingRecipe recipe, ItemStack output) {
super(recipe, output);
}
}
}
18 changes: 16 additions & 2 deletions src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.java
@@ -1,5 +1,6 @@
package tconstruct.smeltery.logic;

import cpw.mods.fml.common.eventhandler.Event;
import mantle.blocks.abstracts.InventoryLogic;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidEvent;
Expand All @@ -19,6 +21,8 @@
import net.minecraftforge.fluids.IFluidTank;
import tconstruct.TConstruct;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.event.SmelteryCastEvent;
import tconstruct.library.event.SmelteryCastedEvent;
import tconstruct.library.util.IPattern;

public class CastingBasinLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory
Expand Down Expand Up @@ -120,6 +124,13 @@ public int fill (FluidStack resource, boolean doFill)
CastingRecipe recipe = TConstruct.basinCasting.getCastingRecipe(resource, inventory[0]);
if (recipe == null)
return 0;

SmelteryCastEvent event = new SmelteryCastEvent.CastingBasin(recipe, resource);
MinecraftForge.EVENT_BUS.post(event);

if(event.getResult() == Event.Result.DENY)
return 0;

this.capacity = updateCapacity(recipe.castingMetal.amount);

if (inventory[1] == null)
Expand Down Expand Up @@ -328,8 +339,11 @@ public void castLiquid ()
CastingRecipe recipe = TConstruct.basinCasting.getCastingRecipe(liquid, inventory[0]);
if (recipe != null)
{
inventory[1] = recipe.getResult();
if (recipe.consumeCast)
SmelteryCastedEvent event = new SmelteryCastedEvent.CastingBasin(recipe, recipe.getResult());
MinecraftForge.EVENT_BUS.post(event);

inventory[1] = event.output;
if (event.consumeCast)
inventory[0] = null;
liquid = null;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
Expand Down
Expand Up @@ -125,7 +125,7 @@ public int fill (FluidStack resource, boolean doFill)
if (recipe == null)
return 0;

SmelteryCastEvent event = new SmelteryCastEvent(recipe, resource);
SmelteryCastEvent event = new SmelteryCastEvent.CastingTable(recipe, resource);
MinecraftForge.EVENT_BUS.post(event);

if(event.getResult() == Event.Result.DENY)
Expand Down Expand Up @@ -340,7 +340,7 @@ public void castLiquid ()
CastingRecipe recipe = TConstruct.tableCasting.getCastingRecipe(liquid, inventory[0]);
if (recipe != null)
{
SmelteryCastedEvent event = new SmelteryCastedEvent(recipe, recipe.getResult());
SmelteryCastedEvent event = new SmelteryCastedEvent.CastingTable(recipe, recipe.getResult());
MinecraftForge.EVENT_BUS.post(event);

inventory[1] = event.output;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/tconstruct/tools/TinkerToolEvents.java
Expand Up @@ -30,6 +30,8 @@
import tconstruct.armor.player.TPlayerStats;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.event.PartBuilderEvent;
import tconstruct.library.event.SmelteryCastEvent;
import tconstruct.library.event.SmelteryCastedEvent;
import tconstruct.library.event.ToolCraftEvent;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ArrowMaterial;
Expand Down

0 comments on commit 0821f9f

Please sign in to comment.