fixed get description packets
This commit is contained in:
parent
32e3d44e13
commit
944b9d693b
6 changed files with 75 additions and 30 deletions
|
@ -109,7 +109,10 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
public static int updateFactor = 10;
|
||||
public static long longUpdateFactor = 40;
|
||||
public static BuildCraftConfiguration mainConfiguration;
|
||||
|
||||
// TODO: This doesn't seem used anymore. Remove if it's the case.
|
||||
public static TreeMap<BlockIndex, PacketUpdate> bufferedDescriptions = new TreeMap<BlockIndex, PacketUpdate>();
|
||||
|
||||
public static final int trackedPassiveEntityId = 156;
|
||||
public static boolean continuousCurrentModel;
|
||||
public static Block springBlock;
|
||||
|
|
|
@ -19,16 +19,22 @@ import buildcraft.core.network.PacketUpdate;
|
|||
import buildcraft.core.network.TilePacketWrapper;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.EmptyByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.buffer.UnpooledHeapByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -100,11 +106,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
// TODO: The description packet mechanism seems to have completely be replaced by other means, e.g.
|
||||
// the update packet. If confirmed, remove the buffer packet mechanism in Utils as well, that is
|
||||
// BuildCraftCore.bufferedDescriptions.
|
||||
//return new PacketTileUpdate(this).getPacket();
|
||||
return null;
|
||||
return Utils.toPacket(getUpdatePacket(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,8 +128,9 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
if (packet.payload instanceof PacketPayloadArrays)
|
||||
updatePacket.fromPayload(this, (PacketPayloadArrays) packet.payload);
|
||||
if (packet.payload instanceof PacketPayloadArrays) {
|
||||
updatePacket.fromPayload(this, (PacketPayloadArrays) packet.payload);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,15 +17,18 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
|||
public class PacketHandler extends BuildCraftChannelHandler {
|
||||
|
||||
private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException {
|
||||
World world = player.worldObj;
|
||||
|
||||
if (!packet.targetExists(world))
|
||||
World world = player.worldObj;
|
||||
|
||||
if (!packet.targetExists(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity entity = packet.getTarget(world);
|
||||
if (!(entity instanceof ISynchronizedTile))
|
||||
|
||||
if (!(entity instanceof ISynchronizedTile)) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ISynchronizedTile tile = (ISynchronizedTile) entity;
|
||||
tile.handleUpdatePacket(packet);
|
||||
tile.postPacketHandling(packet);
|
||||
|
|
|
@ -38,7 +38,6 @@ public class PacketUpdate extends BuildCraftPacket {
|
|||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
|
||||
data.writeInt(posX);
|
||||
data.writeInt(posY);
|
||||
data.writeInt(posZ);
|
||||
|
@ -53,7 +52,6 @@ public class PacketUpdate extends BuildCraftPacket {
|
|||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
|
||||
posX = data.readInt();
|
||||
posY = data.readInt();
|
||||
posZ = data.readInt();
|
||||
|
@ -62,8 +60,9 @@ public class PacketUpdate extends BuildCraftPacket {
|
|||
|
||||
payload = PacketPayload.makePayload(type);
|
||||
|
||||
if (payload != null)
|
||||
if (payload != null) {
|
||||
payload.readData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ import buildcraft.api.core.Position;
|
|||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.EntityBlock;
|
||||
import buildcraft.core.IDropControlInventory;
|
||||
import buildcraft.core.IFramePipeConnection;
|
||||
|
@ -21,11 +22,14 @@ import buildcraft.core.TileBuildCraft;
|
|||
import buildcraft.core.inventory.ITransactor;
|
||||
import buildcraft.core.inventory.InvUtils;
|
||||
import buildcraft.core.inventory.Transactor;
|
||||
import buildcraft.core.network.BuildCraftPacket;
|
||||
import buildcraft.core.network.ISynchronizedTile;
|
||||
import buildcraft.core.network.PacketTileUpdate;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.energy.TileEngine;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -36,6 +40,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -484,4 +489,23 @@ public class Utils {
|
|||
return ItemStack.loadItemStackFromNBT(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This subprogram transforms a packet into a FML packet to be send in the
|
||||
* minecraft default packet mechanism. This always use BC-CORE as a
|
||||
* channel, and as a result, should use discriminators declared there.
|
||||
*
|
||||
* WARNING! The implementation of this subprogram relies on the internal
|
||||
* behavior of #FMLIndexedMessageToMessageCodec (in particular the encode
|
||||
* member). It is probably opening a maintenance issue and should be
|
||||
* replaced eventually by some more solid mechanism.
|
||||
*/
|
||||
public static FMLProxyPacket toPacket (BuildCraftPacket packet, int discriminator) {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
||||
buf.writeByte((byte) discriminator);
|
||||
packet.writeData(buf);
|
||||
|
||||
return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
public static final ResourceLocation IRON_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png");
|
||||
|
||||
public enum EnergyStage {
|
||||
|
||||
BLUE, GREEN, YELLOW, RED, OVERHEAT;
|
||||
public static final EnergyStage[] VALUES = values();
|
||||
}
|
||||
|
||||
public static final float MIN_HEAT = 20;
|
||||
public static final float IDEAL_HEAT = 100;
|
||||
public static final float MAX_HEAT = 250;
|
||||
|
@ -135,8 +135,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
}
|
||||
|
||||
public float getPistonSpeed() {
|
||||
if (CoreProxy.proxy.isSimulating(worldObj))
|
||||
if (CoreProxy.proxy.isSimulating(worldObj)) {
|
||||
return Math.max(0.16f * getHeatLevel(), 0.01f);
|
||||
}
|
||||
|
||||
switch (getEnergyStage()) {
|
||||
case BLUE:
|
||||
return 0.02F;
|
||||
|
@ -163,21 +165,26 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
progressPart = 0;
|
||||
progress = 0;
|
||||
}
|
||||
} else if (this.isPumping)
|
||||
} else if (this.isPumping) {
|
||||
progressPart = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkOrienation) {
|
||||
checkOrienation = false;
|
||||
if (!isOrientationValid())
|
||||
|
||||
if (!isOrientationValid()) {
|
||||
switchOrientation(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isRedstonePowered)
|
||||
if (energy > 1)
|
||||
if (!isRedstonePowered) {
|
||||
if (energy > 1) {
|
||||
energy--;
|
||||
}
|
||||
}
|
||||
|
||||
updateHeatLevel();
|
||||
getEnergyStage();
|
||||
|
@ -195,17 +202,20 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
progress = 0;
|
||||
progressPart = 0;
|
||||
}
|
||||
} else if (isRedstonePowered && isActive())
|
||||
if (isPoweredTile(tile, orientation))
|
||||
} else if (isRedstonePowered && isActive()) {
|
||||
if (isPoweredTile(tile, orientation)) {
|
||||
if (getPowerToExtract() > 0) {
|
||||
progressPart = 1;
|
||||
setPumping(true);
|
||||
} else
|
||||
} else {
|
||||
setPumping(false);
|
||||
else
|
||||
}
|
||||
} else {
|
||||
setPumping(false);
|
||||
else
|
||||
}
|
||||
} else {
|
||||
setPumping(false);
|
||||
}
|
||||
|
||||
// Uncomment for constant power
|
||||
// if (isRedstonePowered && isActive()) {
|
||||
|
@ -318,12 +328,13 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
orientation = ForgeDirection.getOrientation(data.getInteger("orientation"));
|
||||
progress = data.getFloat("progress");
|
||||
energy = data.getDouble("energy");
|
||||
heat = data.getFloat("heat");
|
||||
heat = data.getFloat("heat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
data.setInteger("orientation", orientation.ordinal());
|
||||
data.setFloat("progress", progress);
|
||||
data.setDouble("energy", energy);
|
||||
|
@ -456,11 +467,13 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
@Override
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) {
|
||||
if (type == PipeType.POWER)
|
||||
if (type == PipeType.POWER) {
|
||||
return ConnectOverride.DEFAULT;
|
||||
if (with == orientation)
|
||||
} else if (with == orientation) {
|
||||
return ConnectOverride.DISCONNECT;
|
||||
return ConnectOverride.DEFAULT;
|
||||
} else {
|
||||
return ConnectOverride.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue