aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/ic2/block/RTGGenerator/BlockRTG.java
blob: 2a1b5ab44dc9c36df4e50bdceaa7e93d17c8240c (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
199
200
201
202
203
204
205
206
207
208
package gtPlusPlus.xmod.ic2.block.RTGGenerator;

import java.util.List;
import java.util.Random;

import org.apache.commons.lang3.mutable.MutableObject;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.xmod.ic2.block.kieticgenerator.tileentity.TileEntityKineticWindGenerator;
import gtPlusPlus.xmod.ic2.item.IC2_Items;
import gtPlusPlus.xmod.ic2.item.ItemGenerators;
import ic2.core.IC2;
import ic2.core.Ic2Items;
import ic2.core.block.BlockMultiID;
import ic2.core.block.TileEntityBlock;
import ic2.core.block.reactor.tileentity.TileEntityNuclearReactorElectric;
import ic2.core.init.InternalName;

public class BlockRTG
extends BlockMultiID
{
	public BlockRTG(final InternalName internalName1)
	{
		super(internalName1, Material.iron, ItemGenerators.class);
		this.setCreativeTab(AddToCreativeTab.tabMachines);
		this.setHardness(3.0F);
		this.setStepSound(soundTypeMetal);

		IC2_Items.blockRTG = new ItemStack(this, 1, 0);
		IC2_Items.blockKineticGenerator = new ItemStack(this, 1, 1);

		GameRegistry.registerTileEntity(TileEntityRTG.class, "RTG Mach II");
		GameRegistry.registerTileEntity(TileEntityKineticWindGenerator.class, "Wind Ripper Mach II");
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public void getSubBlocks(final Item j, final CreativeTabs tabs, final List itemList) {
		final Item item = Item.getItemFromBlock(this);
		if (!item.getHasSubtypes()) {
			itemList.add(new ItemStack(this));
		} else {
			for (int i = 0; i < 16; i++)
			{
				final ItemStack is = new ItemStack(this, 1, i);
				if (is.getItem().getUnlocalizedName(is) == null) {
					break;
				}
				itemList.add(is);
			}
		}
	}


	@Override
	public String getTextureFolder(final int id)
	{
		return "generator";
	}

	@Override
	public int damageDropped(final int meta)
	{
		switch (meta)
		{
		case 2:
			return 2;
		}
		return 0;
	}

	@Override
	public Class<? extends TileEntity> getTeClass(final int meta, final MutableObject<Class<?>[]> ctorArgTypes, final MutableObject<Object[]> ctorArgs)
	{
		try
		{
			switch (meta)
			{
			case 0:
				return TileEntityRTG.class;
			case 1:
				return TileEntityKineticWindGenerator.class;
			}
		}
		catch (final Exception e)
		{
			throw new RuntimeException(e);
		}
		return null;
	}

	/*
	 *
	 *  {
      case 0:
        return TileEntityGenerator.class;
      case 1:
        return TileEntityGeoGenerator.class;
      case 2:
        return TileEntityWaterGenerator.class;
      case 3:
        return TileEntitySolarGenerator.class;
      case 4:
        return TileEntityWindGenerator.class;
      case 5:
        return TileEntityNuclearReactorElectric.class;
      case 6:
        return TileEntityRTGenerator.class;
      case 7:
        return TileEntitySemifluidGenerator.class;
      case 8:
        return TileEntityStirlingGenerator.class;
      case 9:
        return TileEntityKineticGenerator.class;
      }
	 *
	 * (non-Javadoc)
	 * @see net.minecraft.block.Block#randomDisplayTick(net.minecraft.world.World, int, int, int, java.util.Random)
	 */

	@Override
	public void randomDisplayTick(final World world, final int x, final int y, final int z, final Random random)
	{
		if (!IC2.platform.isRendering()) {
			return;
		}
		final int meta = world.getBlockMetadata(x, y, z);
		if ((meta == 0) && (this.isActive(world, x, y, z)))
		{
			final TileEntityBlock te = (TileEntityBlock)this.getOwnTe(world, x, y, z);
			if (te == null) {
				return;
			}
			final int l = te.getFacing();
			final float f = x + 0.5F;
			final float f1 = y + 0.0F + ((random.nextFloat() * 6.0F) / 16.0F);
			final float f2 = z + 0.5F;
			final float f3 = 0.52F;
			final float f4 = (random.nextFloat() * 0.6F) - 0.3F;
			switch (l)
			{
			case 4:
				world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
				world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
				break;
			case 5:
				world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
				world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
				break;
			case 2:
				world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
				world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
				break;
			case 3:
				world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
				world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
			}
		}
		else if (meta == 5)
		{
			final TileEntityNuclearReactorElectric te = (TileEntityNuclearReactorElectric)this.getOwnTe(world, x, y, z);
			if (te == null) {
				return;
			}
			int puffs = te.heat / 1000;
			if (puffs <= 0) {
				return;
			}
			puffs = world.rand.nextInt(puffs);
			for (int n = 0; n < puffs; n++) {
				world.spawnParticle("smoke", x + random.nextFloat(), y + 0.95F, z + random.nextFloat(), 0.0D, 0.0D, 0.0D);
			}
			puffs -= world.rand.nextInt(4) + 3;
			for (int n = 0; n < puffs; n++) {
				world.spawnParticle("flame", x + random.nextFloat(), y + 1.0F, z + random.nextFloat(), 0.0D, 0.0D, 0.0D);
			}
		}
	}

	@Override
	public boolean onBlockActivated(final World world, final int i, final int j, final int k, final EntityPlayer entityplayer, final int side, final float a, final float b, final float c)
	{
		if ((entityplayer.getCurrentEquippedItem() != null) && (entityplayer.getCurrentEquippedItem().isItemEqual(Ic2Items.reactorChamber))) {
			return false;
		}
		return super.onBlockActivated(world, i, j, k, entityplayer, side, a, b, c);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public EnumRarity getRarity(final ItemStack stack)
	{
		return stack.getItemDamage() == 5 ? EnumRarity.uncommon : EnumRarity.common;
	}
}