Merge branch 'master' of github.com:SirSengir/BuildCraft
This commit is contained in:
commit
ad111637ac
17 changed files with 357 additions and 194 deletions
|
@ -17,8 +17,8 @@
|
|||
|
||||
<property name="mcpsrc.dir" value="${mcp.dir}/src/minecraft"/>
|
||||
|
||||
<property name="mcp.version" value="722"/>
|
||||
<property name="forge.version" value="6.4.0.381"/>
|
||||
<property name="mcp.version" value="723"/>
|
||||
<property name="forge.version" value="1.4.5-6.4.0.396"/>
|
||||
<property name="bc.version" value="3.1.8"/>
|
||||
|
||||
<available property="forge-exists" file="${download.dir}/minecraftforge-src-${forge.version}.zip"/>
|
||||
|
|
|
@ -69,9 +69,6 @@ import net.minecraft.src.ItemStack;
|
|||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.Property;
|
||||
import net.minecraftforge.liquids.LiquidContainerData;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
|
||||
@Mod(name="BuildCraft", version=Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", dependencies="required-after:Forge@[6.3.0.0,)")
|
||||
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandler.class, clientSideRequired = true, serverSideRequired = true)
|
||||
|
|
|
@ -165,28 +165,29 @@ public class BlockMarker extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void func_85105_g(World world, int x, int y, int z, int par5) {
|
||||
super.func_85105_g(world, x, y, z, par5);
|
||||
int i1 = world.getBlockMetadata(x, y, z);
|
||||
if (par5 == 1 && BuildersProxy.canPlaceTorch(world, x, y - 1, z)) {
|
||||
i1 = 5;
|
||||
public int func_85104_a(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
|
||||
super.func_85104_a(world, x, y, z, side, par6, par7, par8, meta);
|
||||
|
||||
if (side == 1 && BuildersProxy.canPlaceTorch(world, x, y - 1, z)) {
|
||||
meta = 5;
|
||||
}
|
||||
if (par5 == 2 && BuildersProxy.canPlaceTorch(world, x, y, z + 1)) {
|
||||
i1 = 4;
|
||||
if (side == 2 && BuildersProxy.canPlaceTorch(world, x, y, z + 1)) {
|
||||
meta = 4;
|
||||
}
|
||||
if (par5 == 3 && BuildersProxy.canPlaceTorch(world, x, y, z - 1)) {
|
||||
i1 = 3;
|
||||
if (side == 3 && BuildersProxy.canPlaceTorch(world, x, y, z - 1)) {
|
||||
meta = 3;
|
||||
}
|
||||
if (par5 == 4 && BuildersProxy.canPlaceTorch(world, x + 1, y, z)) {
|
||||
i1 = 2;
|
||||
if (side == 4 && BuildersProxy.canPlaceTorch(world, x + 1, y, z)) {
|
||||
meta = 2;
|
||||
}
|
||||
if (par5 == 5 && BuildersProxy.canPlaceTorch(world, x - 1, y, z)) {
|
||||
i1 = 1;
|
||||
if (side == 5 && BuildersProxy.canPlaceTorch(world, x - 1, y, z)) {
|
||||
meta = 1;
|
||||
}
|
||||
if (par5 == 0 && BuildersProxy.canPlaceTorch(world, x, y + 1, z)) {
|
||||
i1 = 0;
|
||||
if (side == 0 && BuildersProxy.canPlaceTorch(world, x, y + 1, z)) {
|
||||
meta = 0;
|
||||
}
|
||||
world.setBlockMetadataWithNotify(x, y, z, i1);
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ public class DefaultProps {
|
|||
public static int WORLD_HEIGHT = 256;
|
||||
public static final String NET_CHANNEL_NAME = "BC";
|
||||
public static int NETWORK_UPDATE_RANGE = 128;
|
||||
public static int PIPE_CONTENTS_RENDER_DIST = 24;
|
||||
|
||||
public static String TEXTURE_PATH_GUI = "/gfx/buildcraft/gui";
|
||||
public static String TEXTURE_PATH_BLOCKS = "/gfx/buildcraft/blocks";
|
||||
|
|
|
@ -35,6 +35,7 @@ public class BlockEngine extends BlockContainer {
|
|||
|
||||
setHardness(0.5F);
|
||||
setCreativeTab(CreativeTabs.tabRedstone);
|
||||
setBlockName("engineBlock");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -636,7 +636,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
|
||||
@Override
|
||||
public void setPowerProvider(IPowerProvider provider) {
|
||||
provider = powerProvider;
|
||||
powerProvider = provider;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,10 @@ public class GuiRefinery extends GuiAdvancedInterface {
|
|||
if (slot != null) {
|
||||
LiquidStack liquid = LiquidContainerRegistry.getLiquidForFilledItem(mc.thePlayer.inventory.getItemStack());
|
||||
|
||||
if(liquid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.setFilter(position, liquid.itemID, liquid.itemMeta);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,13 +73,14 @@ public class BlockLaser extends BlockContainer {
|
|||
|
||||
|
||||
@Override
|
||||
public void func_85105_g(World world, int x, int y, int z, int par5) {
|
||||
super.func_85105_g(world, x, y, z, par5);
|
||||
int i1 = world.getBlockMetadata(x, y, z);
|
||||
if (par5 <= 6) {
|
||||
i1 = par5;
|
||||
public int func_85104_a(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
|
||||
super.func_85104_a(world, x, y, z, side, par6, par7, par8, meta);
|
||||
|
||||
if (side <= 6) {
|
||||
meta = side;
|
||||
}
|
||||
world.setBlockMetadataWithNotify(x, y, z, i1);
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
|
|
@ -60,6 +60,11 @@ public class BlockGenericPipe extends BlockContainer {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeReplacedByLeaves(World world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
|
@ -331,13 +336,14 @@ public class BlockGenericPipe extends BlockContainer {
|
|||
|
||||
|
||||
@Override
|
||||
public void func_85105_g(World world, int x, int y, int z, int par5) {
|
||||
super.func_85105_g(world, x, y, z, par5);
|
||||
public int func_85104_a(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
|
||||
super.func_85104_a(world, x, y, z, side, par6, par7, par8, meta);
|
||||
Pipe pipe = getPipe(world, x, y, z);
|
||||
|
||||
if (isValid(pipe))
|
||||
pipe.onBlockPlaced();
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,4 +88,8 @@ public abstract class PipeTransport {
|
|||
public boolean allowsConnect(PipeTransport with) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendDescriptionPacket() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,7 +440,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
private void sendItemPacket(EntityData data) {
|
||||
int dimension = worldObj.provider.dimensionId;
|
||||
PacketDispatcher.sendPacketToAllAround(xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE, dimension, createItemPacket(data));
|
||||
PacketDispatcher.sendPacketToAllAround(xCoord, yCoord, zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST, dimension, createItemPacket(data));
|
||||
}
|
||||
|
||||
public int getNumberOfItems() {
|
||||
|
@ -479,7 +479,7 @@ public class PipeTransportItems extends PipeTransport {
|
|||
public void groupEntities() {
|
||||
EntityData[] entities = travelingEntities.values().toArray(new EntityData[travelingEntities.size()]);
|
||||
|
||||
TreeSet<Integer> toRemove = new TreeSet<Integer>();
|
||||
TreeSet<Integer> remove = new TreeSet<Integer>();
|
||||
|
||||
for (int i = 0; i < entities.length; ++i) {
|
||||
EntityData data1 = entities[i];
|
||||
|
@ -489,17 +489,17 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
if (data1.item.getItemStack().itemID == data2.item.getItemStack().itemID
|
||||
&& data1.item.getItemStack().getItemDamage() == data2.item.getItemStack().getItemDamage()
|
||||
&& !toRemove.contains(data1.item.getEntityId()) && !toRemove.contains(data2.item.getEntityId())
|
||||
&& !remove.contains(data1.item.getEntityId()) && !remove.contains(data2.item.getEntityId())
|
||||
&& !data1.item.hasContributions() && !data2.item.hasContributions()
|
||||
&& data1.item.getItemStack().stackSize + data2.item.getItemStack().stackSize < data1.item.getItemStack().getMaxStackSize()) {
|
||||
|
||||
data1.item.getItemStack().stackSize += data2.item.getItemStack().stackSize;
|
||||
toRemove.add(data2.item.getEntityId());
|
||||
remove.add(data2.item.getEntityId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer i : toRemove) {
|
||||
for (Integer i : remove) {
|
||||
travelingEntities.get(i).item.remove();
|
||||
travelingEntities.remove(i);
|
||||
}
|
||||
|
@ -509,8 +509,9 @@ public class PipeTransportItems extends PipeTransport {
|
|||
public void dropContents() {
|
||||
groupEntities();
|
||||
|
||||
for (EntityData data : travelingEntities.values())
|
||||
for (EntityData data : travelingEntities.values()) {
|
||||
Utils.dropItems(worldObj, data.item.getItemStack(), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
travelingEntities.clear();
|
||||
}
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
package buildcraft.transport;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.liquids.LiquidTank;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
|
@ -24,8 +18,15 @@ import buildcraft.core.IMachine;
|
|||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.transport.network.PacketLiquidUpdate;
|
||||
import java.util.BitSet;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.liquids.LiquidTank;
|
||||
|
||||
public class PipeTransportLiquids extends PipeTransport implements ITankContainer {
|
||||
|
||||
|
@ -134,7 +135,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
private static final ForgeDirection[] directions = ForgeDirection.VALID_DIRECTIONS;
|
||||
private static final ForgeDirection[] orientations = ForgeDirection.values();
|
||||
|
||||
|
||||
public byte initClient = 0;
|
||||
public short travelDelay = 12;
|
||||
public short flowRate = 20;
|
||||
public LiquidStack[] renderCache = new LiquidStack[orientations.length];
|
||||
|
@ -185,47 +186,87 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
return;
|
||||
|
||||
moveLiquids();
|
||||
for (ForgeDirection direction : orientations) {
|
||||
LiquidStack liquid = internalTanks[direction.ordinal()].getLiquid();
|
||||
|
||||
if (liquid != null){
|
||||
if (renderCache[direction.ordinal()] == null){
|
||||
renderCache[direction.ordinal()] = liquid.copy();
|
||||
} else {
|
||||
renderCache[direction.ordinal()].itemID = liquid.itemID;
|
||||
renderCache[direction.ordinal()].itemMeta = liquid.itemMeta;
|
||||
if (tracker.markTimeIfDelay(worldObj, BuildCraftCore.updateFactor)) {
|
||||
|
||||
boolean changed = false;
|
||||
BitSet delta = new BitSet(21);
|
||||
|
||||
if (initClient > 0) {
|
||||
changed = true;
|
||||
initClient--;
|
||||
delta.set(0, 21);
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : orientations) {
|
||||
LiquidStack current = internalTanks[dir.ordinal()].getLiquid();
|
||||
LiquidStack prev = renderCache[dir.ordinal()];
|
||||
|
||||
if (prev == null && current == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev == null && current != null) {
|
||||
changed = true;
|
||||
renderCache[dir.ordinal()] = current.copy();
|
||||
delta.set(dir.ordinal() * 3 + 0);
|
||||
delta.set(dir.ordinal() * 3 + 1);
|
||||
delta.set(dir.ordinal() * 3 + 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev != null && current == null) {
|
||||
changed = true;
|
||||
renderCache[dir.ordinal()] = null;
|
||||
delta.set(dir.ordinal() * 3 + 0);
|
||||
delta.set(dir.ordinal() * 3 + 1);
|
||||
delta.set(dir.ordinal() * 3 + 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prev.itemID != current.itemID) {
|
||||
changed = true;
|
||||
renderCache[dir.ordinal()].itemID = current.itemID;
|
||||
delta.set(dir.ordinal() * 3 + 0);
|
||||
}
|
||||
|
||||
if (prev.itemMeta != current.itemMeta) {
|
||||
changed = true;
|
||||
renderCache[dir.ordinal()].itemMeta = current.itemMeta;
|
||||
delta.set(dir.ordinal() * 3 + 1);
|
||||
}
|
||||
|
||||
int displayQty = (renderCache[dir.ordinal()].amount * 4 + current.amount) / 5;
|
||||
if (displayQty == 0 && current.amount > 0) {
|
||||
displayQty = current.amount;
|
||||
}
|
||||
displayQty = Math.min(PipeTransportLiquids.LIQUID_IN_PIPE, displayQty);
|
||||
|
||||
if (prev.amount != displayQty) {
|
||||
changed = true;
|
||||
renderCache[dir.ordinal()].amount = displayQty;
|
||||
delta.set(dir.ordinal() * 3 + 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (renderCache[direction.ordinal()] != null){
|
||||
int currentLiquid = liquid != null ? liquid.amount : 0;
|
||||
renderCache[direction.ordinal()].amount = (short) Math.min(LIQUID_IN_PIPE, ((renderCache[direction.ordinal()].amount * 9 + currentLiquid) / 10));
|
||||
if (renderCache[direction.ordinal()].amount == 0 && currentLiquid > 0){
|
||||
renderCache[direction.ordinal()].amount = currentLiquid;
|
||||
}
|
||||
|
||||
//Uncomment to disable the avaraging
|
||||
//renderCache[direction.ordinal()].amount = (liquid != null ? liquid.amount : 0);
|
||||
}
|
||||
|
||||
//Uncomment to disable the renderstate and show actual values
|
||||
// renderCache[direction.ordinal()] = internalTanks[direction.ordinal()].getLiquid();
|
||||
// if (renderCache[direction.ordinal()] != null){
|
||||
// renderCache[direction.ordinal()] = renderCache[direction.ordinal()].copy();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
if (CoreProxy.proxy.isSimulating(worldObj))
|
||||
if (tracker.markTimeIfDelay(worldObj, 1 * BuildCraftCore.updateFactor)){
|
||||
|
||||
if (changed) {
|
||||
PacketLiquidUpdate packet = new PacketLiquidUpdate(xCoord, yCoord, zCoord);
|
||||
packet.displayLiquid = this.renderCache;
|
||||
packet.renderCache = this.renderCache;
|
||||
packet.delta = delta;
|
||||
CoreProxy.proxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord,
|
||||
DefaultProps.NETWORK_UPDATE_RANGE);
|
||||
DefaultProps.PIPE_CONTENTS_RENDER_DIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor);
|
||||
/**
|
||||
* Initializes client
|
||||
*/
|
||||
@Override
|
||||
public void sendDescriptionPacket() {
|
||||
super.sendDescriptionPacket();
|
||||
|
||||
initClient = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -422,10 +463,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
|
|||
return with instanceof PipeTransportLiquids;
|
||||
}
|
||||
|
||||
public void handleLiquidPacket(PacketLiquidUpdate packetLiquid) {
|
||||
this.renderCache = packetLiquid.displayLiquid;
|
||||
}
|
||||
|
||||
/** ITankContainer implementation **/
|
||||
|
||||
@Override
|
||||
|
|
|
@ -168,7 +168,7 @@ public class PipeTransportPower extends PipeTransport {
|
|||
PacketPowerUpdate packet = new PacketPowerUpdate(xCoord, yCoord, zCoord);
|
||||
packet.displayPower = displayPower;
|
||||
CoreProxy.proxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord,
|
||||
DefaultProps.NETWORK_UPDATE_RANGE);
|
||||
DefaultProps.PIPE_CONTENTS_RENDER_DIST);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,20 +9,8 @@
|
|||
|
||||
package buildcraft.transport;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import cpw.mods.fml.common.Side;
|
||||
import cpw.mods.fml.common.asm.SideOnly;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.gates.IOverrideDefaultTriggers;
|
||||
|
@ -30,11 +18,12 @@ import buildcraft.api.gates.ITrigger;
|
|||
import buildcraft.api.power.IPowerProvider;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.IPipe.WireColor;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeEntry;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.IPipedItem;
|
||||
import buildcraft.api.transport.IPipe.WireColor;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.EntityPassiveItem;
|
||||
import buildcraft.core.IDropControlInventory;
|
||||
import buildcraft.core.ITileBufferHolder;
|
||||
|
@ -45,12 +34,21 @@ import buildcraft.core.network.PacketTileState;
|
|||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.transport.Gate.GateKind;
|
||||
import buildcraft.transport.network.PipeRenderStatePacket;
|
||||
|
||||
import cpw.mods.fml.common.Side;
|
||||
import cpw.mods.fml.common.asm.SideOnly;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
|
||||
public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITankContainer, IPipeEntry,
|
||||
IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState,
|
||||
|
@ -389,6 +387,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
|||
} else {
|
||||
coreState.gateKind = 0;
|
||||
}
|
||||
|
||||
if(pipe != null && pipe.transport != null){
|
||||
pipe.transport.sendDescriptionPacket();
|
||||
}
|
||||
|
||||
packet.addStateForSerialization((byte) 0, coreState);
|
||||
packet.addStateForSerialization((byte) 1, renderState);
|
||||
if (pipe instanceof IClientState) {
|
||||
|
@ -613,7 +616,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
|||
if (pipe == null && coreState.pipeId != 0){
|
||||
initialize(BlockGenericPipe.createPipe(coreState.pipeId));
|
||||
}
|
||||
if (pipe != null) {
|
||||
if (pipe != null && coreState.gateKind != GateKind.None.ordinal()) {
|
||||
if (pipe.gate == null) {
|
||||
pipe.gate = new GateVanilla(pipe);
|
||||
}
|
||||
|
@ -627,7 +630,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ITank
|
|||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double func_82115_m() {
|
||||
return 24 * 24;
|
||||
return DefaultProps.PIPE_CONTENTS_RENDER_DIST * DefaultProps.PIPE_CONTENTS_RENDER_DIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
package buildcraft.transport.network;
|
||||
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketSlotChange;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.PipeTransportPower;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.gui.ContainerGateInterface;
|
||||
import buildcraft.transport.pipes.PipeLogicDiamond;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import net.minecraft.src.Container;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.EntityPlayerMP;
|
||||
|
@ -10,18 +20,6 @@ import net.minecraft.src.INetworkManager;
|
|||
import net.minecraft.src.Packet250CustomPayload;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketSlotChange;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.PipeTransportLiquids;
|
||||
import buildcraft.transport.PipeTransportPower;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.gui.ContainerGateInterface;
|
||||
import buildcraft.transport.pipes.PipeLogicDiamond;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketHandlerTransport implements IPacketHandler {
|
||||
|
||||
|
@ -43,7 +41,6 @@ public class PacketHandlerTransport implements IPacketHandler {
|
|||
case PacketIds.PIPE_LIQUID:
|
||||
PacketLiquidUpdate packetLiquid = new PacketLiquidUpdate();
|
||||
packetLiquid.readData(data);
|
||||
onPacketLiquid((EntityPlayer)player, packetLiquid);
|
||||
break;
|
||||
case PacketIds.PIPE_DESCRIPTION:
|
||||
PipeRenderStatePacket descPacket = new PipeRenderStatePacket();
|
||||
|
@ -220,25 +217,6 @@ public class PacketHandlerTransport implements IPacketHandler {
|
|||
|
||||
}
|
||||
|
||||
private void onPacketLiquid(EntityPlayer player, PacketLiquidUpdate packetLiquid) {
|
||||
World world = player.worldObj;
|
||||
if (!world.blockExists(packetLiquid.posX, packetLiquid.posY, packetLiquid.posZ))
|
||||
return;
|
||||
|
||||
TileEntity entity = world.getBlockTileEntity(packetLiquid.posX, packetLiquid.posY, packetLiquid.posZ);
|
||||
if (!(entity instanceof TileGenericPipe))
|
||||
return;
|
||||
|
||||
TileGenericPipe pipe = (TileGenericPipe) entity;
|
||||
if (pipe.pipe == null)
|
||||
return;
|
||||
|
||||
if (!(pipe.pipe.transport instanceof PipeTransportLiquids))
|
||||
return;
|
||||
|
||||
((PipeTransportLiquids) pipe.pipe.transport).handleLiquidPacket(packetLiquid);
|
||||
}
|
||||
|
||||
/******************** SERVER ******************** **/
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,54 +1,137 @@
|
|||
package buildcraft.transport.network;
|
||||
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.transport.PipeTransportLiquids;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
|
||||
|
||||
public class PacketLiquidUpdate extends PacketCoordinates {
|
||||
|
||||
public LiquidStack[] displayLiquid = new LiquidStack[ForgeDirection.values().length];
|
||||
public LiquidStack[] renderCache = new LiquidStack[ForgeDirection.values().length];
|
||||
public BitSet delta;
|
||||
|
||||
public PacketLiquidUpdate(int xCoord, int yCoord, int zCoord) {
|
||||
super(PacketIds.PIPE_LIQUID, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public PacketLiquidUpdate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
for (ForgeDirection direction : ForgeDirection.values()){
|
||||
int liquidId = data.readInt();
|
||||
int liquidQuantity = data.readInt();
|
||||
int liquidMeta = data.readInt();
|
||||
displayLiquid[direction.ordinal()] = new LiquidStack(liquidId, liquidQuantity, liquidMeta);
|
||||
|
||||
World world = CoreProxy.proxy.getClientWorld();
|
||||
if (!world.blockExists(posX, posY, posZ)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity entity = world.getBlockTileEntity(posX, posY, posZ);
|
||||
if (!(entity instanceof TileGenericPipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileGenericPipe pipe = (TileGenericPipe) entity;
|
||||
if (pipe.pipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(pipe.pipe.transport instanceof PipeTransportLiquids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderCache = ((PipeTransportLiquids) pipe.pipe.transport).renderCache;
|
||||
|
||||
byte[] dBytes = new byte[3];
|
||||
data.read(dBytes);
|
||||
delta = fromByteArray(dBytes);
|
||||
|
||||
// System.out.printf("read %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
if (renderCache[dir.ordinal()] == null) {
|
||||
renderCache[dir.ordinal()] = new LiquidStack(0, 0, 0);
|
||||
}
|
||||
|
||||
if (delta.get(dir.ordinal() * 3 + 0)) {
|
||||
renderCache[dir.ordinal()].itemID = data.readShort();
|
||||
}
|
||||
if (delta.get(dir.ordinal() * 3 + 1)) {
|
||||
renderCache[dir.ordinal()].itemMeta = data.readShort();
|
||||
}
|
||||
if (delta.get(dir.ordinal() * 3 + 2)) {
|
||||
renderCache[dir.ordinal()].amount = data.readShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
for (ForgeDirection direction : ForgeDirection.values()){
|
||||
if (displayLiquid[direction.ordinal()] != null){
|
||||
data.writeInt(displayLiquid[direction.ordinal()].itemID);
|
||||
data.writeInt(displayLiquid[direction.ordinal()].amount);
|
||||
data.writeInt(displayLiquid[direction.ordinal()].itemMeta);
|
||||
|
||||
byte[] dBytes = toByteArray(delta);
|
||||
// System.out.printf("write %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta);
|
||||
data.write(dBytes);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.values()) {
|
||||
LiquidStack liquid = renderCache[dir.ordinal()];
|
||||
|
||||
if (delta.get(dir.ordinal() * 3 + 0)) {
|
||||
if (liquid != null) {
|
||||
data.writeShort(liquid.itemID);
|
||||
} else {
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
data.writeShort(0);
|
||||
}
|
||||
}
|
||||
if (delta.get(dir.ordinal() * 3 + 1)) {
|
||||
if (liquid != null) {
|
||||
data.writeShort(liquid.itemMeta);
|
||||
} else {
|
||||
data.writeShort(0);
|
||||
}
|
||||
}
|
||||
if (delta.get(dir.ordinal() * 3 + 2)) {
|
||||
if (liquid != null) {
|
||||
data.writeShort(liquid.amount);
|
||||
} else {
|
||||
data.writeShort(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static BitSet fromByteArray(byte[] bytes) {
|
||||
BitSet bits = new BitSet();
|
||||
for (int i = 0; i < bytes.length * 8; i++) {
|
||||
if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) {
|
||||
bits.set(i);
|
||||
}
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(BitSet bits) {
|
||||
byte[] bytes = new byte[3];
|
||||
for (int i = 0; i < bits.length(); i++) {
|
||||
if (bits.get(i)) {
|
||||
bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return PacketIds.PIPE_LIQUID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,78 +1,124 @@
|
|||
package buildcraft.transport.network;
|
||||
|
||||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.transport.EntityData;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
public class PacketPipeTransportContent extends PacketCoordinates {
|
||||
|
||||
import buildcraft.transport.EntityData;
|
||||
private EntityData entityData;
|
||||
|
||||
public class PacketPipeTransportContent extends PacketUpdate {
|
||||
private int entityId;
|
||||
|
||||
public PacketPipeTransportContent() {
|
||||
super(PacketIds.PIPE_CONTENTS);
|
||||
}
|
||||
private ForgeDirection input;
|
||||
private ForgeDirection output;
|
||||
|
||||
private int itemId;
|
||||
private byte stackSize;
|
||||
private int itemDamage;
|
||||
|
||||
private float itemX;
|
||||
private float itemY;
|
||||
private float itemZ;
|
||||
|
||||
private float speed;
|
||||
|
||||
public PacketPipeTransportContent() {}
|
||||
|
||||
public PacketPipeTransportContent(int x, int y, int z, EntityData data) {
|
||||
this();
|
||||
super(PacketIds.PIPE_CONTENTS, x, y, z);
|
||||
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
this.entityData = data;
|
||||
}
|
||||
|
||||
this.payload = new PacketPayload(6, 4, 0);
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
payload.intPayload[0] = data.item.getEntityId();
|
||||
payload.intPayload[1] = data.input.ordinal();
|
||||
payload.intPayload[2] = data.output.ordinal();
|
||||
payload.intPayload[3] = data.item.getItemStack().itemID;
|
||||
payload.intPayload[4] = data.item.getItemStack().stackSize;
|
||||
payload.intPayload[5] = data.item.getItemStack().getItemDamage();
|
||||
data.writeInt(entityData.item.getEntityId());
|
||||
|
||||
payload.floatPayload[0] = (float) data.item.getPosition().x;
|
||||
payload.floatPayload[1] = (float) data.item.getPosition().y;
|
||||
payload.floatPayload[2] = (float) data.item.getPosition().z;
|
||||
payload.floatPayload[3] = data.item.getSpeed();
|
||||
data.writeByte((byte)entityData.input.ordinal());
|
||||
data.writeByte((byte)entityData.output.ordinal());
|
||||
|
||||
data.writeInt(entityData.item.getItemStack().itemID);
|
||||
data.writeByte((byte)entityData.item.getItemStack().stackSize);
|
||||
data.writeInt(entityData.item.getItemStack().getItemDamage());
|
||||
|
||||
data.writeFloat((float) entityData.item.getPosition().x);
|
||||
data.writeFloat((float) entityData.item.getPosition().y);
|
||||
data.writeFloat((float) entityData.item.getPosition().z);
|
||||
|
||||
data.writeFloat(entityData.item.getSpeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
this.entityId = data.readInt();
|
||||
|
||||
this.input = ForgeDirection.getOrientation(data.readByte());
|
||||
this.output = ForgeDirection.getOrientation(data.readByte());
|
||||
|
||||
this.itemId = data.readInt();
|
||||
this.stackSize = data.readByte();
|
||||
this.itemDamage = data.readInt();
|
||||
|
||||
this.itemX = data.readFloat();
|
||||
this.itemY = data.readFloat();
|
||||
this.itemZ = data.readFloat();
|
||||
|
||||
this.speed = data.readFloat();
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return payload.intPayload[0];
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public ForgeDirection getInputOrientation() {
|
||||
return ForgeDirection.values()[payload.intPayload[1]];
|
||||
return input;
|
||||
}
|
||||
|
||||
public ForgeDirection getOutputOrientation() {
|
||||
return ForgeDirection.values()[payload.intPayload[2]];
|
||||
return output;
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return payload.intPayload[3];
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public int getStackSize() {
|
||||
return payload.intPayload[4];
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
public int getItemDamage() {
|
||||
return payload.intPayload[5];
|
||||
return itemDamage;
|
||||
}
|
||||
|
||||
public double getPosX() {
|
||||
return payload.floatPayload[0];
|
||||
return itemX;
|
||||
}
|
||||
|
||||
public double getPosY() {
|
||||
return payload.floatPayload[1];
|
||||
return itemY;
|
||||
}
|
||||
|
||||
public double getPosZ() {
|
||||
return payload.floatPayload[2];
|
||||
return itemZ;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return payload.floatPayload[3];
|
||||
return speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return PacketIds.PIPE_CONTENTS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue