diff --git a/src/main/java/crazypants/enderio/api/teleport/ITravelAccessable.java b/src/main/java/crazypants/enderio/api/teleport/ITravelAccessable.java index 1e53d207..c0100473 100644 --- a/src/main/java/crazypants/enderio/api/teleport/ITravelAccessable.java +++ b/src/main/java/crazypants/enderio/api/teleport/ITravelAccessable.java @@ -1,5 +1,7 @@ package crazypants.enderio.api.teleport; +import java.util.UUID; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import crazypants.util.BlockCoord; @@ -38,7 +40,7 @@ public interface ITravelAccessable { void setLabel(String label); - String getPlacedBy(); + UUID getPlacedBy(); void setPlacedBy(EntityPlayer player); diff --git a/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java b/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java index 50e59c50..4e5623c5 100644 --- a/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java +++ b/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java @@ -53,6 +53,7 @@ import crazypants.enderio.conduit.packet.PacketItemConduitFilter; import crazypants.enderio.conduit.packet.PacketRedstoneConduitOutputStrength; import crazypants.enderio.conduit.packet.PacketRedstoneConduitSignalColor; import crazypants.enderio.conduit.redstone.IRedstoneConduit; +import crazypants.enderio.item.IRotatableFacade; import crazypants.enderio.item.ItemConduitProbe; import crazypants.enderio.machine.painter.PainterUtil; import crazypants.enderio.network.PacketHandler; @@ -62,7 +63,7 @@ import crazypants.util.IFacade; import crazypants.util.Util; @Optional.Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.IRedNetOmniNode", modid = "MineFactoryReloaded") -public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade, IRedNetOmniNode { +public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade, IRotatableFacade, IRedNetOmniNode { private static final String KEY_CONNECTOR_ICON = "enderIO:conduitConnector"; private static final String KEY_CONNECTOR_ICON_EXTERNAL = "enderIO:conduitConnectorExternal"; @@ -96,7 +97,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade private IIcon lastRemovedComponetIcon = null; - private Random rand = new Random(); + private final Random rand = new Random(); protected BlockConduitBundle() { super(ModObject.blockConduitBundle.unlocalisedName, TileConduitBundle.class); @@ -255,10 +256,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade return false; } IConduitBundle con = (IConduitBundle) te; - if(con.getFacadeId() != null) { - return true; - } - return false; + return con.hasFacade(); } @Override @@ -475,9 +473,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade return; } IConduitBundle te = (IConduitBundle) tile; - if(te != null) { - te.onBlockRemoved(); - } + te.onBlockRemoved(); world.removeTileEntity(x, y, z); } @@ -492,7 +488,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade @Override public boolean onBlockActivated(World world, int x, int y, int z, - EntityPlayer player, int par6, float par7, float par8, float par9) { + EntityPlayer player, int side, float par7, float par8, float par9) { IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z); if(bundle == null) { @@ -502,7 +498,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade ItemStack stack = player.getCurrentEquippedItem(); if(stack != null && stack.getItem() == EnderIO.itemConduitFacade && !bundle.hasFacade()) { //add facade - return handleFacadeClick(world, x, y, z, player, bundle, stack); + return handleFacadeClick(world, x, y, z, player, side, bundle, stack); } else if(ConduitUtil.isConduitEquipped(player)) { // Add conduit @@ -619,29 +615,35 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade private boolean handleConduitClick(World world, int x, int y, int z, EntityPlayer player, IConduitBundle bundle, ItemStack stack) { IConduitItem equipped = (IConduitItem) stack.getItem(); if(!bundle.hasType(equipped.getBaseConduitType())) { - bundle.addConduit(equipped.createConduit(stack, player)); - if(!player.capabilities.isCreativeMode) { - world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, stepSound.getStepResourcePath(), - (stepSound.getVolume() + 1.0F) / 2.0F, stepSound.getPitch() * 0.8F); - player.getCurrentEquippedItem().stackSize--; + if(!world.isRemote) { + bundle.addConduit(equipped.createConduit(stack, player)); + if(!player.capabilities.isCreativeMode) { + world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, stepSound.getStepResourcePath(), + (stepSound.getVolume() + 1.0F) / 2.0F, stepSound.getPitch() * 0.8F); + player.getCurrentEquippedItem().stackSize--; + } } return true; } return false; } - private boolean handleFacadeClick(World world, int x, int y, int z, EntityPlayer player, IConduitBundle bundle, ItemStack stack) { + private boolean handleFacadeClick(World world, int x, int y, int z, EntityPlayer player, int side, IConduitBundle bundle, ItemStack stack) { // Add facade if(player.isSneaking()) { return false; } - if(PainterUtil.getSourceBlock(player.getCurrentEquippedItem()) == null) { + Block facadeID = PainterUtil.getSourceBlock(player.getCurrentEquippedItem()); + if(facadeID == null) { return false; } - bundle.setFacadeId(PainterUtil.getSourceBlock(player.getCurrentEquippedItem())); - bundle.setFacadeMetadata(PainterUtil.getSourceBlockMetadata(player.getCurrentEquippedItem())); + int facadeMeta = PainterUtil.getSourceBlockMetadata(player.getCurrentEquippedItem()); + facadeMeta = PainterUtil.adjustFacadeMetadata(facadeID, facadeMeta, side); + + bundle.setFacadeId(facadeID); + bundle.setFacadeMetadata(facadeMeta); bundle.setFacadeType(FacadeType.values()[player.getCurrentEquippedItem().getItemDamage()]); if(!player.capabilities.isCreativeMode) { stack.stackSize--; @@ -651,6 +653,25 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade return true; } + @Override + public boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis) { + IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z); + if(bundle == null) { + return false; + } + + int oldMeta = bundle.getFacadeMetadata(); + int newMeta = PainterUtil.rotateFacadeMetadata(bundle.getFacadeId(), oldMeta, axis); + if(newMeta == oldMeta) { + return false; + } + + bundle.setFacadeMetadata(newMeta); + world.markBlockForUpdate(x, y, z); + bundle.getEntity().markDirty(); + return true; + } + @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { if(id == GuiHandler.GUI_ID_EXTERNAL_CONNECTION_SELECTOR) { diff --git a/src/main/java/crazypants/enderio/conduit/ConduitDisplayMode.java b/src/main/java/crazypants/enderio/conduit/ConduitDisplayMode.java index bad968c0..107f8117 100644 --- a/src/main/java/crazypants/enderio/conduit/ConduitDisplayMode.java +++ b/src/main/java/crazypants/enderio/conduit/ConduitDisplayMode.java @@ -14,7 +14,8 @@ public enum ConduitDisplayMode { FLUID, ITEM, GAS, - ME; + ME, + NONE; public static ConduitDisplayMode next(ConduitDisplayMode mode) { int index = mode.ordinal() + 1; diff --git a/src/main/java/crazypants/enderio/conduit/facade/ItemConduitFacade.java b/src/main/java/crazypants/enderio/conduit/facade/ItemConduitFacade.java index cc5d5bfa..0d0b51b7 100644 --- a/src/main/java/crazypants/enderio/conduit/facade/ItemConduitFacade.java +++ b/src/main/java/crazypants/enderio/conduit/facade/ItemConduitFacade.java @@ -119,8 +119,11 @@ public class ItemConduitFacade extends Item implements IAdvancedTooltipProvider, world.setBlock(placeX, placeY, placeZ, EnderIO.blockConduitBundle); IConduitBundle bundle = (IConduitBundle) world.getTileEntity(placeX, placeY, placeZ); - bundle.setFacadeId(PainterUtil.getSourceBlock(itemStack)); - bundle.setFacadeMetadata(PainterUtil.getSourceBlockMetadata(itemStack)); + Block facadeID = PainterUtil.getSourceBlock(itemStack); + int facadeMeta = PainterUtil.getSourceBlockMetadata(itemStack); + facadeMeta = PainterUtil.adjustFacadeMetadata(facadeID, facadeMeta, side); + bundle.setFacadeId(facadeID); + bundle.setFacadeMetadata(facadeMeta); bundle.setFacadeType(FacadeType.values()[itemStack.getItemDamage()]); if(!player.capabilities.isCreativeMode) { itemStack.stackSize--; diff --git a/src/main/java/crazypants/enderio/item/ConduitProbeOverlayRenderer.java b/src/main/java/crazypants/enderio/item/ConduitProbeOverlayRenderer.java index 08cc5a32..952a0e05 100644 --- a/src/main/java/crazypants/enderio/item/ConduitProbeOverlayRenderer.java +++ b/src/main/java/crazypants/enderio/item/ConduitProbeOverlayRenderer.java @@ -11,8 +11,6 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import crazypants.enderio.EnderIO; -import crazypants.enderio.conduit.ConduitDisplayMode; -import crazypants.enderio.conduit.gas.GasUtil; import crazypants.enderio.gui.IconEIO; public class ConduitProbeOverlayRenderer { diff --git a/src/main/java/crazypants/enderio/item/IRotatableFacade.java b/src/main/java/crazypants/enderio/item/IRotatableFacade.java new file mode 100644 index 00000000..8d32d708 --- /dev/null +++ b/src/main/java/crazypants/enderio/item/IRotatableFacade.java @@ -0,0 +1,8 @@ +package crazypants.enderio.item; + +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRotatableFacade { + boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis); +} diff --git a/src/main/java/crazypants/enderio/item/ItemYetaWrench.java b/src/main/java/crazypants/enderio/item/ItemYetaWrench.java index 918890ff..73ee1139 100644 --- a/src/main/java/crazypants/enderio/item/ItemYetaWrench.java +++ b/src/main/java/crazypants/enderio/item/ItemYetaWrench.java @@ -23,6 +23,7 @@ import crazypants.enderio.EnderIOTab; import crazypants.enderio.ModObject; import crazypants.enderio.api.tool.IConduitControl; import crazypants.enderio.api.tool.ITool; +import crazypants.enderio.conduit.BlockConduitBundle; import crazypants.enderio.conduit.ConduitDisplayMode; import crazypants.enderio.config.Config; import crazypants.enderio.gui.IAdvancedTooltipProvider; @@ -62,10 +63,20 @@ public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdv @Override public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) { + return false; + } Block block = world.getBlock(x, y, z); + if(block instanceof IRotatableFacade && !player.isSneaking() && + (block != EnderIO.blockConduitBundle || ConduitDisplayMode.getDisplayMode(stack) == ConduitDisplayMode.NONE)) { + if(((IRotatableFacade)block).tryRotateFacade(world, x, y, z, ForgeDirection.getOrientation(side))) { + player.swingItem(); + return true; + } + } if(block != null && !player.isSneaking() && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) { player.swingItem(); - return !world.isRemote; + return true; } return false; } @@ -114,7 +125,8 @@ public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdv @Override public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) { - return true; + ConduitDisplayMode curMode = ConduitDisplayMode.getDisplayMode(stack); + return curMode != ConduitDisplayMode.NONE; } @Override diff --git a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java index 2c5b76f7..eea556ba 100644 --- a/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java +++ b/src/main/java/crazypants/enderio/item/darksteel/DarkSteelController.java @@ -53,9 +53,9 @@ public class DarkSteelController { private int jumpCount; private int ticksSinceLastJump; - private final Map glideActiveMap = new HashMap(); - private final Map speedActiveMap = new HashMap(); - private final Map stepAssistActiveMap = new HashMap(); + private final Map glideActiveMap = new HashMap(); + private final Map speedActiveMap = new HashMap(); + private final Map stepAssistActiveMap = new HashMap(); private boolean nightVisionActive = false; private boolean removeNightvision = false; @@ -66,13 +66,13 @@ public class DarkSteelController { } public void setGlideActive(EntityPlayer player, boolean isGlideActive) { - if(player.getGameProfile().getName() != null) { - glideActiveMap.put(player.getGameProfile().getName(), isGlideActive); + if(player.getGameProfile().getId() != null) { + glideActiveMap.put(player.getGameProfile().getId(), isGlideActive); } } public boolean isGlideActive(EntityPlayer player) { - Boolean isActive = glideActiveMap.get(player.getGameProfile().getName()); + Boolean isActive = glideActiveMap.get(player.getGameProfile().getId()); if(isActive == null) { return false; } @@ -80,13 +80,13 @@ public class DarkSteelController { } public void setSpeedActive(EntityPlayer player, boolean isSpeedActive) { - if(player.getGameProfile().getName() != null) { - speedActiveMap.put(player.getGameProfile().getName(), isSpeedActive); + if(player.getGameProfile().getId() != null) { + speedActiveMap.put(player.getGameProfile().getId(), isSpeedActive); } } public boolean isSpeedActive(EntityPlayer player) { - Boolean isActive = speedActiveMap.get(player.getGameProfile().getName()); + Boolean isActive = speedActiveMap.get(player.getGameProfile().getId()); if(isActive == null) { return true; } @@ -94,13 +94,13 @@ public class DarkSteelController { } public void setStepAssistActive(EntityPlayer player, boolean isActive) { - if(player.getGameProfile().getName() != null) { - stepAssistActiveMap.put(player.getGameProfile().getName(), isActive); + if(player.getGameProfile().getId() != null) { + stepAssistActiveMap.put(player.getGameProfile().getId(), isActive); } } public boolean isStepAssistActive(EntityPlayer player) { - Boolean isActive = stepAssistActiveMap.get(player.getGameProfile().getName()); + Boolean isActive = stepAssistActiveMap.get(player.getGameProfile().getId()); if(isActive == null) { return true; } diff --git a/src/main/java/crazypants/enderio/machine/attractor/ObeliskRenderer.java b/src/main/java/crazypants/enderio/machine/attractor/ObeliskRenderer.java index ae7e3fb7..64f61aef 100644 --- a/src/main/java/crazypants/enderio/machine/attractor/ObeliskRenderer.java +++ b/src/main/java/crazypants/enderio/machine/attractor/ObeliskRenderer.java @@ -13,6 +13,7 @@ import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; @@ -91,7 +92,6 @@ public class ObeliskRenderer extends TileEntitySpecialRend Timer t = RenderUtil.getTimer(); renderItemStack(null, Minecraft.getMinecraft().theWorld, 0, 0, 0, t.renderPartialTicks); GL11.glPopMatrix(); - GL11.glEnable(GL11.GL_LIGHTING); } private EntityItem ei = null; @@ -152,7 +152,6 @@ public class ObeliskRenderer extends TileEntitySpecialRend renderWorldBlock(null, 0, 0, 0, block, 0, renderer); Tessellator.instance.draw(); GL11.glEnable(GL11.GL_LIGHTING); - } @Override diff --git a/src/main/java/crazypants/enderio/machine/hypercube/BlockHyperCube.java b/src/main/java/crazypants/enderio/machine/hypercube/BlockHyperCube.java index c9daeda3..ead17b7d 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/BlockHyperCube.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/BlockHyperCube.java @@ -3,7 +3,9 @@ package crazypants.enderio.machine.hypercube; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Random; +import java.util.UUID; +import crazypants.util.PlayerUtil; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; @@ -196,9 +198,9 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo return null; } - String user = null; + UUID user = null; if(!tag.getBoolean("channelIsPublic")) { - user = tag.getString("channelUser"); + user = PlayerUtil.getPlayerUIDUnstable(tag.getString("channelUser")); } return new Channel(channelName, user); @@ -241,7 +243,7 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo TileHyperCube cb = (TileHyperCube) te; cb.setEnergyStored(PowerHandlerUtil.getStoredEnergyForItem(stack)); if(player instanceof EntityPlayerMP) { - cb.setOwner(((EntityPlayerMP) player).getGameProfile().getName()); + cb.setOwner(PlayerUtil.getPlayerUUID(((EntityPlayerMP) player).getGameProfile().getName())); } cb.setChannel(getChannelFromItem(stack)); setIoOnTransciever(cb, stack); diff --git a/src/main/java/crazypants/enderio/machine/hypercube/Channel.java b/src/main/java/crazypants/enderio/machine/hypercube/Channel.java index b329c0e5..79050866 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/Channel.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/Channel.java @@ -5,9 +5,9 @@ import java.util.UUID; public class Channel { final String name; - final String user; + final UUID user; - Channel(String name, String uuid) { + Channel(String name, UUID uuid) { this.name = trim(name); this.user = uuid; } diff --git a/src/main/java/crazypants/enderio/machine/hypercube/GuiHyperCube.java b/src/main/java/crazypants/enderio/machine/hypercube/GuiHyperCube.java index 9630276d..8fda0fbb 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/GuiHyperCube.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/GuiHyperCube.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.Rectangle; import java.util.List; +import crazypants.util.PlayerUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; @@ -274,7 +275,7 @@ public class GuiHyperCube extends GuiContainerBase { Channel c; if(privateButton.isSelected()) { - c = new Channel(newChannelTF.getText(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName()); + c = new Channel(newChannelTF.getText(), PlayerUtil.getPlayerUUID(Minecraft.getMinecraft().thePlayer.getGameProfile().getName())); } else { c = new Channel(newChannelTF.getText(), null); } diff --git a/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeConfig.java b/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeConfig.java index 9eac603a..3336da87 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeConfig.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeConfig.java @@ -14,6 +14,7 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.UUID; +import crazypants.util.PlayerUtil; import org.apache.commons.io.IOUtils; import crazypants.enderio.Log; @@ -33,7 +34,7 @@ public class HyperCubeConfig { private final List publicChannels = new ArrayList(); - private final Map> userChannels = new HashMap>(); + private final Map> userChannels = new HashMap>(); private final File file; @@ -53,11 +54,11 @@ public class HyperCubeConfig { publicChannels.addAll(chans); } - public Map> getUserChannels() { + public Map> getUserChannels() { return userChannels; } - public void setUserChannels(Map> channels) { + public void setUserChannels(Map> channels) { userChannels.clear(); userChannels.putAll(channels); } @@ -68,10 +69,10 @@ public class HyperCubeConfig { setChannelListProperty(KEY_PUBLIC_CHANNELS, publicChannels); StringBuilder userListStr = new StringBuilder(); - Iterator>> itr = userChannels.entrySet().iterator(); + Iterator>> itr = userChannels.entrySet().iterator(); while (itr.hasNext()) { - Entry> entry = itr.next(); - String user = entry.getKey(); + Entry> entry = itr.next(); + UUID user = entry.getKey(); List channels = entry.getValue(); if(user != null && channels != null && !channels.isEmpty()) { @@ -142,17 +143,19 @@ public class HyperCubeConfig { users.add(user); } } + for (String user : users) { List channels = new ArrayList(); - loadChannelList(user + KEY_USER_CHANNEL, user, channels); + UUID uuid=PlayerUtil.getPlayerUIDUnstable(user); + loadChannelList(user + KEY_USER_CHANNEL, uuid, channels); if(!channels.isEmpty()) { - userChannels.put(user, channels); + userChannels.put(uuid, channels); } } } - private void loadChannelList(String key, String user, List channels) { + private void loadChannelList(String key, UUID user, List channels) { String chans = props.getProperty(key, ""); //chans = chans.replaceAll(DELIM_ESC, DELIM); String[] chanSplit = chans.split(DELIM); diff --git a/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeRegister.java b/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeRegister.java index 46a8c3cc..969c9fca 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeRegister.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/HyperCubeRegister.java @@ -24,7 +24,7 @@ public class HyperCubeRegister { private final List publicChannels = new ArrayList(); private final List publicChannelsRO = Collections.unmodifiableList(publicChannels); - private final Map> userChannels = new HashMap>(); + private final Map> userChannels = new HashMap>(); //private Configuration config; private HyperCubeConfig conf; @@ -45,7 +45,7 @@ public class HyperCubeRegister { userChannels.putAll(conf.getUserChannels()); } - public synchronized List getChannelsForUser(String user) { + public synchronized List getChannelsForUser(UUID user) { List result = userChannels.get(user); if(result == null) { result = new ArrayList(); diff --git a/src/main/java/crazypants/enderio/machine/hypercube/PacketAddRemoveChannel.java b/src/main/java/crazypants/enderio/machine/hypercube/PacketAddRemoveChannel.java index d36f13a5..ab1ded63 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/PacketAddRemoveChannel.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/PacketAddRemoveChannel.java @@ -2,6 +2,7 @@ package crazypants.enderio.machine.hypercube; import java.util.UUID; +import crazypants.util.PlayerUtil; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.ByteBufUtils; @@ -44,7 +45,7 @@ public class PacketAddRemoveChannel implements IMessage, IMessageHandler channels; - private String userId; + private UUID userId; public PacketChannelList() { } public PacketChannelList(EntityPlayer player, boolean isPrivate) { - this(player.getGameProfile().getName(), isPrivate); + this(PlayerUtil.getPlayerUUID(player.getGameProfile().getName()), isPrivate); } - public PacketChannelList(String uuid, boolean isPrivate) { + public PacketChannelList(UUID uuid, boolean isPrivate) { this.userId = uuid; this.isPrivate = isPrivate; if(isPrivate && uuid == null) { @@ -50,7 +51,8 @@ public class PacketChannelList implements IMessage, IMessageHandler 0) { if(user != null && user.trim().length() > 0) { - selectedChannel = new Channel(name, user); + selectedChannel = new Channel(name, PlayerUtil.getPlayerUIDUnstable(user)); } else { selectedChannel = new Channel(name, null); } diff --git a/src/main/java/crazypants/enderio/machine/hypercube/TileHyperCube.java b/src/main/java/crazypants/enderio/machine/hypercube/TileHyperCube.java index e14dc8c1..4909a923 100644 --- a/src/main/java/crazypants/enderio/machine/hypercube/TileHyperCube.java +++ b/src/main/java/crazypants/enderio/machine/hypercube/TileHyperCube.java @@ -1,18 +1,18 @@ package crazypants.enderio.machine.hypercube; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.ListIterator; +import java.util.*; +import com.mojang.authlib.GameProfile; +import crazypants.util.PlayerUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; +import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -114,7 +114,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle private Channel channel = null; private Channel registeredChannel = null; - private String owner; + private UUID owner; private boolean init = true; @@ -183,7 +183,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle HyperCubeRegister.instance.register(this); } - public void setOwner(String owner) { + public void setOwner(UUID owner) { this.owner = owner; } @@ -252,7 +252,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle return; } // else is server, do all logic only on the server - + // Pay upkeep cost storedEnergyRF -= ENERGY_UPKEEP; @@ -260,7 +260,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle storedEnergyRF -= (MILLIBUCKET_TRANSMISSION_COST * milliBucketsTransfered); // update power status - storedEnergyRF = Math.max(storedEnergyRF, 0); + storedEnergyRF = Math.max(storedEnergyRF, 0); milliBucketsTransfered = 0; @@ -293,7 +293,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle boolean stillConnected = canMaintainConnection(); if(isConnected != stillConnected) { fluidHandlersDirty = true; - isConnected = stillConnected; + isConnected = stillConnected; requiresClientSync = true; } updateFluidHandlers(); @@ -307,10 +307,10 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle } requiresClientSync |= prevRedCheck != redstoneCheckPassed; - + boolean powerChanged = lastSyncPowerStored != storedEnergyRF && worldObj.getTotalWorldTime() % 21 == 0; if(powerChanged) { - lastSyncPowerStored = storedEnergyRF; + lastSyncPowerStored = storedEnergyRF; EnderIO.packetPipeline.sendToAllAround(new PacketStoredPower(this), this); } @@ -423,9 +423,9 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle } @Override - public int getMaxEnergyRecieved(ForgeDirection dir) { + public int getMaxEnergyRecieved(ForgeDirection dir) { if(getModeForChannel(SubChannel.POWER) == IoMode.RECIEVE) { - return 0; + return 0; } return internalCapacitor.getMaxEnergyReceived(); } @@ -442,7 +442,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle @Override public void setEnergyStored(int stored) { - storedEnergyRF = MathHelper.clamp_int(stored, 0, getMaxEnergyStored()); + storedEnergyRF = MathHelper.clamp_int(stored, 0, getMaxEnergyStored()); } @Override @@ -813,25 +813,25 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle @Override public void readCustomNBT(NBTTagCompound nbtRoot) { - - int energy; + + int energy; if(nbtRoot.hasKey("storedEnergy")) { energy = (int)(nbtRoot.getFloat("storedEnergy") * 10); } else { energy = nbtRoot.getInteger("storedEnergyRF"); } setEnergyStored(energy); - - + + String channelName = nbtRoot.getString("channelName"); - String channelUser = nbtRoot.getString("channelUser"); + UUID channelUser = PlayerUtil.getPlayerUIDUnstable(nbtRoot.getString("channelUser")); if(channelName != null && !channelName.isEmpty()) { - channel = new Channel(channelName, channelUser == null || channelUser.isEmpty() ? null : channelUser); + channel = new Channel(channelName,channelUser); } else { channel = null; } - owner = nbtRoot.getString("owner"); + owner = PlayerUtil.getPlayerUIDUnstable(nbtRoot.getString("owner")); for (SubChannel subChannel : SubChannel.values()) { String key = "subChannel" + subChannel.ordinal(); diff --git a/src/main/java/crazypants/enderio/machine/painter/BlockItemPaintedGlowstone.java b/src/main/java/crazypants/enderio/machine/painter/BlockItemPaintedGlowstone.java index 449ec3a6..c8defe5e 100644 --- a/src/main/java/crazypants/enderio/machine/painter/BlockItemPaintedGlowstone.java +++ b/src/main/java/crazypants/enderio/machine/painter/BlockItemPaintedGlowstone.java @@ -9,6 +9,8 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.EnderIO; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; public class BlockItemPaintedGlowstone extends ItemBlock { @@ -27,6 +29,24 @@ public class BlockItemPaintedGlowstone extends ItemBlock { return par1; } + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { + if(!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) { + return false; + } + Block b = PainterUtil.getSourceBlock(stack); + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileEntityPaintedBlock) { + TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te; + int meta = PainterUtil.getSourceBlockMetadata(stack); + meta = PainterUtil.adjustFacadeMetadata(b, meta, side); + tef.setSourceBlock(b); + tef.setSourceBlockMetadata(meta); + world.markBlockForUpdate(x, y, z); + } + return true; + } + @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack item, EntityPlayer par2EntityPlayer, List list, boolean par4) { diff --git a/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstone.java b/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstone.java index dbcff41d..f847b3fb 100644 --- a/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstone.java +++ b/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstone.java @@ -10,7 +10,6 @@ import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityDiggingFX; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -31,12 +30,13 @@ import crazypants.enderio.BlockEio; import crazypants.enderio.EnderIO; import crazypants.enderio.ModObject; import crazypants.enderio.TileEntityEio; +import crazypants.enderio.item.IRotatableFacade; import crazypants.enderio.machine.MachineRecipeInput; import crazypants.enderio.machine.MachineRecipeRegistry; import crazypants.util.IFacade; import crazypants.util.Lang; -public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvider, IPaintedBlock, IFacade { +public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvider, IPaintedBlock, IFacade, IRotatableFacade { public static int renderId = -1; @@ -48,7 +48,7 @@ public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvid private IIcon lastRemovedComponetIcon = null; - private Random rand = new Random(); + private final Random rand = new Random(); protected BlockPaintedGlowstone() { super(ModObject.blockPaintedGlowstone.unlocalisedName, TileEntityPaintedBlock.class, Material.glass); @@ -196,16 +196,20 @@ public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvid } @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { - Block b = PainterUtil.getSourceBlock(stack); + public boolean tryRotateFacade(World world, int x, int y, int z, ForgeDirection axis) { TileEntity te = world.getTileEntity(x, y, z); if(te instanceof TileEntityPaintedBlock) { TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te; - tef.setSourceBlock(b); - tef.setSourceBlockMetadata(PainterUtil.getSourceBlockMetadata(stack)); + int oldMeta = tef.getSourceBlockMetadata(); + int newMeta = PainterUtil.rotateFacadeMetadata(tef.getSourceBlock(), oldMeta, axis); + if(oldMeta != newMeta) { + tef.setSourceBlockMetadata(newMeta); + world.markBlockForUpdate(x, y, z); + tef.markDirty(); + return true; + } } - world.markBlockForUpdate(x, y, z); - super.onBlockPlacedBy(world, x, y, z, player, stack); + return false; } @Override diff --git a/src/main/java/crazypants/enderio/machine/painter/PainterUtil.java b/src/main/java/crazypants/enderio/machine/painter/PainterUtil.java index d3fdbf6d..479bae34 100644 --- a/src/main/java/crazypants/enderio/machine/painter/PainterUtil.java +++ b/src/main/java/crazypants/enderio/machine/painter/PainterUtil.java @@ -3,12 +3,13 @@ package crazypants.enderio.machine.painter; import com.google.common.base.Strings; import net.minecraft.block.Block; +import net.minecraft.block.BlockRotatedPillar; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import cpw.mods.fml.common.registry.GameData; import crazypants.util.Lang; +import net.minecraftforge.common.util.ForgeDirection; public final class PainterUtil { @@ -56,10 +57,8 @@ public final class PainterUtil { Block sourceId = PainterUtil.getSourceBlock(item); int meta = PainterUtil.getSourceBlockMetadata(item); if(sourceId != null) { - if(sourceId != null) { - ItemStack is = new ItemStack(Item.getItemFromBlock(sourceId), 1, meta); - sourceName = is.getDisplayName(); - } + ItemStack is = new ItemStack(Item.getItemFromBlock(sourceId), 1, meta); + sourceName = is.getDisplayName(); } return Lang.localize("blockPainter.paintedWith") + " " + sourceName; } @@ -79,6 +78,7 @@ public final class PainterUtil { } String name = Block.blockRegistry.getNameForObject(source); if(name != null && !name.trim().isEmpty()) { + meta = normalizeFacadeMetadata(source, meta); tag.setString(BlockPainter.KEY_SOURCE_BLOCK_ID, name); tag.setInteger(BlockPainter.KEY_SOURCE_BLOCK_META, meta); } @@ -88,4 +88,52 @@ public final class PainterUtil { setSourceBlock(stack, Blocks.stone, 0); return stack; } + + public static int normalizeFacadeMetadata(Block facadeID, int facadeMeta) { + if(facadeID instanceof BlockRotatedPillar) { + return facadeMeta & 3; + } + return facadeMeta; + } + + public static int adjustFacadeMetadata(Block facadeID, int facadeMeta, int side) { + if(facadeID instanceof BlockRotatedPillar) { + int dir = facadeMeta & 0xC; + switch (side) { + case 0: + case 1: dir = 0; break; + case 4: + case 5: dir = 4; break; + case 2: + case 3: dir = 8; break; + } + facadeMeta = (facadeMeta & 3) | dir; + } + return facadeMeta; + } + + public static int rotateFacadeMetadata(Block facadeID, int facadeMeta, ForgeDirection axis) { + if(facadeID instanceof BlockRotatedPillar) { + int dir = facadeMeta & 0xC; + ForgeDirection orientation; + switch (dir) { + case 0: orientation = ForgeDirection.UP; break; + case 4: orientation = ForgeDirection.EAST; break; + case 8: orientation = ForgeDirection.SOUTH; break; + default: return facadeMeta; + } + orientation = orientation.getRotation(axis); + switch (orientation) { + case UP: + case DOWN: dir = 0; break; + case WEST: + case EAST: dir = 4; break; + case NORTH: + case SOUTH: dir = 8; break; + default: return facadeMeta; + } + return (facadeMeta & 3) | dir; + } + return facadeMeta; + } } diff --git a/src/main/java/crazypants/enderio/machine/painter/TileEntityPaintedBlock.java b/src/main/java/crazypants/enderio/machine/painter/TileEntityPaintedBlock.java index 2938f1a5..337bbcdb 100644 --- a/src/main/java/crazypants/enderio/machine/painter/TileEntityPaintedBlock.java +++ b/src/main/java/crazypants/enderio/machine/painter/TileEntityPaintedBlock.java @@ -2,6 +2,8 @@ package crazypants.enderio.machine.painter; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import crazypants.enderio.TileEntityEio; public class TileEntityPaintedBlock extends TileEntityEio implements IPaintableTileEntity { @@ -30,6 +32,12 @@ public class TileEntityPaintedBlock extends TileEntityEio implements IPaintableT nbtRoot.setInteger(KEY_SOURCE_BLOCK_META, sourceBlockMetadata); } + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + super.onDataPacket(net, pkt); + updateBlock(); + } + @Override public Block getSourceBlock() { return sourceBlock; diff --git a/src/main/java/crazypants/enderio/machine/transceiver/Channel.java b/src/main/java/crazypants/enderio/machine/transceiver/Channel.java index 4a62f071..3578303b 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/Channel.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/Channel.java @@ -1,6 +1,10 @@ package crazypants.enderio.machine.transceiver; +import crazypants.util.PlayerUtil; import net.minecraft.nbt.NBTTagCompound; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.UUID; public class Channel { @@ -10,19 +14,19 @@ public class Channel { return null; } String name = root.getString("name"); - String user = null; + UUID user = null; if(root.hasKey("user")) { - user = root.getString("user"); + user = PlayerUtil.getPlayerUIDUnstable(root.getString("user")); } ChannelType type = ChannelType.values()[root.getShort("type")]; return new Channel(name, user, type); } private final String name; - final String user; + final UUID user; final ChannelType type; - public Channel(String name, String user, ChannelType type) { + public Channel(String name, UUID user, ChannelType type) { this.name = trim(name); this.user = user; this.type = type; @@ -38,8 +42,8 @@ public class Channel { } root.setString("name", name); root.setShort("type", (short)type.ordinal()); - if(user != null && user.length() > 0) { - root.setString("user", user); + if(user != null ) { + root.setString("user", user.toString()); } } @@ -96,7 +100,7 @@ public class Channel { return type; } - public String getUser() { + public UUID getUser() { return user; } diff --git a/src/main/java/crazypants/enderio/machine/transceiver/ClientChannelRegister.java b/src/main/java/crazypants/enderio/machine/transceiver/ClientChannelRegister.java index b459e3e0..81f328d1 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/ClientChannelRegister.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/ClientChannelRegister.java @@ -1,6 +1,10 @@ package crazypants.enderio.machine.transceiver; import crazypants.enderio.EnderIO; +import crazypants.enderio.Log; +import crazypants.util.PlayerUtil; + +import java.util.UUID; public class ClientChannelRegister extends ChannelRegister { @@ -15,8 +19,8 @@ public class ClientChannelRegister extends ChannelRegister { public void addChannel(Channel channel) { if(channel == null) { return; - } - if(channel.getUser() != null && !channel.getUser().equals(EnderIO.proxy.getClientPlayer().getGameProfile().getName())) { + } + if(channel.getUser() != null && !channel.getUser().equals(PlayerUtil.getPlayerUUID(EnderIO.proxy.getClientPlayer().getGameProfile().getName()))) { return; } super.addChannel(channel); diff --git a/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java b/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java index 92955392..1b121d06 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java @@ -15,6 +15,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import crazypants.util.PlayerUtil; import net.minecraft.item.ItemStack; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.util.ForgeDirection; @@ -66,7 +67,7 @@ public class ServerChannelRegister extends ChannelRegister { } int oridinal = reader.nextInt(); - Channel chan = new Channel(name, user, ChannelType.values()[oridinal]); + Channel chan = new Channel(name, PlayerUtil.getPlayerUIDUnstable(user), ChannelType.values()[oridinal]); instance.addChannel(chan); reader.endObject(); @@ -144,7 +145,7 @@ public class ServerChannelRegister extends ChannelRegister { writer.beginObject(); writer.name("name").value(chan.getName()); if(chan.getUser() != null) { - writer.name("user").value(chan.getUser()); + writer.name("user").value(chan.getUser().toString()); } writer.name("type").value(chan.getType().ordinal()); writer.endObject(); diff --git a/src/main/java/crazypants/enderio/machine/transceiver/gui/ChannelTab.java b/src/main/java/crazypants/enderio/machine/transceiver/gui/ChannelTab.java index 9a6e5573..605b6331 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/gui/ChannelTab.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/gui/ChannelTab.java @@ -2,6 +2,7 @@ package crazypants.enderio.machine.transceiver.gui; import java.awt.Color; +import crazypants.util.PlayerUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; @@ -250,7 +251,7 @@ public class ChannelTab implements ITabPanel { } Channel c; if(privateButton.isSelected()) { - c = new Channel(newChannelTF.getText(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName(), type); + c = new Channel(newChannelTF.getText(), PlayerUtil.getPlayerUUID(Minecraft.getMinecraft().thePlayer.getGameProfile().getName()), type); } else { c = new Channel(newChannelTF.getText(), null, type); } diff --git a/src/main/java/crazypants/enderio/teleport/GuiTravelAccessable.java b/src/main/java/crazypants/enderio/teleport/GuiTravelAccessable.java index c4058836..6f2f4004 100644 --- a/src/main/java/crazypants/enderio/teleport/GuiTravelAccessable.java +++ b/src/main/java/crazypants/enderio/teleport/GuiTravelAccessable.java @@ -146,7 +146,7 @@ public class GuiTravelAccessable extends GuiContainerBase { } @Override - protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { + public void drawGuiContainerBackgroundLayer(float f, int i, int j) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); RenderUtil.bindTexture("enderio:textures/gui/travelAccessable.png"); int sx = (width - xSize) / 2; diff --git a/src/main/java/crazypants/enderio/teleport/GuiTravelAuth.java b/src/main/java/crazypants/enderio/teleport/GuiTravelAuth.java index 6c7eed25..a3f0aeae 100644 --- a/src/main/java/crazypants/enderio/teleport/GuiTravelAuth.java +++ b/src/main/java/crazypants/enderio/teleport/GuiTravelAuth.java @@ -1,7 +1,6 @@ package crazypants.enderio.teleport; import java.awt.Color; -import java.util.UUID; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -73,7 +72,7 @@ public class GuiTravelAuth extends GuiContainerBase { } @Override - protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) { + public void drawGuiContainerBackgroundLayer(float f, int mx, int my) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); RenderUtil.bindTexture("enderio:textures/gui/travelAuth.png"); int sx = (width - xSize) / 2; diff --git a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java index 99641834..0ee4c7f6 100644 --- a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java +++ b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java @@ -2,6 +2,7 @@ package crazypants.enderio.teleport.anchor; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -17,9 +18,10 @@ import crazypants.enderio.api.teleport.ITravelAccessable; import crazypants.enderio.api.teleport.TravelSource; import crazypants.enderio.machine.painter.IPaintableTileEntity; import crazypants.util.BlockCoord; +import crazypants.util.PlayerUtil; public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable, IPaintableTileEntity { - + private static final String KEY_SOURCE_BLOCK_ID = "sourceBlock"; private static final String KEY_SOURCE_BLOCK_META = "sourceBlockMeta"; @@ -34,9 +36,9 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable private String label; - private String placedBy; + private UUID placedBy; - private List authorisedUsers = new ArrayList(); + private List authorisedUsers = new ArrayList(); @Override public boolean canBlockBeAccessed(EntityPlayer playerName) { @@ -44,12 +46,12 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable return true; } if(accessMode == AccessMode.PRIVATE) { - return placedBy != null && placedBy.equals(playerName.getGameProfile().getName()); + return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName())); } - if(placedBy != null && placedBy.equals(playerName.getGameProfile().getName())) { + if(placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()))) { return true; } - return authorisedUsers.contains(playerName.getGameProfile().getName()); + return authorisedUsers.contains(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName())); } @Override @@ -83,13 +85,13 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable @Override public boolean getRequiresPassword(EntityPlayer username) { - return getAccessMode() != AccessMode.PUBLIC && !canUiBeAccessed(username) && !authorisedUsers.contains(username.getGameProfile().getName()); + return getAccessMode() != AccessMode.PUBLIC && !canUiBeAccessed(username) && !authorisedUsers.contains(PlayerUtil.getPlayerUUID(username.getGameProfile().getName())); } @Override public boolean authoriseUser(EntityPlayer username, ItemStack[] password) { if(checkPassword(password)) { - authorisedUsers.add(username.getGameProfile().getName()); + authorisedUsers.add(PlayerUtil.getPlayerUUID(username.getGameProfile().getName())); return true; } return false; @@ -97,7 +99,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable @Override public boolean canUiBeAccessed(EntityPlayer playerName) { - return placedBy != null && placedBy.equals(playerName.getGameProfile().getName()); + return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName())); } @Override @@ -105,7 +107,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable if(accessMode != AccessMode.PRIVATE) { return true; } - return placedBy != null && placedBy.equals(playerName.getGameProfile().getName()); + return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName())); } @Override @@ -147,7 +149,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable } @Override - public String getPlacedBy() { + public UUID getPlacedBy() { return placedBy; } @@ -156,7 +158,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable if(player == null || player.getGameProfile() == null) { this.placedBy = null; } else { - placedBy = player.getGameProfile().getName(); + placedBy = PlayerUtil.getPlayerUUID(player.getGameProfile().getName()); } } @@ -204,7 +206,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable //keep behavior the same for blocks placed prior to this update accessMode = AccessMode.PUBLIC; } - placedBy = root.getString("placedBy"); + placedBy = PlayerUtil.getPlayerUIDUnstable(root.getString("placedBy")); for (int i = 0; i < password.length; i++) { if(root.hasKey("password" + i)) { NBTTagCompound stackRoot = (NBTTagCompound) root.getTag("password" + i); @@ -221,7 +223,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable if(user != null) { user = user.trim(); if(user.length() > 0) { - authorisedUsers.add(user); + authorisedUsers.add(PlayerUtil.getPlayerUIDUnstable(user)); } } } @@ -246,7 +248,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable @Override protected void writeCustomNBT(NBTTagCompound root) { root.setShort("accessMode", (short) accessMode.ordinal()); - if(placedBy != null && !placedBy.trim().isEmpty()) { + if(placedBy != null ) { root.setString("placedBy", placedBy.toString()); } for (int i = 0; i < password.length; i++) { @@ -258,7 +260,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable } } StringBuffer userStr = new StringBuffer(); - for (String user : authorisedUsers) { + for (UUID user : authorisedUsers) { if(user != null) { userStr.append(user.toString()); userStr.append(","); diff --git a/src/main/java/crazypants/enderio/teleport/telepad/BlockTelePad.java b/src/main/java/crazypants/enderio/teleport/telepad/BlockTelePad.java index 28795bab..b86e38f6 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/BlockTelePad.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/BlockTelePad.java @@ -109,7 +109,7 @@ public class BlockTelePad extends BlockTravelAnchor { TileEntity te = world.getTileEntity(x, y, z); if(te instanceof ITravelAccessable) { if(ID == GuiHandler.GUI_ID_TELEPAD) { - return new GuiTravelAccessable(player.inventory, (ITravelAccessable) te, world); + return new GuiTelePad(player.inventory, (ITravelAccessable) te, world); } else { return new GuiTravelAuth(player, (ITravelAccessable) te, world); } diff --git a/src/main/java/crazypants/enderio/teleport/telepad/GuiTelePad.java b/src/main/java/crazypants/enderio/teleport/telepad/GuiTelePad.java index 24152467..6342dd1e 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/GuiTelePad.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/GuiTelePad.java @@ -1,14 +1,73 @@ package crazypants.enderio.teleport.telepad; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.world.World; -import crazypants.enderio.api.teleport.ITravelAccessable; -import crazypants.enderio.teleport.GuiTravelAccessable; -public class GuiTelePad extends GuiTravelAccessable { +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder; +import crazypants.enderio.api.teleport.ITravelAccessable; +import crazypants.enderio.gui.IconEIO; +import crazypants.enderio.gui.ToggleButtonEIO; +import crazypants.enderio.teleport.ContainerTravelAccessable; +import crazypants.enderio.teleport.GuiTravelAccessable; +import crazypants.gui.GuiContainerBase; +import crazypants.render.RenderUtil; + +public class GuiTelePad extends GuiContainerBase { + + private static final int ID_SWITCH_BUTTON = 99; + + private GuiTravelAccessable behind; + private boolean showBehind; + + ToggleButtonEIO switchButton; + ToggleButtonEIO behindSwitchButton; public GuiTelePad(InventoryPlayer playerInv, ITravelAccessable te, World world) { - super(playerInv, te, world); + super(new ContainerTravelAccessable(playerInv, te, world)); + behind = new GuiTravelAccessable(playerInv, te, world); + + switchButton = new ToggleButtonEIO(this, ID_SWITCH_BUTTON, 50, 10, IconEIO.BUTTON, IconEIO.CHECKED_BUTTON); } + @Override + public void initGui() { + super.initGui(); + switchButton.onGuiInit(); + + behind.width = this.width; + behind.height = this.height; + behind.setGuiLeft(this.guiLeft); + behind.setGuiTop(this.guiTop); +// behind.setXSize(this.xSize); +// behind.setYSize(this.ySize); + behind.mc = this.mc; + behind.initGui(); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + if(showBehind) { + behind.drawGuiContainerBackgroundLayer(p_146976_1_, p_146976_2_, p_146976_3_); + } else { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderUtil.bindTexture("enderio:textures/gui/telePad.png"); + int sx = (width - xSize) / 2; + int sy = (height - ySize) / 2; + + drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize); + } + } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + switch (button.id) { + case ID_SWITCH_BUTTON: + showBehind = !showBehind; + break; + } + } } diff --git a/src/main/java/crazypants/gui/GuiContainerBase.java b/src/main/java/crazypants/gui/GuiContainerBase.java index bedda7cd..3dc25e9f 100644 --- a/src/main/java/crazypants/gui/GuiContainerBase.java +++ b/src/main/java/crazypants/gui/GuiContainerBase.java @@ -1,6 +1,5 @@ package crazypants.gui; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -19,12 +18,10 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -import cpw.mods.fml.common.Optional; -import cpw.mods.fml.relauncher.ReflectionHelper; import codechicken.nei.VisiblityData; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.TaggedInventoryArea; -import crazypants.enderio.Log; +import cpw.mods.fml.common.Optional; import crazypants.enderio.gui.IGuiOverlay; import crazypants.gui.ToolTipManager.ToolTipRenderer; import crazypants.render.RenderUtil; @@ -294,6 +291,22 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe public int getYSize() { return ySize; } + + public void setGuiLeft(int i) { + guiLeft = i; + } + + public void setGuiTop(int i) { + guiTop = i; + } + + public void setXSize(int i) { + xSize = i; + } + + public void setYSize(int i) { + ySize = i; + } @Override public FontRenderer getFontRenderer() { diff --git a/src/main/java/crazypants/util/PlayerUtil.java b/src/main/java/crazypants/util/PlayerUtil.java new file mode 100644 index 00000000..135dd787 --- /dev/null +++ b/src/main/java/crazypants/util/PlayerUtil.java @@ -0,0 +1,56 @@ +package crazypants.util; + + +import net.minecraftforge.common.UsernameCache; + +import java.util.Map; +import java.util.UUID; + + +public class PlayerUtil { + + + + public static UUID getPlayerUUID(String username) + { + /* + if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(username); + UUID uuid = null; + if (profile == null) + uuid = EntityPlayer.func_146094_a(new GameProfile(null, username)); + else + uuid = profile.getId(); + return uuid; + } + else + return PacketPlayerUUID.playerUUID.get(username); + */ + for (Map.Entry entry : UsernameCache.getMap().entrySet()) + { + + if (entry.getValue().equalsIgnoreCase(username)) + { + return entry.getKey(); + } + } + return null; + } + + + public static UUID getPlayerUIDUnstable(String possibleUUID) + { + if(possibleUUID==null || possibleUUID.isEmpty()) + return null; + UUID uuid=null; + try + { + uuid=UUID.fromString(possibleUUID); + } + catch(IllegalArgumentException e) + { + uuid=getPlayerUUID(possibleUUID); + } + return uuid; + } +}