Skip to content

Commit

Permalink
Fire a SmelteryCastEvent when a castingTable tries to cast something.…
Browse files Browse the repository at this point in the history
… Allows to deny the casting.
  • Loading branch information
bonii-xx committed Aug 6, 2014
1 parent 6f84462 commit d5829b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/tconstruct/library/event/SmelteryCastEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tconstruct.library.event;

import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.library.crafting.CastingRecipe;

/**
* Fires when somebody tries to pour a liquid into a metal cast.
*
* Set result to DENY to prevent casting.
*/
public class SmelteryCastEvent extends Event {
public final CastingRecipe recipe;
public final FluidStack fluid;

public SmelteryCastEvent(CastingRecipe recipe, FluidStack fluid) {
this.recipe = recipe;
this.fluid = fluid;
}
}
10 changes: 10 additions & 0 deletions src/main/java/tconstruct/smeltery/logic/CastingTableLogic.java
Original file line number Diff line number Diff line change
@@ -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,7 @@
import net.minecraftforge.fluids.IFluidTank;
import tconstruct.TConstruct;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.event.SmelteryCastEvent;
import tconstruct.library.util.IPattern;

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

SmelteryCastEvent event = new SmelteryCastEvent(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

0 comments on commit d5829b0

Please sign in to comment.