-
Notifications
You must be signed in to change notification settings - Fork 497
/
PowerAdapterPluggable.java
129 lines (103 loc) · 3.48 KB
/
PowerAdapterPluggable.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
package buildcraft.transport.pluggable;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyReceiver;
import buildcraft.BuildCraftTransport;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.pluggable.IPluggableStaticBaker;
import buildcraft.api.transport.pluggable.PipePluggable;
import buildcraft.core.lib.utils.MatrixTranformations;
import buildcraft.transport.client.model.PowerAdapterModel;
public class PowerAdapterPluggable extends PipePluggable implements IEnergyReceiver {
private static final int MAX_POWER = 40;
private IPipeTile container;
public PowerAdapterPluggable() {
}
@Override
public void validate(IPipeTile pipe, EnumFacing direction) {
this.container = pipe;
}
@Override
public void invalidate() {
this.container = null;
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
}
@Override
public ItemStack[] getDropItems(IPipeTile pipe) {
return new ItemStack[] { new ItemStack(BuildCraftTransport.powerAdapterItem) };
}
@Override
public boolean isBlocking(IPipeTile pipe, EnumFacing direction) {
return true;
}
@Override
public AxisAlignedBB getBoundingBox(EnumFacing side) {
float[][] bounds = new float[3][2];
// X START - END
bounds[0][0] = 0.1875F;
bounds[0][1] = 0.8125F;
// Y START - END
bounds[1][0] = 0.000F;
bounds[1][1] = 0.251F;
// Z START - END
bounds[2][0] = 0.1875F;
bounds[2][1] = 0.8125F;
MatrixTranformations.transform(bounds, side);
return new AxisAlignedBB(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]);
}
public IPluggableStaticBaker getRenderer() {
return PowerAdapterModel.INSTANCE;
}
@Override
public void writeData(ByteBuf data) {
}
@Override
public void readData(ByteBuf data) {
}
@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
int maxR = Math.min(MAX_POWER, maxReceive);
if (container != null && container.getPipe() instanceof IEnergyReceiver) {
int energyCanReceive = ((IEnergyReceiver) container.getPipe()).receiveEnergy(from, maxR, true);
if (!simulate) {
return ((IEnergyReceiver) container.getPipe()).receiveEnergy(from, energyCanReceive, false);
} else {
return energyCanReceive;
}
}
return 0;
}
@Override
public int getEnergyStored(EnumFacing from) {
if (container.getPipe() instanceof IEnergyHandler) {
return ((IEnergyHandler) container.getPipe()).getEnergyStored(from);
} else {
return 0;
}
}
@Override
public int getMaxEnergyStored(EnumFacing from) {
if (container.getPipe() instanceof IEnergyHandler) {
return ((IEnergyHandler) container.getPipe()).getMaxEnergyStored(from);
} else {
return 0;
}
}
@Override
public boolean canConnectEnergy(EnumFacing from) {
return true;
}
@Override
public boolean requiresRenderUpdate(PipePluggable o) {
return false;
}
}