forked from ReikaKalseki/ReactorCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiquidHandler.java
160 lines (153 loc) · 5.88 KB
/
LiquidHandler.java
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
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.ReactorCraft;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import Reika.DragonAPI.Instantiable.Data.BlockStruct.BlockArray;
import Reika.DragonAPI.Instantiable.Data.Immutable.Coordinate;
import Reika.DragonAPI.Libraries.IO.ReikaSoundHelper;
import Reika.DragonAPI.Libraries.Registry.ReikaParticleHelper;
import Reika.DragonAPI.Libraries.World.ReikaWorldHelper;
import Reika.DragonAPI.ModInteract.ItemHandlers.BCPipeHandler;
import Reika.ReactorCraft.Base.TileEntityReactorBase;
import Reika.ReactorCraft.TileEntities.Fusion.TileEntityFusionHeater;
import Reika.RotaryCraft.Registry.MachineRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class LiquidHandler {
@SubscribeEvent
public void onFluidEntersPipe(FluidEvent.FluidMotionEvent evt) {
World world = evt.world;
int x = evt.x;
int y = evt.y;
int z = evt.z;
FluidStack liq = evt.fluid;
if (liq != null) {
if (liq.getFluid().equals(FluidRegistry.getFluid("fusion plasma"))) {
TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof TileEntityReactorBase)) {
ForgeDirection[] dirs = ForgeDirection.values();
BlockArray blocks = new BlockArray();
for (int i = 0; i < 6; i++) {
ForgeDirection dir = dirs[i];
int dx = x+dir.offsetX;
int dy = y+dir.offsetY;
int dz = z+dir.offsetZ;
Block id = world.getBlock(dx, dy, dz);
int meta = world.getBlockMetadata(dx, dy, dz);
TileEntity te2 = world.getTileEntity(dx, dy, dz);
if (!(te2 instanceof TileEntityReactorBase)) {
blocks.recursiveAdd(world, dx, dy, dz, id);
}
}
for (int i = 0; i < blocks.getSize(); i++) {
Coordinate c = blocks.getNthBlock(i);
TileEntity te2 = world.getTileEntity(c.xCoord, c.yCoord, c.zCoord);
if (!(te2 instanceof TileEntityReactorBase)) {
ReikaSoundHelper.playSoundAtBlock(world, c.xCoord, c.yCoord, c.zCoord, "random.fizz", 0.4F, 1);
ReikaParticleHelper.LAVA.spawnAroundBlock(world, c.xCoord, c.yCoord, c.zCoord, 36);
c.setBlock(world, Blocks.flowing_lava);
int r = 4;
for (int dx = c.xCoord-r; dx <= c.xCoord+r; dx++) {
for (int dy = c.yCoord-r; dy <= c.yCoord+r; dy++) {
for (int dz = c.zCoord-r; dz <= c.zCoord+r; dz++) {
ReikaWorldHelper.temperatureEnvironment(world, c.xCoord, c.yCoord, c.zCoord, TileEntityFusionHeater.PLASMA_TEMP);
}
}
}
}
}
}
}
else if (this.isCorrosive(liq.getFluid())) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof IFluidHandler) {
IFluidHandler ifl = (IFluidHandler)te;
ForgeDirection[] dirs = ForgeDirection.values();
BlockArray blocks = new BlockArray();
for (int i = 0; i < 6; i++) {
ForgeDirection dir = dirs[i];
int dx = x+dir.offsetX;
int dy = y+dir.offsetY;
int dz = z+dir.offsetZ;
Block id = world.getBlock(dx, dy, dz);
int meta = world.getBlockMetadata(dx, dy, dz);
TileEntity te2 = world.getTileEntity(dx, dy, dz);
if (te2 instanceof IFluidHandler) {
blocks.recursiveAdd(world, dx, dy, dz, id);
}
}
for (int i = 0; i < blocks.getSize(); i++) {
Coordinate c = blocks.getNthBlock(i);
if (this.isCorrodable(world, c.xCoord, c.yCoord, c.zCoord)) {
ReikaSoundHelper.playSoundAtBlock(world, c.xCoord, c.yCoord, c.zCoord, "random.fizz", 0.4F, 1);
ReikaParticleHelper.SMOKE.spawnAroundBlock(world, x, y, z, 6);
c.setBlock(world, Blocks.air);
}
else if (this.isExplodable(world, c.xCoord, c.yCoord, c.zCoord)) {
world.createExplosion(null, c.xCoord+0.5, c.yCoord+0.5, c.zCoord+0.5, 2F, true);
c.setBlock(world, Blocks.air);
}
}
}
}
}
}
public boolean isCorrosive(Fluid f) {
if (f.equals(FluidRegistry.getFluid("uranium hexafluoride")))
return true;
if (f.equals(FluidRegistry.getFluid("hydrofluoric acid")))
return true;
return false;
}
public boolean isCorrodable(World world, int x, int y, int z) {
Block id = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
MachineRegistry m = MachineRegistry.getMachine(world, x, y, z);
if (m == MachineRegistry.PIPE)
return true;
if (!(te instanceof IFluidHandler))
return false;
if (id == BCPipeHandler.getInstance().pipeID) {
BCPipeHandler.Types type = BCPipeHandler.getInstance().getPipeType(te);
if (type == BCPipeHandler.Types.GOLD)
return true;
if (type == BCPipeHandler.Types.IRON)
return true;
}
//if (id == ThermalHandler.getInstance().ductID) {
// return ThermalHandler.getInstance().getConduitType(te) == ThermalHandler.Types.LIQUID;
//}
return false;
}
public boolean isExplodable(World world, int x, int y, int z) {
Block id = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof IFluidHandler))
return false;
if (id == BCPipeHandler.getInstance().pipeID) {
BCPipeHandler.Types type = BCPipeHandler.getInstance().getPipeType(te);
if (type == BCPipeHandler.Types.DIAMOND)
return true;
if (type == BCPipeHandler.Types.EMERALD)
return true;
}
return false;
}
}