summaryrefslogtreecommitdiff
path: root/ihl/processing/metallurgy/DetonationSprayingMachineTileEntity.java
blob: ce594ed2814461c7aa55643c2ff114622a8b28cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package ihl.processing.metallurgy;

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 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<String> getNetworkedFields()
    {
		List<String> 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";
	}
	
	@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());
    }

	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<IRecipeInput> input1 = DetonationSprayingMachineTileEntity.recipeManager.getRecipeInput(getInput()).getItemInputs();
			List<RecipeOutputItemStack> output1 = DetonationSprayingMachineTileEntity.recipeManager.getOutputFor(getInput()).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<maxDamage-400)
					{
						damage+=400;
						if(maxDamage<128000)
						{
							int dd = (128000-maxDamage)*3/4;
							maxDamage+=dd;
						}
						gtTagCompound.setInteger("Damage",damage);
						gtTagCompound.setInteger("MaxDamage",maxDamage);
						resultStack.stackTagCompound.setTag("GT.ToolStats", gtTagCompound);
					}
					else
					{
						resultStack=null;
					}
				}
			}
			for(IRecipeInput stack:input1){
				this.input.consume(stack);
			}
			this.input.put(0,resultStack);
	        ExplosionIC2 explosion = new ExplosionIC2(worldObj, null, this.xCoord+0.5D, this.yCoord+0.5D, this.zCoord+0.5D, 0.5F, 0.3F, ExplosionIC2.Type.Normal, null, 0);
	        explosion.doExplosion();
            IC2.network.get().initiateTileEntityEvent(this, 0, true);
		}
	}
	
	public static void addRecipe(ItemStack input, ItemStack output) 
	{
		IRecipeInput[] dsmInputs1 = new IRecipeInput[3];
		dsmInputs1[0]=new RecipeInputItemStack(input);
		dsmInputs1[1]=new RecipeInputOreDict("dustDiamond");
		dsmInputs1[2]=new RecipeInputOreDict("dustGunpowder");
		recipeManager.addRecipe(new UniversalRecipeInput(null, dsmInputs1), new UniversalRecipeOutput(null,new ItemStack[] {output},1));
	}
	
	public static void addRecipe(UniversalRecipeInput input, UniversalRecipeOutput output) 
	{
		recipeManager.addRecipe(input, output);
	}

	public static Map<UniversalRecipeInput, UniversalRecipeOutput> getRecipes() {
		return recipeManager.getRecipes();
	}
	
	@Override
    public boolean shouldRenderInPass(int pass)
    {
        return pass==0;
    }

}