Work on Portable Teleporter, need to fix the screwed up GUI
This commit is contained in:
parent
9043e12938
commit
6d36926866
11 changed files with 467 additions and 349 deletions
|
@ -1,8 +1,11 @@
|
|||
package mekanism.api;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -15,8 +18,6 @@ import net.minecraft.world.chunk.Chunk;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Coord4D - an integer-based way to keep track of and perform operations on blocks in a Minecraft-based environment. This also takes
|
||||
* in account the dimension the coordinate is in.
|
||||
|
@ -45,6 +46,19 @@ public class Coord4D
|
|||
|
||||
dimensionId = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Coord4D from an entity's position, rounded down.
|
||||
* @param entity - entity to create the Coord4D from
|
||||
*/
|
||||
public Coord4D(Entity entity)
|
||||
{
|
||||
xCoord = (int)entity.posX;
|
||||
yCoord = (int)entity.posY;
|
||||
zCoord = (int)entity.posZ;
|
||||
|
||||
dimensionId = entity.worldObj.provider.dimensionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Coord4D from the defined x, y, z, and dimension values.
|
||||
|
|
|
@ -116,6 +116,7 @@ import mekanism.common.inventory.InventoryElectricChest;
|
|||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.item.ItemSeismicReader;
|
||||
import mekanism.common.multiblock.MultiblockManager;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.tile.TileEntityAdvancedElectricMachine;
|
||||
import mekanism.common.tile.TileEntityAdvancedFactory;
|
||||
import mekanism.common.tile.TileEntityAmbientAccumulator;
|
||||
|
@ -509,10 +510,26 @@ public class ClientProxy extends CommonProxy
|
|||
case 51:
|
||||
return new GuiTransporterConfig(player, (ISideConfiguration)tileEntity);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTeleporterUpdate(PortableTeleporterMessage message)
|
||||
{
|
||||
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if(screen instanceof GuiTeleporter && ((GuiTeleporter)screen).itemStack != null)
|
||||
{
|
||||
GuiTeleporter teleporter = (GuiTeleporter)screen;
|
||||
|
||||
teleporter.clientStatus = message.status;
|
||||
teleporter.clientFreq = message.frequency;
|
||||
teleporter.clientPublicCache = message.publicCache;
|
||||
teleporter.clientPrivateCache = message.privateCache;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHitEffects(Coord4D coord, MovingObjectPosition mop)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,8 @@ import mekanism.common.frequency.Frequency;
|
|||
import mekanism.common.inventory.container.ContainerNull;
|
||||
import mekanism.common.inventory.container.ContainerTeleporter;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterPacketType;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.tile.TileEntityTeleporter;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
@ -57,6 +59,12 @@ public class GuiTeleporter extends GuiMekanism
|
|||
public GuiTextField frequencyField;
|
||||
|
||||
public boolean privateMode;
|
||||
|
||||
public Frequency clientFreq;
|
||||
public byte clientStatus;
|
||||
|
||||
public List<Frequency> clientPublicCache = new ArrayList<Frequency>();
|
||||
public List<Frequency> clientPrivateCache = new ArrayList<Frequency>();
|
||||
|
||||
public GuiTeleporter(InventoryPlayer inventory, TileEntityTeleporter tentity)
|
||||
{
|
||||
|
@ -134,6 +142,8 @@ public class GuiTeleporter extends GuiMekanism
|
|||
buttonList.add(privateButton);
|
||||
buttonList.add(setButton);
|
||||
buttonList.add(deleteButton);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new PortableTeleporterMessage(PortableTeleporterPacketType.DATA_REQUEST, clientFreq));
|
||||
}
|
||||
|
||||
public void setFrequency(String freq)
|
||||
|
@ -143,12 +153,20 @@ public class GuiTeleporter extends GuiMekanism
|
|||
return;
|
||||
}
|
||||
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(0);
|
||||
data.add(freq);
|
||||
data.add(!privateMode);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
|
||||
if(tileEntity != null)
|
||||
{
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(0);
|
||||
data.add(freq);
|
||||
data.add(!privateMode);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
|
||||
}
|
||||
else {
|
||||
Frequency newFreq = new Frequency(freq, null).setPublic(!privateMode);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new PortableTeleporterMessage(PortableTeleporterPacketType.SET_FREQ, newFreq));
|
||||
}
|
||||
}
|
||||
|
||||
public String getSecurity(Frequency freq)
|
||||
|
@ -167,13 +185,13 @@ public class GuiTeleporter extends GuiMekanism
|
|||
|
||||
if(privateMode)
|
||||
{
|
||||
for(Frequency freq : tileEntity.privateCache)
|
||||
for(Frequency freq : getPrivateCache())
|
||||
{
|
||||
text.add(freq.name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(Frequency freq : tileEntity.publicCache)
|
||||
for(Frequency freq : getPublicCache())
|
||||
{
|
||||
text.add(freq.name + " (" + freq.owner + ")");
|
||||
}
|
||||
|
@ -193,7 +211,7 @@ public class GuiTeleporter extends GuiMekanism
|
|||
|
||||
if(scrollList.hasSelection())
|
||||
{
|
||||
Frequency freq = privateMode ? tileEntity.privateCache.get(scrollList.selected) : tileEntity.publicCache.get(scrollList.selected);
|
||||
Frequency freq = privateMode ? getPrivateCache().get(scrollList.selected) : getPublicCache().get(scrollList.selected);
|
||||
|
||||
if(getFrequency() == null || !getFrequency().equals(freq))
|
||||
{
|
||||
|
@ -294,7 +312,7 @@ public class GuiTeleporter extends GuiMekanism
|
|||
|
||||
if(selection != -1)
|
||||
{
|
||||
Frequency freq = privateMode ? tileEntity.privateCache.get(selection) : tileEntity.publicCache.get(selection);
|
||||
Frequency freq = privateMode ? getPrivateCache().get(selection) : getPublicCache().get(selection);
|
||||
setFrequency(freq.name);
|
||||
}
|
||||
}
|
||||
|
@ -304,14 +322,21 @@ public class GuiTeleporter extends GuiMekanism
|
|||
|
||||
if(selection != -1)
|
||||
{
|
||||
Frequency freq = privateMode ? tileEntity.privateCache.get(selection) : tileEntity.publicCache.get(selection);
|
||||
Frequency freq = privateMode ? getPrivateCache().get(selection) : getPublicCache().get(selection);
|
||||
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(1);
|
||||
data.add(freq.name);
|
||||
data.add(freq.publicFreq);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
|
||||
if(tileEntity != null)
|
||||
{
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(1);
|
||||
data.add(freq.name);
|
||||
data.add(freq.publicFreq);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
|
||||
}
|
||||
else {
|
||||
Mekanism.packetHandler.sendToServer(new PortableTeleporterMessage(PortableTeleporterPacketType.DEL_FREQ, freq));
|
||||
Mekanism.packetHandler.sendToServer(new PortableTeleporterMessage(PortableTeleporterPacketType.DATA_REQUEST, null));
|
||||
}
|
||||
|
||||
scrollList.selected = -1;
|
||||
}
|
||||
|
@ -380,6 +405,8 @@ public class GuiTeleporter extends GuiMekanism
|
|||
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
||||
|
||||
frequencyField.drawTextBox();
|
||||
|
||||
System.out.println(xSize + " " + ySize);
|
||||
}
|
||||
|
||||
public String getStatusDisplay()
|
||||
|
@ -406,12 +433,22 @@ public class GuiTeleporter extends GuiMekanism
|
|||
|
||||
private byte getStatus()
|
||||
{
|
||||
return tileEntity.status;
|
||||
return tileEntity != null ? tileEntity.status : clientStatus;
|
||||
}
|
||||
|
||||
private List<Frequency> getPublicCache()
|
||||
{
|
||||
return tileEntity != null ? tileEntity.publicCache : clientPublicCache;
|
||||
}
|
||||
|
||||
private List<Frequency> getPrivateCache()
|
||||
{
|
||||
return tileEntity != null ? tileEntity.privateCache : clientPrivateCache;
|
||||
}
|
||||
|
||||
private Frequency getFrequency()
|
||||
{
|
||||
return tileEntity.frequency;
|
||||
return tileEntity != null ? tileEntity.frequency : clientFreq;
|
||||
}
|
||||
|
||||
private String getInventoryName()
|
||||
|
|
|
@ -7,11 +7,8 @@ import mekanism.common.item.ItemFreeRunners;
|
|||
import mekanism.common.item.ItemGasMask;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import mekanism.common.item.ItemJetpack.JetpackMode;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.item.ItemScubaTank;
|
||||
import mekanism.common.network.PacketStatusUpdate.StatusUpdateMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -34,60 +31,6 @@ public class CommonPlayerTickHandler
|
|||
|
||||
public void tickEnd(EntityPlayer player)
|
||||
{
|
||||
if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemPortableTeleporter)
|
||||
{
|
||||
ItemPortableTeleporter item = (ItemPortableTeleporter)player.getCurrentEquippedItem().getItem();
|
||||
ItemStack itemstack = player.getCurrentEquippedItem();
|
||||
|
||||
/*Teleporter.Code teleCode = new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3));
|
||||
|
||||
if(Mekanism.teleporters.containsKey(teleCode))
|
||||
{
|
||||
if(Mekanism.teleporters.get(teleCode).size() > 0 && Mekanism.teleporters.get(teleCode).size() <= 2)
|
||||
{
|
||||
int energyNeeded = item.calculateEnergyCost(player, MekanismUtils.getClosestCoords(teleCode, player));
|
||||
|
||||
if(item.getEnergy(itemstack) < energyNeeded)
|
||||
{
|
||||
if(item.getStatus(itemstack) != 2)
|
||||
{
|
||||
item.setStatus(itemstack, 2);
|
||||
Mekanism.packetHandler.sendTo(new StatusUpdateMessage(2), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(item.getStatus(itemstack) != 1)
|
||||
{
|
||||
item.setStatus(itemstack, 1);
|
||||
Mekanism.packetHandler.sendTo(new StatusUpdateMessage(1), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Mekanism.teleporters.get(teleCode).size() > 2)
|
||||
{
|
||||
if(item.getStatus(itemstack) != 3)
|
||||
{
|
||||
item.setStatus(itemstack, 3);
|
||||
Mekanism.packetHandler.sendTo(new StatusUpdateMessage(3), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(item.getStatus(itemstack) != 4)
|
||||
{
|
||||
item.setStatus(itemstack, 4);
|
||||
Mekanism.packetHandler.sendTo(new StatusUpdateMessage(4), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(item.getStatus(itemstack) != 4)
|
||||
{
|
||||
item.setStatus(itemstack, 4);
|
||||
Mekanism.packetHandler.sendTo(new StatusUpdateMessage(4), (EntityPlayerMP)player);
|
||||
}
|
||||
}TODO*/
|
||||
}
|
||||
|
||||
if(player.getEquipmentInSlot(1) != null && player.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners)
|
||||
{
|
||||
player.stepHeight = 1.002F;
|
||||
|
|
|
@ -50,6 +50,7 @@ import mekanism.common.inventory.container.ContainerSolarEvaporationController;
|
|||
import mekanism.common.inventory.container.ContainerSolarNeutronActivator;
|
||||
import mekanism.common.inventory.container.ContainerTeleporter;
|
||||
import mekanism.common.inventory.container.ContainerUpgradeManagement;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.tile.TileEntityAdvancedElectricMachine;
|
||||
import mekanism.common.tile.TileEntityAdvancedFactory;
|
||||
import mekanism.common.tile.TileEntityAmbientAccumulator;
|
||||
|
@ -173,6 +174,8 @@ public class CommonProxy
|
|||
GameRegistry.registerTileEntity(TileEntityInductionCell.class, "InductionCell");
|
||||
GameRegistry.registerTileEntity(TileEntityInductionProvider.class, "InductionProvider");
|
||||
}
|
||||
|
||||
public void handleTeleporterUpdate(PortableTeleporterMessage message) {}
|
||||
|
||||
/**
|
||||
* Handles an ELECTRIC_CHEST_CLIENT_OPEN packet via the proxy, not handled on the server-side.
|
||||
|
|
|
@ -18,8 +18,6 @@ import mekanism.common.network.PacketContainerEditMode;
|
|||
import mekanism.common.network.PacketContainerEditMode.ContainerEditModeMessage;
|
||||
import mekanism.common.network.PacketDataRequest;
|
||||
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
|
||||
import mekanism.common.network.PacketDigitUpdate;
|
||||
import mekanism.common.network.PacketDigitUpdate.DigitUpdateMessage;
|
||||
import mekanism.common.network.PacketDigitalMinerGui;
|
||||
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
|
||||
import mekanism.common.network.PacketDropperUse;
|
||||
|
@ -42,8 +40,8 @@ import mekanism.common.network.PacketNewFilter;
|
|||
import mekanism.common.network.PacketNewFilter.NewFilterMessage;
|
||||
import mekanism.common.network.PacketPortableTankState;
|
||||
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
|
||||
import mekanism.common.network.PacketPortableTeleport;
|
||||
import mekanism.common.network.PacketPortableTeleport.PortableTeleportMessage;
|
||||
import mekanism.common.network.PacketPortableTeleporter;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.network.PacketPortalFX;
|
||||
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
|
||||
import mekanism.common.network.PacketRedstoneControl;
|
||||
|
@ -56,8 +54,6 @@ import mekanism.common.network.PacketScubaTankData;
|
|||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.network.PacketSimpleGui;
|
||||
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
||||
import mekanism.common.network.PacketStatusUpdate;
|
||||
import mekanism.common.network.PacketStatusUpdate.StatusUpdateMessage;
|
||||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.network.PacketTransmitterUpdate;
|
||||
|
@ -101,9 +97,9 @@ public class PacketHandler
|
|||
netHandler.registerMessage(PacketTileEntity.class, TileEntityMessage.class, 5, Side.SERVER);
|
||||
netHandler.registerMessage(PacketPortalFX.class, PortalFXMessage.class, 6, Side.CLIENT);
|
||||
netHandler.registerMessage(PacketDataRequest.class, DataRequestMessage.class, 7, Side.SERVER);
|
||||
netHandler.registerMessage(PacketStatusUpdate.class, StatusUpdateMessage.class, 8, Side.CLIENT);
|
||||
netHandler.registerMessage(PacketDigitUpdate.class, DigitUpdateMessage.class, 9, Side.SERVER);
|
||||
netHandler.registerMessage(PacketPortableTeleport.class, PortableTeleportMessage.class, 10, Side.SERVER);
|
||||
//EMPTY SLOTS 8 & 9
|
||||
netHandler.registerMessage(PacketPortableTeleporter.class, PortableTeleporterMessage.class, 10, Side.CLIENT);
|
||||
netHandler.registerMessage(PacketPortableTeleporter.class, PortableTeleporterMessage.class, 10, Side.SERVER);
|
||||
netHandler.registerMessage(PacketRemoveUpgrade.class, RemoveUpgradeMessage.class, 11, Side.SERVER);
|
||||
netHandler.registerMessage(PacketRedstoneControl.class, RedstoneControlMessage.class, 12, Side.SERVER);
|
||||
netHandler.registerMessage(PacketWalkieTalkieState.class, WalkieTalkieStateMessage.class, 13, Side.SERVER);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ItemPortableTeleporter extends ItemEnergized
|
|||
return itemstack;
|
||||
}
|
||||
|
||||
public int calculateEnergyCost(Entity entity, Coord4D coords)
|
||||
public static double calculateEnergyCost(Entity entity, Coord4D coords)
|
||||
{
|
||||
if(coords == null)
|
||||
{
|
||||
|
@ -46,65 +46,6 @@ public class ItemPortableTeleporter extends ItemEnergized
|
|||
return neededEnergy;
|
||||
}
|
||||
|
||||
public String getStatusAsString(int i)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
return EnumColor.DARK_RED + MekanismUtils.localize("gui.teleporter.notReady");
|
||||
case 1:
|
||||
return EnumColor.DARK_GREEN + MekanismUtils.localize("gui.teleporter.ready");
|
||||
case 2:
|
||||
return EnumColor.DARK_RED + MekanismUtils.localize("gui.teleporter.needsEnergy");
|
||||
case 3:
|
||||
return EnumColor.DARK_RED + MekanismUtils.localize("gui.teleporter.exceeds");
|
||||
case 4:
|
||||
return EnumColor.DARK_RED + MekanismUtils.localize("gui.teleporter.noLink");
|
||||
default:
|
||||
return EnumColor.DARK_RED + MekanismUtils.localize("gui.teleporter.notReady");
|
||||
}
|
||||
}
|
||||
|
||||
public int getStatus(ItemStack itemstack)
|
||||
{
|
||||
if(itemstack.stackTagCompound == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return itemstack.stackTagCompound.getInteger("status");
|
||||
}
|
||||
|
||||
public void setStatus(ItemStack itemstack, int status)
|
||||
{
|
||||
if(itemstack.stackTagCompound == null)
|
||||
{
|
||||
itemstack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
itemstack.stackTagCompound.setInteger("status", status);
|
||||
}
|
||||
|
||||
public int getDigit(ItemStack itemstack, int index)
|
||||
{
|
||||
if(itemstack.stackTagCompound == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return itemstack.stackTagCompound.getInteger("digit"+index);
|
||||
}
|
||||
|
||||
public void setDigit(ItemStack itemstack, int index, int digit)
|
||||
{
|
||||
if(itemstack.stackTagCompound == null)
|
||||
{
|
||||
itemstack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
itemstack.stackTagCompound.setInteger("digit"+index, digit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSend(ItemStack itemStack)
|
||||
{
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.network.PacketDigitUpdate.DigitUpdateMessage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PacketDigitUpdate implements IMessageHandler<DigitUpdateMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(DigitUpdateMessage message, MessageContext context)
|
||||
{
|
||||
ItemStack currentStack = PacketHandler.getPlayer(context).getCurrentEquippedItem();
|
||||
|
||||
if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
|
||||
{
|
||||
ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
|
||||
item.setDigit(currentStack, message.index, message.digit);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class DigitUpdateMessage implements IMessage
|
||||
{
|
||||
public int index;
|
||||
public int digit;
|
||||
|
||||
public DigitUpdateMessage() {}
|
||||
|
||||
public DigitUpdateMessage(int ind, int dig)
|
||||
{
|
||||
index = ind;
|
||||
digit = dig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(index);
|
||||
dataStream.writeInt(digit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf dataStream)
|
||||
{
|
||||
index = dataStream.readInt();
|
||||
digit = dataStream.readInt();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.ObfuscatedNames;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.network.PacketPortableTeleport.PortableTeleportMessage;
|
||||
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
|
||||
import mekanism.common.tile.TileEntityTeleporter;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketPortableTeleport implements IMessageHandler<PortableTeleportMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PortableTeleportMessage message, MessageContext context)
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
ItemStack itemstack = player.getCurrentEquippedItem();
|
||||
World world = player.worldObj;
|
||||
|
||||
if(itemstack != null && itemstack.getItem() instanceof ItemPortableTeleporter)
|
||||
{
|
||||
ItemPortableTeleporter item = (ItemPortableTeleporter)itemstack.getItem();
|
||||
|
||||
if(item.getStatus(itemstack) == 1)
|
||||
{
|
||||
Coord4D coords = null;//TODO MekanismUtils.getClosestCoords(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3)), player);
|
||||
|
||||
World teleWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(coords.dimensionId);
|
||||
TileEntityTeleporter teleporter = (TileEntityTeleporter)coords.getTileEntity(teleWorld);
|
||||
|
||||
if(teleporter != null)
|
||||
{
|
||||
try {
|
||||
teleporter.didTeleport.add(player);
|
||||
teleporter.teleDelay = 5;
|
||||
|
||||
item.setEnergy(itemstack, item.getEnergy(itemstack) - item.calculateEnergyCost(player, coords));
|
||||
|
||||
if(player instanceof EntityPlayerMP)
|
||||
{
|
||||
MekanismUtils.setPrivateValue(((EntityPlayerMP)player).playerNetServerHandler, 0, NetHandlerPlayServer.class, ObfuscatedNames.NetHandlerPlayServer_floatingTickCount);
|
||||
}
|
||||
|
||||
if(world.provider.dimensionId != coords.dimensionId)
|
||||
{
|
||||
((EntityPlayerMP)player).travelToDimension(coords.dimensionId);
|
||||
}
|
||||
|
||||
((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(coords.xCoord+0.5, coords.yCoord+1, coords.zCoord+0.5, player.rotationYaw, player.rotationPitch);
|
||||
|
||||
world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
Mekanism.packetHandler.sendToReceivers(new PortalFXMessage(coords), new Range4D(coords));
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class PortableTeleportMessage implements IMessage
|
||||
{
|
||||
public PortableTeleportMessage() {}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,368 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.ObfuscatedNames;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.frequency.Frequency;
|
||||
import mekanism.common.frequency.FrequencyManager;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
|
||||
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
|
||||
import mekanism.common.tile.TileEntityTeleporter;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketPortableTeleporter implements IMessageHandler<PortableTeleporterMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PortableTeleporterMessage message, MessageContext context)
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
ItemStack itemstack = player.getCurrentEquippedItem();
|
||||
World world = player.worldObj;
|
||||
|
||||
if(itemstack != null && itemstack.getItem() instanceof ItemPortableTeleporter)
|
||||
{
|
||||
ItemPortableTeleporter item = (ItemPortableTeleporter)itemstack.getItem();
|
||||
|
||||
switch(message.packetType)
|
||||
{
|
||||
case DATA_REQUEST:
|
||||
sendDataResponse(message.frequency, world, player, item, itemstack);
|
||||
break;
|
||||
case DATA_RESPONSE:
|
||||
Mekanism.proxy.handleTeleporterUpdate(message);
|
||||
break;
|
||||
case SET_FREQ:
|
||||
FrequencyManager manager1 = getManager(message.frequency.isPublic() ? null : player.getCommandSenderName(), world);
|
||||
Frequency toUse = null;
|
||||
|
||||
for(Frequency freq : manager1.getFrequencies())
|
||||
{
|
||||
if(freq.name.equals(message.frequency.name))
|
||||
{
|
||||
toUse = freq;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(toUse == null)
|
||||
{
|
||||
toUse = new Frequency(message.frequency.name, player.getCommandSenderName()).setPublic(message.frequency.isPublic());
|
||||
manager1.addFrequency(toUse);
|
||||
}
|
||||
|
||||
sendDataResponse(toUse, world, player, item, itemstack);
|
||||
|
||||
break;
|
||||
case DEL_FREQ:
|
||||
FrequencyManager manager = getManager(message.frequency.isPublic() ? null : player.getCommandSenderName(), world);
|
||||
|
||||
for(Iterator<Frequency> iter = manager.getFrequencies().iterator(); iter.hasNext();)
|
||||
{
|
||||
Frequency iterFreq = iter.next();
|
||||
|
||||
if(iterFreq.name.equals(message.frequency.name) && iterFreq.owner.equals(player.getCommandSenderName()))
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case TELEPORT:
|
||||
Coord4D coords = null;//TODO MekanismUtils.getClosestCoords(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3)), player);
|
||||
|
||||
World teleWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(coords.dimensionId);
|
||||
TileEntityTeleporter teleporter = (TileEntityTeleporter)coords.getTileEntity(teleWorld);
|
||||
|
||||
if(teleporter != null)
|
||||
{
|
||||
try {
|
||||
teleporter.didTeleport.add(player);
|
||||
teleporter.teleDelay = 5;
|
||||
|
||||
item.setEnergy(itemstack, item.getEnergy(itemstack) - item.calculateEnergyCost(player, coords));
|
||||
|
||||
if(player instanceof EntityPlayerMP)
|
||||
{
|
||||
MekanismUtils.setPrivateValue(((EntityPlayerMP)player).playerNetServerHandler, 0, NetHandlerPlayServer.class, ObfuscatedNames.NetHandlerPlayServer_floatingTickCount);
|
||||
}
|
||||
|
||||
if(world.provider.dimensionId != coords.dimensionId)
|
||||
{
|
||||
((EntityPlayerMP)player).travelToDimension(coords.dimensionId);
|
||||
}
|
||||
|
||||
((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(coords.xCoord+0.5, coords.yCoord+1, coords.zCoord+0.5, player.rotationYaw, player.rotationPitch);
|
||||
|
||||
world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
Mekanism.packetHandler.sendToReceivers(new PortalFXMessage(coords), new Range4D(coords));
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendDataResponse(Frequency given, World world, EntityPlayer player, ItemPortableTeleporter item, ItemStack itemstack)
|
||||
{
|
||||
List<Frequency> publicFreqs = new ArrayList<Frequency>();
|
||||
|
||||
for(Frequency f : getManager(null, world).getFrequencies())
|
||||
{
|
||||
publicFreqs.add(f);
|
||||
}
|
||||
|
||||
List<Frequency> privateFreqs = new ArrayList<Frequency>();
|
||||
|
||||
for(Frequency f : getManager(player.getCommandSenderName(), world).getFrequencies())
|
||||
{
|
||||
privateFreqs.add(f);
|
||||
}
|
||||
|
||||
byte status = 3;
|
||||
|
||||
if(given != null)
|
||||
{
|
||||
FrequencyManager manager = given.isPublic() ? getManager(null, world) : getManager(player.getCommandSenderName(), world);
|
||||
boolean found = false;
|
||||
|
||||
for(Frequency iterFreq : manager.getFrequencies())
|
||||
{
|
||||
if(given.equals(iterFreq))
|
||||
{
|
||||
given = iterFreq;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
given = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(given != null)
|
||||
{
|
||||
if(given.activeCoords.size() == 0)
|
||||
{
|
||||
status = 3;
|
||||
}
|
||||
else {
|
||||
Coord4D coords = given.getClosestCoords(new Coord4D(player));
|
||||
double energyNeeded = item.calculateEnergyCost(player, coords);
|
||||
|
||||
if(energyNeeded > item.getEnergy(itemstack))
|
||||
{
|
||||
status = 4;
|
||||
}
|
||||
else {
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendTo(new PortableTeleporterMessage(given, status, publicFreqs, privateFreqs), (EntityPlayerMP)player);
|
||||
}
|
||||
|
||||
public FrequencyManager getManager(String owner, World world)
|
||||
{
|
||||
if(owner == null)
|
||||
{
|
||||
return Mekanism.publicTeleporters;
|
||||
}
|
||||
else {
|
||||
if(!Mekanism.privateTeleporters.containsKey(owner))
|
||||
{
|
||||
FrequencyManager manager = new FrequencyManager(Frequency.class, owner);
|
||||
Mekanism.privateTeleporters.put(owner, manager);
|
||||
manager.createOrLoad(world);
|
||||
}
|
||||
|
||||
return Mekanism.privateTeleporters.get(owner);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PortableTeleporterMessage implements IMessage
|
||||
{
|
||||
public PortableTeleporterPacketType packetType;
|
||||
public Frequency frequency;
|
||||
public byte status;
|
||||
|
||||
public List<Frequency> publicCache = new ArrayList<Frequency>();
|
||||
public List<Frequency> privateCache = new ArrayList<Frequency>();
|
||||
|
||||
public PortableTeleporterMessage() {}
|
||||
|
||||
public PortableTeleporterMessage(PortableTeleporterPacketType type, Frequency freq)
|
||||
{
|
||||
packetType = type;
|
||||
|
||||
if(type == PortableTeleporterPacketType.DATA_REQUEST)
|
||||
{
|
||||
frequency = freq;
|
||||
}
|
||||
else if(type == PortableTeleporterPacketType.SET_FREQ)
|
||||
{
|
||||
frequency = freq;
|
||||
}
|
||||
else if(type == PortableTeleporterPacketType.DEL_FREQ)
|
||||
{
|
||||
frequency = freq;
|
||||
}
|
||||
else if(type == PortableTeleporterPacketType.TELEPORT)
|
||||
{
|
||||
frequency = freq;
|
||||
}
|
||||
}
|
||||
|
||||
public PortableTeleporterMessage(Frequency freq, byte b, List<Frequency> publicFreqs, List<Frequency> privateFreqs)
|
||||
{
|
||||
packetType = PortableTeleporterPacketType.DATA_RESPONSE;
|
||||
|
||||
frequency = freq;
|
||||
status = b;
|
||||
|
||||
publicCache = publicFreqs;
|
||||
privateCache = privateFreqs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer)
|
||||
{
|
||||
buffer.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == PortableTeleporterPacketType.DATA_REQUEST)
|
||||
{
|
||||
if(frequency != null)
|
||||
{
|
||||
buffer.writeBoolean(true);
|
||||
PacketHandler.writeString(buffer, frequency.name);
|
||||
buffer.writeBoolean(frequency.publicFreq);
|
||||
}
|
||||
else {
|
||||
buffer.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.DATA_RESPONSE)
|
||||
{
|
||||
if(frequency != null)
|
||||
{
|
||||
buffer.writeBoolean(true);
|
||||
PacketHandler.writeString(buffer, frequency.name);
|
||||
buffer.writeBoolean(frequency.publicFreq);
|
||||
}
|
||||
else {
|
||||
buffer.writeBoolean(false);
|
||||
}
|
||||
|
||||
buffer.writeByte(status);
|
||||
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(publicCache.size());
|
||||
|
||||
for(Frequency freq : publicCache)
|
||||
{
|
||||
freq.write(data);
|
||||
}
|
||||
|
||||
data.add(privateCache.size());
|
||||
|
||||
for(Frequency freq : privateCache)
|
||||
{
|
||||
freq.write(data);
|
||||
}
|
||||
|
||||
PacketHandler.encode(data.toArray(), buffer);
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.SET_FREQ)
|
||||
{
|
||||
PacketHandler.writeString(buffer, frequency.name);
|
||||
buffer.writeBoolean(frequency.publicFreq);
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.DEL_FREQ)
|
||||
{
|
||||
PacketHandler.writeString(buffer, frequency.name);
|
||||
buffer.writeBoolean(frequency.publicFreq);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer)
|
||||
{
|
||||
packetType = PortableTeleporterPacketType.values()[buffer.readInt()];
|
||||
|
||||
if(packetType == PortableTeleporterPacketType.DATA_REQUEST)
|
||||
{
|
||||
if(buffer.readBoolean())
|
||||
{
|
||||
frequency = new Frequency(PacketHandler.readString(buffer), null).setPublic(buffer.readBoolean());
|
||||
}
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.DATA_RESPONSE)
|
||||
{
|
||||
if(buffer.readBoolean())
|
||||
{
|
||||
frequency = new Frequency(PacketHandler.readString(buffer), null).setPublic(buffer.readBoolean());
|
||||
}
|
||||
|
||||
status = buffer.readByte();
|
||||
|
||||
int amount = buffer.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
publicCache.add(new Frequency(buffer));
|
||||
}
|
||||
|
||||
amount = buffer.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
privateCache.add(new Frequency(buffer));
|
||||
}
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.SET_FREQ)
|
||||
{
|
||||
frequency = new Frequency(PacketHandler.readString(buffer), null).setPublic(buffer.readBoolean());
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.DEL_FREQ)
|
||||
{
|
||||
frequency = new Frequency(PacketHandler.readString(buffer), null).setPublic(buffer.readBoolean());
|
||||
}
|
||||
else if(packetType == PortableTeleporterPacketType.TELEPORT)
|
||||
{
|
||||
frequency = new Frequency(PacketHandler.readString(buffer), null).setPublic(buffer.readBoolean());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PortableTeleporterPacketType
|
||||
{
|
||||
DATA_REQUEST,
|
||||
DATA_RESPONSE,
|
||||
SET_FREQ,
|
||||
DEL_FREQ,
|
||||
TELEPORT;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.item.ItemPortableTeleporter;
|
||||
import mekanism.common.network.PacketStatusUpdate.StatusUpdateMessage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PacketStatusUpdate implements IMessageHandler<StatusUpdateMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(StatusUpdateMessage message, MessageContext context)
|
||||
{
|
||||
ItemStack currentStack = PacketHandler.getPlayer(context).getCurrentEquippedItem();
|
||||
|
||||
if(currentStack != null && currentStack.getItem() instanceof ItemPortableTeleporter)
|
||||
{
|
||||
ItemPortableTeleporter item = (ItemPortableTeleporter)currentStack.getItem();
|
||||
item.setStatus(currentStack, message.status);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class StatusUpdateMessage implements IMessage
|
||||
{
|
||||
public int status;
|
||||
|
||||
public StatusUpdateMessage() {}
|
||||
|
||||
public StatusUpdateMessage(int state)
|
||||
{
|
||||
status = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf dataStream)
|
||||
{
|
||||
status = dataStream.readInt();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue