From 05c78126859231a68e199dc34613689bd0978e2f Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Mon, 11 Apr 2016 19:44:54 +0300 Subject: Initial commit --- .../DetonationSprayingMachineTileEntity.java | 251 +++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java (limited to 'ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java') diff --git a/ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java b/ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java new file mode 100644 index 0000000..590f6e9 --- /dev/null +++ b/ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java @@ -0,0 +1,251 @@ +package ihl.processing.metallurgy; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import ic2.api.network.INetworkTileEntityEventListener; +import ic2.api.recipe.IRecipeInput; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.RecipeInputOreDict; +import ic2.core.ContainerBase; +import ic2.core.ExplosionIC2; +import ic2.core.IC2; +import ic2.core.IHasGui; +import ic2.core.audio.AudioSource; +import ic2.core.audio.PositionSpec; +import ic2.core.block.TileEntityInventory; +import ic2.core.block.invslot.InvSlot.Access; +import ic2.core.network.NetworkManager; +import ihl.processing.chemistry.ApparatusProcessableInvSlot; +import ihl.recipes.RecipeOutputItemStack; +import ihl.recipes.UniversalRecipeInput; +import ihl.recipes.UniversalRecipeManager; +import ihl.recipes.UniversalRecipeOutput; +import ihl.utils.IHLUtils; + +public class DetonationSprayingMachineTileEntity extends TileEntityInventory implements IHasGui, INetworkTileEntityEventListener +{ + protected static final UniversalRecipeManager recipeManager = new UniversalRecipeManager("detonationsprayingmachine"); + public final ApparatusProcessableInvSlot input; + private AudioSource explosion; + + public DetonationSprayingMachineTileEntity() { + super(); + this.input = new ApparatusProcessableInvSlot(this, "input", 0, Access.IO, 3, 64); + } + + @Override + public List getNetworkedFields() + { + List fields = super.getNetworkedFields(); + return fields; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + } + + @Override + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) { + return false; + } + + @Override + public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { + return IHLUtils.getThisModItemStack("cannonBronze"); + } + + @Override + public String getInventoryName() { + return "detonationSprayingMachine"; + } + + private int mX() + { + switch(this.getFacing()) + { + case 4: + return -1; + case 5: + return 1; + default: + return 0; + } + } + + private int mZ() + { + switch(this.getFacing()) + { + case 3: + return 1; + case 2: + return -1; + case 4: + return 0; + case 5: + return 0; + default: + return -1; + } + } + + private short getFacingFromXZ(int x, int z) + { + switch(x) + { + case -1: + return (short)4; + case 1: + return (short)5; + default: + switch(z) + { + case 1: + return (short)3; + case -1: + return (short)2; + default: + return (short)2; + } + } + } + + + @Override + public void onNetworkEvent(int event) + { + worldObj.playSoundEffect(xCoord, yCoord, zCoord, "random.explode", 4.0F, 1.0F); + } + + @Override + @SideOnly(Side.CLIENT) + public GuiScreen getGui(EntityPlayer player, boolean arg1) { + return new DetonationSprayingMachineGui(new DetonationSprayingMachineContainer(player, this)); + } + + @Override + public ContainerBase getGuiContainer(EntityPlayer player) { + return new DetonationSprayingMachineContainer(player, this); + } + + @Override + public void onGuiClosed(EntityPlayer player) {} + + public boolean canOperate() + { + return getOutput()!=null; + } + + public UniversalRecipeOutput getOutput() + { + return DetonationSprayingMachineTileEntity.recipeManager.getOutputFor(this.getInput(), false, false); + } + + public List[] getInput() + { + return new List[] {null,this.input.getItemStackList()}; + } + + @Override + public void onLoaded() + { + super.onLoaded(); + if (IC2.platform.isRendering() && this.explosion==null) + { + this.explosion = IC2.audioManager.createSource(this, PositionSpec.Center, "Machines/MinerOp.ogg",false,false, 0.5F); + } + } + + + public void operate() + {//diamond file max durability - 128000 + //file tags - "GT.ToolStats"->"MaxDamage" & "Damage" + if(this.canOperate()) + { + List output1 = DetonationSprayingMachineTileEntity.recipeManager.getOutputFor(getInput(), false, false).getItemOutputs(); + ItemStack resultStack = output1.get(0).itemStack.copy(); + resultStack.stackSize=this.input.get(0).stackSize; + if(resultStack.stackTagCompound==null) + { + resultStack.stackTagCompound=this.input.get(0).stackTagCompound; + } + if(resultStack.stackTagCompound!=null && resultStack.stackTagCompound.hasKey("GT.ToolStats")) + { + NBTTagCompound gtTagCompound = resultStack.stackTagCompound.getCompoundTag("GT.ToolStats"); + if(gtTagCompound!=null && gtTagCompound.hasKey("MaxDamage")) + { + int maxDamage = gtTagCompound.getInteger("MaxDamage"); + int damage = 0; + if(gtTagCompound.hasKey("Damage")) + { + damage = gtTagCompound.getInteger("Damage"); + } + if(damage dsmInputs1 = new ArrayList(); + dsmInputs1.add(new RecipeInputItemStack(input)); + dsmInputs1.add(new RecipeInputOreDict("dustDiamond")); + dsmInputs1.add(new RecipeInputOreDict("dustGunpowder")); + recipeManager.addRecipe(new UniversalRecipeInput(null, dsmInputs1), new UniversalRecipeOutput(null,Arrays.asList(new ItemStack[] {output}),1)); + } + + public static void addRecipe(UniversalRecipeInput input, UniversalRecipeOutput output) + { + recipeManager.addRecipe(input, output); + } + + public static Map getRecipes() { + return recipeManager.getRecipes(); + } + + @Override + public boolean shouldRenderInPass(int pass) + { + return pass==0; + } + +} \ No newline at end of file -- cgit v1.2.3