Skip to content

Commit

Permalink
Merge pull request #822 from bonii-xx/master
Browse files Browse the repository at this point in the history
Add Casting events for CastingTable and CastingBasin, lots of bugfixes, remove console spam for invalid tools
  • Loading branch information
mDiyo committed Aug 8, 2014
2 parents e07036a + cf0d0cc commit 41679a1
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/TConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class TConstruct
public static TProxyCommon proxy;

/* Loads modules in a way that doesn't clutter the @Mod list */
private PulseManager pulsar = new PulseManager(modID, new ForgeCFG("TinkersModules", "Modules: Disabling these will disable a chunk of the mod"));
public static PulseManager pulsar = new PulseManager(modID, new ForgeCFG("TinkersModules", "Modules: Disabling these will disable a chunk of the mod"));

public TConstruct()
{
Expand Down
30 changes: 3 additions & 27 deletions src/main/java/tconstruct/items/tools/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,7 @@ public void getSubItems (Item id, CreativeTabs tab, List list)
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(extra, 1, 0) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, 3), new ItemStack(getHandleItem(), 1, 0), accessoryStack, extraStack, "");
if (tool == null)
{
if (!TinkerTools.supressMissingToolLogs)
{
TConstruct.logger.warn("Creative builder failed tool for Vanilla style" + this.getToolName());
TConstruct.logger.warn("Make sure you do not have item ID conflicts");
}
}
else
if (tool != null)
{
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
Expand All @@ -126,18 +118,7 @@ public void getSubItems (Item id, CreativeTabs tab, List list)
tool = ToolBuilder.instance
.buildTool(new ItemStack(getHeadItem(), 1, random.nextInt(18)), new ItemStack(getHandleItem(), 1, random.nextInt(18)), accessoryStack, extraStack, StatCollector.translateToLocal("item.tool.randomarrow"));

if (tool == null)
{
if (!TinkerTools.supressMissingToolLogs)
{
if (!TinkerTools.supressMissingToolLogs)
{
TConstruct.logger.warn("Creative builder failed tool for Vanilla style" + this.getToolName());
TConstruct.logger.warn("Make sure you do not have item ID conflicts");
}
}
}
else
if (tool != null)
{
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
Expand All @@ -154,12 +135,7 @@ public void buildTool (int id, String name, List list)
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(getExtraItem(), 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), new ItemStack(getHandleItem(), 1, id), accessoryStack, extraStack, name + getToolName());
if (tool == null)
{
TConstruct.logger.warn("Creative builder failed tool for " + name + this.getToolName());
TConstruct.logger.warn("Make sure you do not have item ID conflicts");
}
else
if (tool != null)
{
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/tconstruct/items/tools/BowBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,9 @@ public void buildTool (int id, String name, List list)
ItemStack extraStack = extra != null ? new ItemStack(getExtraItem(), 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), new ItemStack(getHandleItem(), 1, 0), accessoryStack, extraStack, name + getToolName());
if (tool == null)
{
if (!TinkerTools.supressMissingToolLogs)
{
TConstruct.logger.warn("Creative builder failed tool for " + name + this.getToolName());
TConstruct.logger.warn("Make sure you do not have item ID conflicts");
}
}
else
{
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
return;

tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
}
10 changes: 1 addition & 9 deletions src/main/java/tconstruct/items/tools/Mattock.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@ public void buildTool (int id, String name, List list)
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(extra, 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), new ItemStack(getHandleItem(), 1, id), accessoryStack, extraStack, name + getToolName());
if (tool == null)
{
if (!TinkerTools.supressMissingToolLogs)
{
TConstruct.logger.warn("Creative builder failed tool for " + name + this.getToolName());
TConstruct.logger.warn("Make sure you do not have item ID conflicts");
}
}
else
if (tool != null)
{
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/tconstruct/library/event/SmelteryCastEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 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);
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/tconstruct/library/event/SmelteryCastedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package tconstruct.library.event;

import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.item.ItemStack;
import tconstruct.library.crafting.CastingRecipe;

/**
* Fired when an item is cast in the casting table.
* If consumeCast is set to true, the cast will be destroyed.
*/
public abstract class SmelteryCastedEvent extends Event {
public final CastingRecipe recipe;
public ItemStack output;
public boolean consumeCast;

public SmelteryCastedEvent(CastingRecipe recipe, ItemStack output) {
this.recipe = recipe;
this.consumeCast = recipe.consumeCast;
this.output = 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);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/tconstruct/library/tools/AbilityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static boolean hoeGround (ItemStack stack, EntityPlayer player, World wor

if (event.getResult() == Result.ALLOW)
{
stack.damageItem(1, player);
damageTool(stack, 1, player, false);
return true;
}

Expand All @@ -509,7 +509,7 @@ public static boolean hoeGround (ItemStack stack, EntityPlayer player, World wor
else
{
world.setBlock(x, y, z, block1);
stack.damageItem(1, player);
damageTool(stack, 1, player, false);
return true;
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/tconstruct/library/tools/ToolCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.entity.FancyEntityItem;
import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.relauncher.Side;
Expand Down Expand Up @@ -554,16 +555,7 @@ public void buildTool (int id, String name, List list)
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(extra, 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), new ItemStack(getHandleItem(), 1, id), accessoryStack, extraStack, name + getToolName());
if (tool == null)
{
boolean supress = false; //TODO: Find this for iguana tweaks
if (!supress)
{
TConstructRegistry.logger.error("Creative builder failed tool for " + name + this.getToolName());
TConstructRegistry.logger.error("Make sure you do not have item ID conflicts");
}
}
else
if (tool != null)
{
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/tconstruct/smeltery/logic/CastingBasinLogic.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,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
18 changes: 16 additions & 2 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,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 CastingTableLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory
Expand Down Expand Up @@ -120,6 +124,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.CastingTable(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 @@ -329,8 +340,11 @@ public void castLiquid ()
CastingRecipe recipe = TConstruct.tableCasting.getCastingRecipe(liquid, inventory[0]);
if (recipe != null)
{
inventory[1] = recipe.getResult();
if (recipe.consumeCast)
SmelteryCastedEvent event = new SmelteryCastedEvent.CastingTable(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
3 changes: 2 additions & 1 deletion src/main/java/tconstruct/smeltery/logic/FaucetLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public void setActive (boolean flag)
if (!active)
{
active = true;
activateFaucet();
if(!activateFaucet())
active = false;
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/tconstruct/tools/TinkerToolEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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
3 changes: 0 additions & 3 deletions src/main/java/tconstruct/tools/TinkerTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ public class TinkerTools
public static Item knifeBlade;
public static Item wideGuard;

// Supresses console spam when iguana's tweaks remove stuff
public static boolean supressMissingToolLogs = false;

// Patterns and other materials
public static Item blankPattern;
public static Item materials; //TODO: Untwine this item
Expand Down
1 change: 0 additions & 1 deletion src/main/java/tconstruct/util/config/PHConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static void initProps (File location)
//config.load(); /* Load happens in the constructor */

superfunWorld = config.get("Superfun", "All the world is Superfun", false).getBoolean(false);
TinkerTools.supressMissingToolLogs = config.get("Logging", "Disable tool build messages", false).getBoolean(false);

keepHunger = config.get("Difficulty Changes", "Keep hunger on death", true).getBoolean(true);
keepLevels = config.get("Difficulty Changes", "Keep levels on death", true).getBoolean(true);
Expand Down

0 comments on commit 41679a1

Please sign in to comment.