mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-25 06:24:24 +00:00
Basic telepad GUI functional, now only opens when formed.
Also fix up forming code
This commit is contained in:
1 parent
e4c6034476
commit
61eb85eb97
16 files changed
+499
-60
No files matched your search
@@ -53,6 +53,7 @@ public class GuiHandler implements IGuiHandler {
|
||||
public static final int GUI_ID_BUFFER = 100;
|
||||
public static final int GUI_ID_WEATHER_OBELISK = 101;
|
||||
public static final int GUI_ID_TELEPAD = 102;
|
||||
public static final int GUI_ID_TELEPAD_TRAVEL = 103;
|
||||
|
||||
public static final int GUI_ID_CAP_BANK = 142; // leave room for more machines
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import crazypants.util.ArrayInventory;
|
||||
|
||||
public class ContainerTravelAccessable extends Container {
|
||||
|
||||
private ITravelAccessable ta;
|
||||
private TileEntity te;
|
||||
private World world;
|
||||
ITravelAccessable ta;
|
||||
TileEntity te;
|
||||
World world;
|
||||
|
||||
public ContainerTravelAccessable(InventoryPlayer playerInv, final ITravelAccessable travelAccessable, World world) {
|
||||
ta = travelAccessable;
|
||||
|
||||
@@ -45,12 +45,16 @@ public class GuiTravelAccessable extends GuiContainerBase {
|
||||
private int col1x;
|
||||
private int col2x;
|
||||
|
||||
private World world;
|
||||
protected World world;
|
||||
|
||||
public GuiTravelAccessable(InventoryPlayer playerInv, ITravelAccessable te, World world) {
|
||||
super(new ContainerTravelAccessable(playerInv, te, world));
|
||||
this.te = te;
|
||||
this.world = world;
|
||||
this(new ContainerTravelAccessable(playerInv, te, world));
|
||||
}
|
||||
|
||||
public GuiTravelAccessable(ContainerTravelAccessable container) {
|
||||
super(container);
|
||||
this.te = container.ta;
|
||||
this.world = container.world;
|
||||
|
||||
publicStr = Lang.localize("gui.travelAccessable.public");
|
||||
privateStr = Lang.localize("gui.travelAccessable.private");
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
package crazypants.enderio.teleport.anchor;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.UsernameCache;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.api.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.MachineRecipeRegistry;
|
||||
import crazypants.enderio.machine.painter.BasicPainterTemplate;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.ConnectionHandler;
|
||||
import crazypants.enderio.teleport.ContainerTravelAccessable;
|
||||
import crazypants.enderio.teleport.ContainerTravelAuth;
|
||||
import crazypants.enderio.teleport.GuiTravelAccessable;
|
||||
import crazypants.enderio.teleport.GuiTravelAuth;
|
||||
import crazypants.enderio.teleport.packet.PacketAccessMode;
|
||||
import crazypants.enderio.teleport.packet.PacketConfigSync;
|
||||
import crazypants.enderio.teleport.packet.PacketDrainStaff;
|
||||
import crazypants.enderio.teleport.packet.PacketLabel;
|
||||
import crazypants.enderio.teleport.packet.PacketOpenAuthGui;
|
||||
import crazypants.enderio.teleport.packet.PacketTravelEvent;
|
||||
import crazypants.util.IFacade;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEntityProvider, IResourceTooltipProvider, IFacade {
|
||||
|
||||
public static int renderId = -1;
|
||||
|
||||
public static BlockTravelAnchor create() {
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketAccessMode.class, PacketAccessMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketLabel.class, PacketLabel.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketTravelEvent.class, PacketTravelEvent.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDrainStaff.class, PacketDrainStaff.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenAuthGui.class, PacketOpenAuthGui.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketConfigSync.class, PacketConfigSync.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
ConnectionHandler ch = new ConnectionHandler();
|
||||
FMLCommonHandler.instance().bus().register(ch);
|
||||
|
||||
BlockTravelAnchor result = new BlockTravelAnchor();
|
||||
result.init();
|
||||
return result;
|
||||
}
|
||||
|
||||
IIcon selectedOverlayIcon;
|
||||
IIcon highlightOverlayIcon;
|
||||
|
||||
private BlockTravelAnchor() {
|
||||
super(ModObject.blockTravelAnchor.unlocalisedName, TileTravelAnchor.class);
|
||||
if(!Config.travelAnchorEnabled) {
|
||||
setCreativeTab(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected BlockTravelAnchor(String name, Class<? extends TileEntityEio> clazz) {
|
||||
super(name, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
if(getClass() == BlockTravelAnchor.class) {
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, this);
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TRAVEL_AUTH, this);
|
||||
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPainter.unlocalisedName, new PainterTemplate());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister iIconRegister) {
|
||||
super.registerBlockIcons(iIconRegister);
|
||||
highlightOverlayIcon = iIconRegister.registerIcon("enderio:blockTravelAnchorHighlight");
|
||||
selectedOverlayIcon = iIconRegister.registerIcon("enderio:blockTravelAnchorSelected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
TileTravelAnchor tef = (TileTravelAnchor) te;
|
||||
if(tef.getSourceBlock() != null) {
|
||||
return tef.getSourceBlock().getIcon(blockSide, tef.getSourceBlockMetadata());
|
||||
}
|
||||
}
|
||||
return super.getIcon(world, x, y, z, blockSide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1, int var2) {
|
||||
return new TileTravelAnchor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack par6ItemStack) {
|
||||
if(entity instanceof EntityPlayer) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
TileTravelAnchor ta = (TileTravelAnchor) te;
|
||||
ta.setPlacedBy((EntityPlayer) entity);
|
||||
Block b = PainterUtil.getSourceBlock(par6ItemStack);
|
||||
ta.setSourceBlock(b);
|
||||
ta.setSourceBlockMetadata(PainterUtil.getSourceBlockMetadata(par6ItemStack));
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
ITravelAccessable ta = (ITravelAccessable) te;
|
||||
if(ta.canUiBeAccessed(entityPlayer)) {
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, world, x, y, z);
|
||||
} else {
|
||||
if(world.isRemote && !entityPlayer.isSneaking()) {
|
||||
entityPlayer.addChatComponentMessage(new ChatComponentText(Lang.localize("gui.travelAccessable.privateBlock1") + " " + UsernameCache.getLastKnownUsername(ta.getPlacedBy()) + " "
|
||||
+ Lang.localize("gui.travelAccessable.privateBlock2")));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
if(ID == GuiHandler.GUI_ID_TRAVEL_ACCESSABLE) {
|
||||
return new ContainerTravelAccessable(player.inventory, (ITravelAccessable) te, world);
|
||||
} else {
|
||||
return new ContainerTravelAuth(player.inventory);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
if(ID == GuiHandler.GUI_ID_TRAVEL_ACCESSABLE) {
|
||||
return new GuiTravelAccessable(player.inventory, (ITravelAccessable) te, world);
|
||||
} else {
|
||||
return new GuiTravelAuth(player, (ITravelAccessable) te, world);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
|
||||
TileTravelAnchor anchor = (TileTravelAnchor) te;
|
||||
|
||||
if(anchor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(this);
|
||||
Block srcBlk = anchor.getSourceBlock();
|
||||
if(srcBlk != null) {
|
||||
itemStack = createItemStackForSourceBlock(anchor.getSourceBlock(), anchor.getSourceBlockMetadata());
|
||||
drop.stackTagCompound = (NBTTagCompound) itemStack.stackTagCompound.copy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doNormalDrops(World world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
TileTravelAnchor tef = (TileTravelAnchor) te;
|
||||
if(tef.getSourceBlock() != null) {
|
||||
return tef.getSourceBlock().colorMultiplier(world, x, y, z);
|
||||
}
|
||||
}
|
||||
return super.colorMultiplier(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
public ItemStack createItemStackForSourceBlock(Block block, int damage) {
|
||||
if(block == this) {
|
||||
return new ItemStack(this);
|
||||
}
|
||||
ItemStack result = new ItemStack(this, 1, damage);
|
||||
PainterUtil.setSourceBlock(result, block, damage);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final class PainterTemplate extends BasicPainterTemplate {
|
||||
|
||||
public PainterTemplate() {
|
||||
super(BlockTravelAnchor.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStack[] getCompletedResult(float chance, MachineRecipeInput... inputs) {
|
||||
ItemStack paintSource = MachineRecipeInput.getInputForSlot(1, inputs);
|
||||
if(paintSource == null) {
|
||||
return new ResultStack[0];
|
||||
}
|
||||
return new ResultStack[] { new ResultStack(createItemStackForSourceBlock(Block.getBlockFromItem(paintSource.getItem()), paintSource.getItemDamage())) };
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
return ((TileTravelAnchor) te).getSourceBlockMetadata();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getFacade(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
return ((TileTravelAnchor) te).getSourceBlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,14 @@ import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.UsernameCache;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.api.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.ContainerTravelAccessable;
|
||||
import crazypants.enderio.teleport.ContainerTravelAuth;
|
||||
import crazypants.enderio.teleport.GuiTravelAuth;
|
||||
@@ -28,6 +30,7 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
|
||||
public static BlockTelePad create() {
|
||||
BlockTelePad ret = new BlockTelePad();
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenServerGui.class, PacketOpenServerGui.class, PacketHandler.nextID(), Side.SERVER);
|
||||
ret.init();
|
||||
return ret;
|
||||
}
|
||||
@@ -40,8 +43,9 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
protected void init() {
|
||||
super.init();
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TELEPAD, this);
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TELEPAD_TRAVEL, this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister iIconRegister) {
|
||||
unconnected = iIconRegister.registerIcon("EnderIO:blockTelePad");
|
||||
@@ -76,13 +80,23 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
@Override
|
||||
public boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
ITravelAccessable ta = (ITravelAccessable) te;
|
||||
if(ta.canUiBeAccessed(entityPlayer)) {
|
||||
if(te instanceof TileTelePad) {
|
||||
TileTelePad tp = (TileTelePad) te;
|
||||
if (tp.inNetwork) {
|
||||
if (!tp.isMaster()) {
|
||||
TileTelePad master = tp.getMaster();
|
||||
openGui(world, master.xCoord, master.yCoord, master.zCoord, entityPlayer, side);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// from here out we know that we are connected and are the master
|
||||
if(tp.canUiBeAccessed(entityPlayer)) {
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TELEPAD, world, x, y, z);
|
||||
} else {
|
||||
if(world.isRemote && !entityPlayer.isSneaking()) {
|
||||
entityPlayer.addChatComponentMessage(new ChatComponentText(Lang.localize("gui.travelAccessable.privateBlock1") + " " + ta.getPlacedBy() + " "
|
||||
entityPlayer.addChatComponentMessage(new ChatComponentText(Lang.localize("gui.travelAccessable.privateBlock1") + " " + UsernameCache.getLastKnownUsername(tp.getPlacedBy()) + " "
|
||||
+ Lang.localize("gui.travelAccessable.privateBlock2")));
|
||||
}
|
||||
}
|
||||
@@ -93,10 +107,13 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
if(ID == GuiHandler.GUI_ID_TELEPAD) {
|
||||
return new ContainerTravelAccessable(player.inventory, (ITravelAccessable) te, world);
|
||||
} else {
|
||||
if(te instanceof TileTelePad) {
|
||||
switch (ID) {
|
||||
case GuiHandler.GUI_ID_TELEPAD:
|
||||
return new ContainerTelePad(player.inventory);
|
||||
case GuiHandler.GUI_ID_TELEPAD_TRAVEL:
|
||||
return new ContainerTravelAccessable(player.inventory, (TileTelePad) te, world);
|
||||
default:
|
||||
return new ContainerTravelAuth(player.inventory);
|
||||
}
|
||||
}
|
||||
@@ -106,10 +123,13 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
if(ID == GuiHandler.GUI_ID_TELEPAD) {
|
||||
return new GuiTelePad(player.inventory, (ITravelAccessable) te, world);
|
||||
} else {
|
||||
if(te instanceof TileTelePad) {
|
||||
switch (ID) {
|
||||
case GuiHandler.GUI_ID_TELEPAD:
|
||||
return new GuiTelePad(player.inventory, (TileTelePad) te, world);
|
||||
case GuiHandler.GUI_ID_TELEPAD_TRAVEL:
|
||||
return new GuiAugmentedTravelAccessible(player.inventory, (TileTelePad) te, world);
|
||||
default:
|
||||
return new GuiTravelAuth(player, (ITravelAccessable) te, world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ContainerTelePad extends Container {
|
||||
|
||||
InventoryPlayer playerInv;
|
||||
|
||||
public ContainerTelePad(InventoryPlayer playerInv) {
|
||||
|
||||
this.playerInv = playerInv;
|
||||
|
||||
// add players inventory
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 161));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.ContainerTravelAccessable;
|
||||
import crazypants.enderio.teleport.GuiTravelAccessable;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class GuiAugmentedTravelAccessible extends GuiTravelAccessable implements IToggleableGui {
|
||||
|
||||
private static final int ID_SWITCH_BUTTON = 99;
|
||||
|
||||
ToggleTravelButton switchButton;
|
||||
|
||||
private TileTelePad te;
|
||||
|
||||
public GuiAugmentedTravelAccessible(InventoryPlayer playerInv, TileTelePad te, World world) {
|
||||
super(playerInv, te, world);
|
||||
this.te = te;
|
||||
switchButton = new ToggleTravelButton(this, ID_SWITCH_BUTTON, 150, 10, IconEIO.IO_WHATSIT);
|
||||
switchButton.setToolTip(Lang.localize("gui.telepad.configure.telepad"));
|
||||
}
|
||||
|
||||
public GuiAugmentedTravelAccessible(ContainerTravelAccessable container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
switchButton.onGuiInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchGui() {
|
||||
mc.thePlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TELEPAD, world, te.xCoord, te.yCoord, te.zCoord);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketOpenServerGui(te, GuiHandler.GUI_ID_TELEPAD));
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,57 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import crazypants.enderio.api.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.teleport.ContainerTravelAccessable;
|
||||
import crazypants.enderio.teleport.GuiTravelAccessable;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class GuiTelePad extends GuiContainerBase {
|
||||
public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
|
||||
private static final int ID_SWITCH_BUTTON = 99;
|
||||
|
||||
private GuiTravelAccessable behind;
|
||||
private boolean showBehind;
|
||||
ToggleTravelButton switchButton;
|
||||
|
||||
private World world;
|
||||
private TileTelePad te;
|
||||
|
||||
ToggleButtonEIO switchButton;
|
||||
ToggleButtonEIO behindSwitchButton;
|
||||
|
||||
public GuiTelePad(InventoryPlayer playerInv, ITravelAccessable te, World 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);
|
||||
public GuiTelePad(InventoryPlayer playerInv, TileTelePad te, World world) {
|
||||
super(new ContainerTelePad(playerInv));
|
||||
this.world = world;
|
||||
this.te = te;
|
||||
|
||||
switchButton = new ToggleTravelButton(this, ID_SWITCH_BUTTON, 150, 10, IconEIO.IO_WHATSIT);
|
||||
switchButton.setToolTip(Lang.localize("gui.telepad.configure.travel"));
|
||||
|
||||
this.ySize += 19;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
public void switchGui() {
|
||||
mc.thePlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TELEPAD_TRAVEL, world, te.xCoord, te.yCoord, te.zCoord);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketOpenServerGui(te, GuiHandler.GUI_ID_TELEPAD_TRAVEL));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import crazypants.gui.IGuiScreen;
|
||||
|
||||
public interface IToggleableGui extends IGuiScreen {
|
||||
|
||||
void switchGui();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
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 crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketOpenServerGui extends MessageTileEntity<TileTelePad> implements IMessageHandler<PacketOpenServerGui, IMessage> {
|
||||
|
||||
public PacketOpenServerGui() {
|
||||
}
|
||||
|
||||
int id;
|
||||
|
||||
public PacketOpenServerGui(TileTelePad te, int guiId) {
|
||||
super(te);
|
||||
this.id = guiId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
this.id = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketOpenServerGui message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
World world = message.getWorld(ctx);
|
||||
TileTelePad te = message.getTileEntity(world);
|
||||
|
||||
if(te != null) {
|
||||
player.openGui(EnderIO.instance, message.id, world, te.xCoord, te.yCoord, te.zCoord);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,12 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
TileEntity te = bc.getTileEntity(worldObj);
|
||||
ForgeDirection con = Util.getDirFromOffset(xCoord - bc.x, 0, zCoord - bc.z);
|
||||
if(te instanceof TileTelePad) {
|
||||
if(fromBlock) {
|
||||
// let's find the master and let him do the work
|
||||
if(((TileTelePad) te).isMaster() && fromBlock) {
|
||||
((TileTelePad) te).updateConnectedState(false);
|
||||
return;
|
||||
}
|
||||
// otherwise we either are the master or this is a secondary call, so update connections
|
||||
if(con != ForgeDirection.UNKNOWN && !((TileTelePad) te).inNetwork) {
|
||||
connections.add(con);
|
||||
}
|
||||
@@ -81,6 +84,10 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
public boolean isMaster() {
|
||||
return connections.size() == 4;
|
||||
}
|
||||
|
||||
public TileTelePad getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
||||
private boolean formNetwork() {
|
||||
List<TileTelePad> temp = Lists.newArrayList();
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
|
||||
public class ToggleTravelButton extends IconButtonEIO {
|
||||
|
||||
IToggleableGui gui;
|
||||
|
||||
public ToggleTravelButton(IToggleableGui gui, int id, int x, int y, IconEIO icon) {
|
||||
super(gui, id, x, y, icon);
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if(result) {
|
||||
gui.switchGui();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
private int realMx, realMy;
|
||||
|
||||
@Override
|
||||
protected final void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
public final void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
drawForegroundImpl(mouseX, mouseY);
|
||||
|
||||
Timer t = RenderUtil.getTimer();
|
||||
|
||||
@@ -24,5 +24,4 @@ public interface IGuiScreen {
|
||||
|
||||
void doActionPerformed(GuiButton but);
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user