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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
package darkknight.jewelrycraft.block;
import java.io.IOException;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.network.PacketRequestLiquidData;
import darkknight.jewelrycraft.network.PacketSendLiquidData;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import darkknight.jewelrycraft.util.Variables;
public class BlockMoltenMetal extends BlockFluidClassic
{
@SideOnly (Side.CLIENT)
protected IIcon stillIcon;
@SideOnly (Side.CLIENT)
protected IIcon flowingIcon;
/**
* @param fluid
* @param material
*/
public BlockMoltenMetal(Fluid fluid, Material material)
{
super(fluid, material);
setBlockName(Variables.MODID + ".moltenMetal");
setQuantaPerBlock(5);
setRenderPass(1);
setLightLevel(15f);
}
/**
* @param side
* @param meta
* @return
*/
@Override
public IIcon getIcon(int side, int meta)
{
return side == 0 || side == 1 ? stillIcon : flowingIcon;
}
/**
* @param register
*/
@Override
@SideOnly (Side.CLIENT)
public void registerBlockIcons(IIconRegister register)
{
stillIcon = register.registerIcon(Variables.MODID + ":moltenMetalStill");
flowingIcon = register.registerIcon(Variables.MODID + ":moltenMetalFlow");
}
/**
* @param world
* @param x
* @param y
* @param z
* @return
*/
@Override
public boolean canDisplace(IBlockAccess world, int x, int y, int z)
{
if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
return super.canDisplace(world, x, y, z);
}
/**
* @param world
* @param x
* @param y
* @param z
* @return
*/
@Override
public boolean displaceIfPossible(World world, int x, int y, int z)
{
if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
return super.displaceIfPossible(world, x, y, z);
}
/**
* @param world
* @param x
* @param y
* @param z
* @return
*/
@Override
protected boolean canFlowInto(IBlockAccess world, int x, int y, int z)
{
if (world.getBlock(x, y, z).isAir(world, x, y, z)) return true;
Block block = world.getBlock(x, y, z);
if (block == this) return false;
if (displacements.containsKey(block)) return displacements.get(block);
Material material = block.getMaterial();
if (material.blocksMovement() || material == Material.water || material == Material.lava || material == Material.portal) return false;
int density = getDensity(world, x, y, z);
if (density == Integer.MAX_VALUE) return true;
if (this.density > density) return true;
else return false;
}
/**
* @param world
* @param i
* @param j
* @param k
* @return
*/
@Override
@SideOnly (Side.CLIENT)
public int colorMultiplier(IBlockAccess world, int i, int j, int k)
{
try{
return color(world, i, j, k, false, null);
}
catch(IOException e){
e.printStackTrace();
}
return 0;
}
/**
* @param world
* @param x
* @param y
* @param z
* @param rand
*/
@Override
public void updateTick(World world, int x, int y, int z, Random rand)
{
int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
int expQuanta = -101;
// check adjacent block levels if non-source
if (quantaRemaining < quantaPerBlock){
int y2 = y - densityDir;
if (world.getBlock(x, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x - 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x + 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z - 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z + 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) expQuanta = quantaPerBlock - 1;
else{
int maxQuanta = -100;
if (JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta);
if (JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta);
if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta);
if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta);
expQuanta = maxQuanta - 1;
}
// decay calculation
if (expQuanta != quantaRemaining){
quantaRemaining = expQuanta;
if (expQuanta <= 0) world.setBlock(x, y, z, Blocks.air);
else{
world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3);
world.scheduleBlockUpdate(x, y, z, this, tickRate);
world.notifyBlocksOfNeighborChange(x, y, z, this);
}
}
}
// This is a "source" block, set meta to zero, and send a server only
// update
else if (quantaRemaining >= quantaPerBlock) world.setBlockMetadataWithNotify(x, y, z, 0, 2);
String originData = JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId));
// Flow vertically if possible
if (canDisplace(world, x, y + densityDir, z)){
JewelrycraftMod.saveData.setString(stringFromLocation(x, y + densityDir, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
flowIntoBlock(world, x, y + densityDir, z, 1, originData);
return;
}
// Flow outward if possible
int flowMeta = quantaPerBlock - quantaRemaining + 1;
if (flowMeta >= quantaPerBlock) return;
if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)){
if (world.getBlock(x, y - densityDir, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y - densityDir, z, world.provider.dimensionId)))) flowMeta = 1;
boolean flowTo[] = getOptimalFlowDirections(world, x, y, z);
if (flowTo[0]){
if (JewelrycraftMod.saveData.getTag(stringFromLocation(x - 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x - 1, y, z).isAir(world, x - 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x - 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
flowIntoBlock(world, x - 1, y, z, flowMeta, originData);
}
if (flowTo[1]){
if (JewelrycraftMod.saveData.getTag(stringFromLocation(x + 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x + 1, y, z).isAir(world, x + 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x + 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
flowIntoBlock(world, x + 1, y, z, flowMeta, originData);
}
if (flowTo[2]){
if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z - 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z - 1).isAir(world, x, y, z - 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z - 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
flowIntoBlock(world, x, y, z - 1, flowMeta, originData);
}
if (flowTo[3]){
if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z + 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z + 1).isAir(world, x, y, z + 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z + 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
flowIntoBlock(world, x, y, z + 1, flowMeta, originData);
}
}
}
/**
* @param world
* @param x
* @param y
* @param z
* @param meta
* @param originData
*/
public void flowIntoBlock(World world, int x, int y, int z, int meta, String originData)
{
if (meta < 0 || world.isRemote) return;
if (displaceIfPossible(world, x, y, z)){
world.setBlock(x, y, z, this, meta, 3);
JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z, world.provider.dimensionId), originData);
String[] data = originData.split(":");
try{
JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Integer.parseInt(data[0]), Integer.parseInt(data[1])));
}
catch(Exception e){
System.out.println("The liquids file is either corrupt, missing or the metal for the liquid simply doesn't exist!");
}
}
}
/**
* @param world
* @param i
* @param j
* @param k
* @param forcecolor
* @param itemC
* @return
* @throws IOException
*/
@SideOnly (Side.CLIENT)
public static int color(IBlockAccess world, int i, int j, int k, boolean forcecolor, Item itemC) throws IOException
{
String ingotData = JewelrycraftMod.clientData.getString(String.valueOf(i) + " " + String.valueOf(j) + " " + String.valueOf(k) + " " + Minecraft.getMinecraft().theWorld.provider.dimensionId);
if (ingotData == ""){
JewelrycraftMod.netWrapper.sendToServer(new PacketRequestLiquidData(Minecraft.getMinecraft().theWorld.provider.dimensionId, i, j, k));
return 0xFFFFFF;
}else{
String[] splitData = ingotData.split(":");
if (splitData.length == 2){
int color;
try{
Integer.parseInt(splitData[0]);
Integer.parseInt(splitData[1]);
return JewelrycraftUtil.getColor(new ItemStack(Item.getItemById(Integer.parseInt(splitData[0])), 1, Integer.parseInt(splitData[1])));
}
catch(Exception e){
e.printStackTrace();
}
}
}
return 16777215;
}
/**
* @param x
* @param y
* @param z
* @param dimID
* @return
*/
public static String stringFromLocation(int x, int y, int z, int dimID)
{
return x + " " + y + " " + z + " " + dimID;
}
}
|