Fix issues with serverside networks, make target save to NBT

This commit is contained in:
tterrag1098 committed 2015-02-13 16:11:05 -05:00
1 parent cb17d38101
commit 8ad52a2de0
4 files changed
+64 -21

No files matched your search

@@ -1,7 +1,9 @@
package crazypants.enderio.teleport.telepad;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
@@ -83,6 +85,7 @@ public class BlockTelePad extends BlockTravelAnchor {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileTelePad) {
TileTelePad tp = (TileTelePad) te;
System.out.println(tp.inNetwork() + " " + tp);
if (tp.inNetwork()) {
if (!tp.isMaster()) {
TileTelePad master = tp.getMaster();
@@ -104,6 +107,12 @@ public class BlockTelePad extends BlockTravelAnchor {
}
return true;
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack par6ItemStack) {
super.onBlockPlacedBy(world, x, y, z, entity, par6ItemStack);
((TileTelePad) world.getTileEntity(x, y, z)).updateConnectedState(true);
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -87,8 +87,7 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
}
private void updateCoords() {
Triple<String, String, String> texts = Triple.of(x.getText(), y.getText(), z.getText());
BlockCoord bc = new BlockCoord(texts.getLeft(), texts.getMiddle(), texts.getRight());
BlockCoord bc = new BlockCoord(x.getText(), y.getText(), z.getText());
if(bc.x != te.getX() || bc.y != te.getY() || bc.z != te.getZ()) {
te.setX(bc.x);
te.setY(bc.y);
@@ -5,6 +5,9 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.EnergyStorage;
@@ -42,6 +45,9 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
updateConnectedState(true);
autoUpdate = false;
}
if (isMaster() && !worldObj.isRemote) {
System.out.println(inNetwork() + " " + this);
}
}
public void updateConnectedState(boolean fromBlock) {
@@ -129,6 +135,39 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
return ret;
}
@Override
public boolean canUpdate() {
return true;
}
@Override
protected void writeCustomNBT(NBTTagCompound root) {
super.writeCustomNBT(root);
energy.writeToNBT(root);
target.writeToNBT(root);
}
@Override
protected void readCustomNBT(NBTTagCompound root) {
super.readCustomNBT(root);
energy.readFromNBT(root);
target = new BlockCoord().readFromNBT(root);
autoUpdate = true;
}
@Override
public Packet getDescriptionPacket() {
S35PacketUpdateTileEntity pkt = (S35PacketUpdateTileEntity) super.getDescriptionPacket();
pkt.func_148857_g().setBoolean("inNetwork", inNetwork);
return pkt;
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
this.inNetwork = pkt.func_148857_g().getBoolean("inNetwork");
}
/* ITelePad */
@Override
@@ -196,25 +235,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
}
return null;
}
@Override
public boolean canUpdate() {
return true;
}
@Override
protected void writeCustomNBT(NBTTagCompound root) {
super.writeCustomNBT(root);
energy.writeToNBT(root);
}
@Override
protected void readCustomNBT(NBTTagCompound root) {
super.readCustomNBT(root);
energy.readFromNBT(root);
autoUpdate = true;
}
/* ITravelAccessable overrides */
@Override
@@ -5,6 +5,7 @@ import com.google.common.base.Strings;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@@ -121,4 +122,17 @@ public final class BlockCoord {
public static BlockCoord readFromBuf(ByteBuf buf) {
return new BlockCoord(buf.readInt(), buf.readInt(), buf.readInt());
}
public void writeToNBT(NBTTagCompound tag) {
tag.setInteger("bc:x", x);
tag.setInteger("bc:y", y);
tag.setInteger("bc:z", z);
}
public BlockCoord readFromNBT(NBTTagCompound tag) {
x = tag.getInteger("bc:x");
y = tag.getInteger("bc:y");
z = tag.getInteger("bc:z");
return this;
}
}