Started re-write of dim. trans.

This commit is contained in:
CrazyPants committed 2014-10-09 13:58:36 +08:00
1 parent 8ce3b77fb9
commit b7f9cfb013
41 files changed
+3538 -39

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
package crazypants;
import java.io.BufferedReader;
import java.io.FileReader;
public class Crap {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("C:\\MyData\\Dev\\Minecraft\\Workspace17\\PamsSeeds.txt"));
String line = br.readLine();
System.out.println("private static final String[] PAMS_SEEDS = new String[] {");
while(line != null) {
System.out.println("\"" + line.trim() + "\",");
line = br.readLine();
}
System.out.println("};");
}
}
@@ -104,6 +104,8 @@ import crazypants.enderio.machine.still.VatRenderer;
import crazypants.enderio.machine.tank.TankFluidRenderer;
import crazypants.enderio.machine.tank.TankItemRenderer;
import crazypants.enderio.machine.tank.TileTank;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.enderio.machine.transceiver.render.TransceiverRenderer;
import crazypants.enderio.machine.vacuum.BlockVacuumChest;
import crazypants.enderio.machine.vacuum.VacuumChestRenderer;
import crazypants.enderio.machine.xp.BlockExperianceObelisk;
@@ -344,6 +346,10 @@ public class ClientProxy extends CommonProxy {
HyperCubeRenderer hcr = new HyperCubeRenderer();
ClientRegistry.bindTileEntitySpecialRenderer(TileHyperCube.class, hcr);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockHyperCube), hcr);
TransceiverRenderer tr = new TransceiverRenderer();
ClientRegistry.bindTileEntitySpecialRenderer(TileTransceiver.class, tr);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockTransceiver), tr);
new YetaWrenchOverlayRenderer(EnderIO.itemYetaWench);
new ConduitProbeOverlayRenderer();
@@ -114,6 +114,8 @@ import crazypants.enderio.machine.spawnguard.RangeEntity;
import crazypants.enderio.machine.still.BlockVat;
import crazypants.enderio.machine.still.VatRecipeManager;
import crazypants.enderio.machine.tank.BlockTank;
import crazypants.enderio.machine.transceiver.BlockTransceiver;
import crazypants.enderio.machine.transceiver.ServerChannelRegister;
import crazypants.enderio.machine.vacuum.BlockVacuumChest;
import crazypants.enderio.machine.wireless.BlockWirelessCharger;
import crazypants.enderio.machine.xp.BlockExperianceObelisk;
@@ -221,6 +223,7 @@ public class EnderIO {
public static BlockAttractor blockAttractor;
public static BlockSpawnGuard blockSpawnGuard;
public static BlockExperianceObelisk blockExperianceOblisk;
public static BlockTransceiver blockTransceiver;
public static BlockKillerJoe blockKillerJoe;
@@ -314,6 +317,8 @@ public class EnderIO {
blockTank = BlockTank.create();
blockReservoir = BlockReservoir.create();
blockVacuumChest = BlockVacuumChest.create();
blockTransceiver = BlockTransceiver.create();
blockEnderIo = BlockEnderIO.create();
blockTravelPlatform = BlockTravelAnchor.create();
@@ -597,10 +602,12 @@ public class EnderIO {
@EventHandler
public void serverStarted(FMLServerStartedEvent event) {
HyperCubeRegister.load();
ServerChannelRegister.load();
}
@EventHandler
public void serverStopped(FMLServerStoppedEvent event) {
HyperCubeRegister.unload();
ServerChannelRegister.store();
}
}
@@ -47,6 +47,7 @@ public class GuiHandler implements IGuiHandler {
public static final int GUI_ID_SLICE_N_SPLICE = 94;
public static final int GUI_ID_ATTRACTOR = 95;
public static final int GUI_ID_SPAWN_GUARD = 96;
public static final int GUI_ID_TRANSCEIVER = 97;
protected final Map<Integer, IGuiHandler> guiHandlers = new HashMap<Integer, IGuiHandler>();
@@ -56,6 +56,7 @@ public enum ModObject {
blockAttractor,
blockSpawnGuard,
blockExperienceObelisk,
blockTransceiver,
blockPoweredSpawner,
itemBrokenSpawner,
@@ -11,13 +11,14 @@ import org.lwjgl.opengl.GL11;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.packet.PacketConnectionMode;
import crazypants.enderio.gui.ITabPanel;
import crazypants.enderio.gui.IconButtonEIO;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.network.PacketHandler;
import crazypants.render.ColorUtil;
import crazypants.util.Lang;
public class BaseSettingsPanel implements ISettingsPanel {
public class BaseSettingsPanel implements ITabPanel {
static final int PREV_MODE_B = 327;
static final int NEXT_MODE_B = 328;
@@ -88,8 +89,15 @@ public class BaseSettingsPanel implements ISettingsPanel {
public void deactivate() {
}
public void mouseClicked(int x, int y, int par3) {
public void mouseClicked(int x, int y, int par3) {
}
@Override
public void keyTyped(char par1, int par2) {
}
@Override
public void updateScreen() {
}
@Override
@@ -21,6 +21,7 @@ import crazypants.enderio.conduit.item.IItemConduit;
import crazypants.enderio.conduit.liquid.ILiquidConduit;
import crazypants.enderio.conduit.power.IPowerConduit;
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
import crazypants.enderio.gui.ITabPanel;
import crazypants.enderio.gui.IconEIO;
import crazypants.gui.GuiContainerBase;
import crazypants.render.RenderUtil;
@@ -49,7 +50,7 @@ public class GuiExternalConnection extends GuiContainerBase {
private final ForgeDirection dir;
private final List<IConduit> conduits = new ArrayList<IConduit>();
private final List<ISettingsPanel> tabs = new ArrayList<ISettingsPanel>();
private final List<ITabPanel> tabs = new ArrayList<ITabPanel>();
private int activeTab = 0;
private int tabYOffset = 4;
@@ -91,7 +92,7 @@ public class GuiExternalConnection extends GuiContainerBase {
for (IConduit con : cons) {
if(con.containsExternalConnection(dir) || con.canConnectToExternal(dir, true)) {
ISettingsPanel tab = TabFactory.instance.createPanelForConduit(this, con);
ITabPanel tab = TabFactory.instance.createPanelForConduit(this, con);
if(tab != null) {
conduits.add(con);
tabs.add(tab);
@@ -7,6 +7,7 @@ import crazypants.enderio.conduit.item.IItemConduit;
import crazypants.enderio.conduit.liquid.ILiquidConduit;
import crazypants.enderio.conduit.power.IPowerConduit;
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
import crazypants.enderio.gui.ITabPanel;
public class TabFactory {
@@ -15,7 +16,7 @@ public class TabFactory {
private TabFactory() {
}
public ISettingsPanel createPanelForConduit(GuiExternalConnection gui, IConduit con) {
public ITabPanel createPanelForConduit(GuiExternalConnection gui, IConduit con) {
Class<? extends IConduit> baseType = con.getBaseConduitType();
if(baseType.isAssignableFrom(IPowerConduit.class)) {
return new PowerSettings(gui, con);
@@ -40,17 +40,7 @@ import net.minecraftforge.event.entity.living.EnderTeleportEvent;
public class EntityEnderminy extends EntityMob {
private final class ClosestEntityComparator implements Comparator<EntityCreeper> {
Vector3d pos = new Vector3d(posX, posY, posZ);
@Override
public int compare(EntityCreeper o1, EntityCreeper o2) {
double d1 = new Vector3d(o1.posX, o1.posY, o1.posZ).distanceSquared(pos);
double d2 = new Vector3d(o2.posX, o2.posY, o2.posZ).distanceSquared(pos);
return Double.compare(d1, d2);
}
}
public static String NAME = "Enderminy";
private static final int MAX_RND_TP_DISTANCE = 32;
@@ -390,6 +380,10 @@ public class EntityEnderminy extends EntityMob {
if(!groupAgroEnabled) {
return;
}
if(! (entityToAttack instanceof EntityPlayer)) {
return;
}
System.out.println("EntityEnderminy.doGroupArgo: ");
int range = 16;
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range);
List<EntityEnderminy> minies = worldObj.getEntitiesWithinAABB(EntityEnderminy.class, bb);
@@ -410,5 +404,18 @@ public class EntityEnderminy extends EntityMob {
public void setScreaming(boolean p_70819_1_) {
dataWatcher.updateObject(18, Byte.valueOf((byte) (p_70819_1_ ? 1 : 0)));
}
private final class ClosestEntityComparator implements Comparator<EntityCreeper> {
Vector3d pos = new Vector3d();
@Override
public int compare(EntityCreeper o1, EntityCreeper o2) {
pos.set(posX,posY,posZ);
double d1 = new Vector3d(o1.posX, o1.posY, o1.posZ).distanceSquared(pos);
double d2 = new Vector3d(o2.posX, o2.posY, o2.posZ).distanceSquared(pos);
return Double.compare(d1, d2);
}
}
}
@@ -1,9 +1,8 @@
package crazypants.enderio.conduit.gui;
package crazypants.enderio.gui;
import net.minecraft.client.gui.GuiButton;
import crazypants.enderio.gui.IconEIO;
public interface ISettingsPanel {
public interface ITabPanel {
void onGuiInit(int x, int y, int width, int height);
@@ -16,5 +15,9 @@ public interface ISettingsPanel {
void actionPerformed(GuiButton guiButton);
void mouseClicked(int x, int y, int par3);
void keyTyped(char par1, int par2);
void updateScreen();
}
@@ -14,6 +14,7 @@ public final class IconEIO {
public static final IconEIO PRIVATE = new IconEIO(48, 100);
public static final IconEIO CROSS = new IconEIO(64, 100);
public static final IconEIO PLUS = new IconEIO(80, 100);
public static final IconEIO ARROWS = new IconEIO(178, 100);
public static final IconEIO BUTTON = new IconEIO(0, 116);
public static final IconEIO CHECKED_BUTTON = new IconEIO(0, 132);
@@ -1,6 +1,10 @@
package crazypants.enderio.machine;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -11,6 +15,8 @@ import net.minecraft.item.ItemStack;
public abstract class AbstractMachineContainer extends Container {
protected final AbstractMachineEntity tileEntity;
protected Map<Slot, Point> playerSlotLocations = new HashMap<Slot, Point>();
public AbstractMachineContainer(InventoryPlayer playerInv, AbstractMachineEntity te) {
this.tileEntity = te;
@@ -33,17 +39,26 @@ public abstract class AbstractMachineContainer extends Container {
}
int x = getPlayerInventoryOffset().x;
int y = getPlayerInventoryOffset().y;
int y = getPlayerInventoryOffset().y;
// 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, x + j * 18, y + i * 18));
Point loc = new Point(x + j * 18, y + i * 18);
Slot slot = new Slot(playerInv, j + i * 9 + 9, loc.x, loc.y);
addSlotToContainer(slot);
playerSlotLocations.put(slot, loc);
}
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, x + i * 18, y + 58));
Point loc = new Point(x + i * 18, y + 58);
Slot slot = new Slot(playerInv, i, loc.x, loc.y);
addSlotToContainer(slot);
playerSlotLocations.put(slot, loc);
}
}
@Override
@@ -51,11 +66,11 @@ public abstract class AbstractMachineContainer extends Container {
return tileEntity.isUseableByPlayer(entityplayer);
}
protected Point getPlayerInventoryOffset() {
public Point getPlayerInventoryOffset() {
return new Point(8,84);
}
protected Point getUpgradeOffset() {
public Point getUpgradeOffset() {
return new Point(12,60);
}
@@ -37,11 +37,11 @@ public abstract class GuiMachineBase extends GuiContainerBase {
private AbstractMachineEntity tileEntity;
private RedstoneModeButton redstoneButton;
protected RedstoneModeButton redstoneButton;
private GuiOverlayIoConfig configOverlay;
private IconButtonEIO configB;
protected IconButtonEIO configB;
public GuiMachineBase(AbstractMachineEntity machine, Container container) {
super(container);
@@ -52,15 +52,18 @@ public abstract class GuiMachineBase extends GuiContainerBase {
@Override
protected void updateText() {
text.clear();
text.add(getPowerOutputText() + PowerDisplayUtil.formatPower(tileEntity.getPowerUsePerTick()) + " " + PowerDisplayUtil.abrevation()
+ PowerDisplayUtil.perTickStr());
//text.add()
text.add(PowerDisplayUtil.formatStoredPower(tileEntity.getEnergyStored(), tileEntity.getCapacitor().getMaxEnergyStored()));
if(renderPowerBar()) {
text.add(getPowerOutputText() + PowerDisplayUtil.formatPower(tileEntity.getPowerUsePerTick()) + " " + PowerDisplayUtil.abrevation()
+ PowerDisplayUtil.perTickStr());
//text.add()
text.add(PowerDisplayUtil.formatStoredPower(tileEntity.getEnergyStored(), tileEntity.getCapacitor().getMaxEnergyStored()));
}
}
});
}
xSize = getXSize();
ySize = getYSize();
int x = getXSize() - 5 - BUTTON_SIZE;
int y = 5;
redstoneButton = new RedstoneModeButton(this, -1, x, y, tileEntity, new BlockCoord(tileEntity));
@@ -84,7 +87,7 @@ public abstract class GuiMachineBase extends GuiContainerBase {
protected boolean showRecipeButton() {
return EnderIO.proxy.isNeiInstalled();
}
protected String getPowerOutputText() {
return "Max: ";
}
@@ -152,8 +155,8 @@ public abstract class GuiMachineBase extends GuiContainerBase {
int k = (width - xSize) / 2;
int l = (height - ySize) / 2;
if(renderPowerBar()) {
int i1 = tileEntity.getEnergyStoredScaled(getPowerHeight());
if(renderPowerBar()) {
int i1 = tileEntity.getEnergyStoredScaled(getPowerHeight());
// x, y, u, v, width, height
drawTexturedModalRect(k + getPowerX(), l + (getPowerY() + getPowerHeight()) - i1, getPowerU(), getPowerV(), getPowerWidth(), i1);
}
@@ -41,11 +41,11 @@ public class ContainerCrafter extends AbstractMachineContainer {
}
@Override
protected Point getPlayerInventoryOffset() {
public Point getPlayerInventoryOffset() {
return new Point(30, 84);
}
protected Point getUpgradeOffset() {
public Point getUpgradeOffset() {
return new Point(6, 60);
}
@@ -132,6 +132,7 @@ public class ZombieGeneratorRenderer extends TileEntitySpecialRenderer implement
GL11.glPushMatrix();
GL11.glTranslatef(x, y, z);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
renderModel(ForgeDirection.SOUTH.ordinal());
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
@@ -0,0 +1,80 @@
package crazypants.enderio.machine.transceiver;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.transceiver.gui.ContainerTransceiver;
import crazypants.enderio.machine.transceiver.gui.GuiTransceiver;
import crazypants.enderio.network.PacketHandler;
public class BlockTransceiver extends AbstractMachineBlock<TileTransceiver> {
public static BlockTransceiver create() {
PacketHandler.INSTANCE.registerMessage(PacketSendRecieveChannel.class, PacketSendRecieveChannel.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketAddRemoveChannel.class, PacketAddRemoveChannel.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketAddRemoveChannel.class, PacketAddRemoveChannel.class, PacketHandler.nextID(), Side.CLIENT);
PacketHandler.INSTANCE.registerMessage(PacketChannelList.class, PacketChannelList.class, PacketHandler.nextID(), Side.CLIENT);
ConnectionHandler ch = new ConnectionHandler();
FMLCommonHandler.instance().bus().register(ch);
MinecraftForge.EVENT_BUS.register(ch);
BlockTransceiver res = new BlockTransceiver();
res.init();
return res;
}
private BlockTransceiver() {
super(ModObject.blockTransceiver, TileTransceiver.class);
}
@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 TileTransceiver) {
return new ContainerTransceiver(player.inventory, (TileTransceiver) te);
}
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);
return new GuiTransceiver(player.inventory, (TileTransceiver) te);
}
@Override
protected int getGuiId() {
return GuiHandler.GUI_ID_TRANSCEIVER;
}
@Override
protected String getMachineFrontIconKey(boolean active) {
if(active) {
return "enderio:alloySmelterFrontOn";
}
return "enderio:alloySmelterFront";
}
@Override
public int getRenderType() {
return -1;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
}
@@ -0,0 +1,104 @@
package crazypants.enderio.machine.transceiver;
import net.minecraft.nbt.NBTTagCompound;
public class Channel {
public static Channel readFromNBT(NBTTagCompound root) {
if(!root.hasKey("name")) {
return null;
}
String name = root.getString("name");
String user = null;
if(root.hasKey("user")) {
user = root.getString("user");
}
ChannelType type = ChannelType.values()[root.getShort("type")];
return new Channel(name, user, type);
}
private final String name;
final String user;
final ChannelType type;
public Channel(String name, String user, ChannelType type) {
this.name = trim(name);
this.user = user;
this.type = type;
}
public boolean isPublic() {
return user == null;
}
public void writeToNBT(NBTTagCompound root) {
if(name == null || name.isEmpty()) {
return;
}
root.setString("name", name);
root.setShort("type", (short)type.ordinal());
if(user != null && user.length() > 0) {
root.setString("user", user);
}
}
private String trim(String str) {
if(str == null) {
return null;
}
str = str.trim();
if(str.isEmpty()) {
return null;
}
return str;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
Channel other = (Channel) obj;
if(getName() == null) {
if(other.getName() != null)
return false;
} else if(!getName().equals(other.getName()))
return false;
if(type != other.type)
return false;
if(user == null) {
if(other.user != null)
return false;
} else if(!user.equals(other.user))
return false;
return true;
}
public String getName() {
return name;
}
public ChannelType getType() {
return type;
}
public String getUser() {
return user;
}
}
@@ -0,0 +1,39 @@
package crazypants.enderio.machine.transceiver;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
public class ChannelRegister {
protected EnumMap<ChannelType, List<Channel>> channels = new EnumMap<ChannelType, List<Channel>>(ChannelType.class);
public List<Channel> getChannelsForType(ChannelType type) {
return channels.get(type);
}
public void addChannel(Channel channel) {
if(channel == null) {
return;
}
List<Channel> chans = getChannelsForType(channel.getType());
if(!chans.contains(channel)) {
chans.add(channel);
}
}
public void removeChannel(Channel channel) {
if(channel == null) {
return;
}
getChannelsForType(channel.getType()).remove(channel);
}
public void reset() {
channels.clear();
for (ChannelType type : ChannelType.values()) {
channels.put(type, new ArrayList<Channel>());
}
}
}
@@ -0,0 +1,9 @@
package crazypants.enderio.machine.transceiver;
public enum ChannelType {
POWER,
ITEM,
FLUID
}
@@ -0,0 +1,27 @@
package crazypants.enderio.machine.transceiver;
import crazypants.enderio.EnderIO;
public class ClientChannelRegister extends ChannelRegister {
public static final ChannelRegister instance = new ClientChannelRegister();
private ClientChannelRegister() {
reset();
}
@Override
public void addChannel(Channel channel) {
if(channel == null) {
return;
}
if(channel.getUser() != null && !channel.getUser().equals(EnderIO.proxy.getClientPlayer().getGameProfile().getName())) {
return;
}
super.addChannel(channel);
}
}
@@ -0,0 +1,24 @@
package crazypants.enderio.machine.transceiver;
import net.minecraft.entity.player.EntityPlayerMP;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent;
import crazypants.enderio.network.PacketHandler;
public class ConnectionHandler {
@SubscribeEvent
public void onPlayerLoggon(PlayerLoggedInEvent evt) {
PacketHandler.INSTANCE.sendTo(new PacketChannelList(ServerChannelRegister.instance), (EntityPlayerMP) evt.player);
}
@SubscribeEvent
public void onDisconnectedFromServer(ClientDisconnectionFromServerEvent evt) {
ClientChannelRegister.instance.reset();
}
}
@@ -0,0 +1,57 @@
package crazypants.enderio.machine.transceiver;
import net.minecraft.nbt.NBTTagCompound;
import io.netty.buffer.ByteBuf;
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 cpw.mods.fml.relauncher.Side;
import crazypants.enderio.machine.hypercube.PacketChannelList;
import crazypants.enderio.network.NetworkUtil;
import crazypants.enderio.network.PacketHandler;
public class PacketAddRemoveChannel implements IMessage, IMessageHandler<PacketAddRemoveChannel, IMessage> {
private boolean isAdd;
private Channel channel;
public PacketAddRemoveChannel() {
}
public PacketAddRemoveChannel(Channel channel, boolean isAdd) {
this.channel = channel;
this.isAdd = isAdd;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeBoolean(isAdd);
NBTTagCompound nbt = new NBTTagCompound();
channel.writeToNBT(nbt);
NetworkUtil.writeNBTTagCompound(nbt, buf);
}
@Override
public void fromBytes(ByteBuf buf) {
isAdd = buf.readBoolean();
NBTTagCompound tag = NetworkUtil.readNBTTagCompound(buf);
channel = Channel.readFromNBT(tag);
}
@Override
public IMessage onMessage(PacketAddRemoveChannel message, MessageContext ctx) {
ChannelRegister register = ctx.side == Side.CLIENT ? ClientChannelRegister.instance : ServerChannelRegister.instance;
if(message.isAdd) {
register.addChannel(message.channel);
} else {
register.removeChannel(message.channel);
}
if(ctx.side == Side.SERVER) {
PacketHandler.INSTANCE.sendToAll(new PacketAddRemoveChannel(message.channel, message.isAdd));
}
return null;
}
}
@@ -0,0 +1,67 @@
package crazypants.enderio.machine.transceiver;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import io.netty.buffer.ByteBuf;
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.network.NetworkUtil;
public class PacketChannelList implements IMessage, IMessageHandler<PacketChannelList, IMessage> {
private List<Channel> channels;
public PacketChannelList() {
}
public PacketChannelList(ChannelRegister register) {
channels = new ArrayList<Channel>();
for (ChannelType type : ChannelType.values()) {
for (Channel channel : register.getChannelsForType(type)) {
channels.add(channel);
}
}
}
@Override
public void toBytes(ByteBuf buf) {
NBTTagList tagList = new NBTTagList();
for(Channel chan : channels) {
NBTTagCompound tag = new NBTTagCompound();
chan.writeToNBT(tag);
tagList.appendTag(tag);
}
NBTTagCompound root = new NBTTagCompound();
root.setTag("chanList", tagList);
NetworkUtil.writeNBTTagCompound(root, buf);
}
@Override
public void fromBytes(ByteBuf buf) {
NBTTagCompound root = NetworkUtil.readNBTTagCompound(buf);
NBTTagList tagList = (NBTTagList)root.getTag("chanList");
channels = new ArrayList<Channel>();
for(int i=0; i < tagList.tagCount();i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
Channel chan = Channel.readFromNBT(tag);
if(chan != null) {
channels.add(chan);
}
}
}
@Override
public IMessage onMessage(PacketChannelList message, MessageContext ctx) {
for(Channel channel : message.channels) {
ClientChannelRegister.instance.addChannel(channel);
}
return null;
}
}
@@ -0,0 +1,78 @@
package crazypants.enderio.machine.transceiver;
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 net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import io.netty.buffer.ByteBuf;
import crazypants.enderio.EnderIO;
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
import crazypants.enderio.machine.PacketCurrentTask;
import crazypants.enderio.machine.PoweredTask;
import crazypants.enderio.network.MessageTileEntity;
import crazypants.enderio.network.NetworkUtil;
public class PacketSendRecieveChannel extends MessageTileEntity<TileTransceiver> implements IMessageHandler<PacketSendRecieveChannel, IMessage> {
private boolean isSend;
private boolean isAdd;
private Channel channel;
public PacketSendRecieveChannel() {
}
public PacketSendRecieveChannel(TileTransceiver te, boolean isSend, boolean isAdd, Channel channel) {
super(te);
this.isSend = isSend;
this.isAdd = isAdd;
this.channel = channel;
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeBoolean(isSend);
buf.writeBoolean(isAdd);
NBTTagCompound tag = new NBTTagCompound();
channel.writeToNBT(tag);
NetworkUtil.writeNBTTagCompound(tag, buf);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
isSend = buf.readBoolean();
isAdd = buf.readBoolean();
NBTTagCompound tag = NetworkUtil.readNBTTagCompound(buf);
channel = Channel.readFromNBT(tag);
}
@Override
public IMessage onMessage(PacketSendRecieveChannel message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
TileTransceiver tile = message.getTileEntity(player.worldObj);
Channel channel = message.channel;
boolean isSend = message.isSend;
boolean isAdd = message.isAdd;
if (tile != null && channel != null) {
if(isSend) {
if(isAdd) {
tile.addSendChanel(channel);
} else {
tile.removeSendChanel(channel);
}
} else {
if(isAdd) {
tile.addRecieveChanel(channel);
} else {
tile.removeRecieveChanel(channel);
}
}
}
return null;
}
}
@@ -0,0 +1,82 @@
package crazypants.enderio.machine.transceiver;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.List;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import crazypants.enderio.Log;
import net.minecraftforge.common.DimensionManager;
public class ServerChannelRegister extends ChannelRegister {
public static ServerChannelRegister instance = new ServerChannelRegister();
public static void load() {
instance.reset();
File dataFile = getDataFile();
if(!dataFile.exists()) {
return;
}
try {
JsonReader reader = new JsonReader(new FileReader(getDataFile()));
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
reader.nextName();
String name = reader.nextString();
String key = reader.nextName();
String user = null;
if("user".equals(key)) {
user = reader.nextString();
reader.nextName();
}
int oridinal = reader.nextInt();
Channel chan = new Channel(name, user, ChannelType.values()[oridinal]);
instance.addChannel(chan);
reader.endObject();
}
reader.endArray();
reader.close();
} catch (Exception e) {
Log.error("Could not read Dimensional trasciever channels from " + getDataFile().getAbsolutePath() + " : " + e);
}
}
public static void store() {
try {
File dataFile = getDataFile();
dataFile.getParentFile().mkdirs();
JsonWriter writer = new JsonWriter(new FileWriter(dataFile, false));
writer.setIndent(" ");
writer.beginArray();
for (List<Channel> chanList : instance.channels.values()) {
for (Channel chan : chanList) {
writer.beginObject();
writer.name("name").value(chan.getName());
if(chan.getUser() != null) {
writer.name("user").value(chan.getUser());
}
writer.name("type").value(chan.getType().ordinal());
writer.endObject();
}
}
writer.endArray();
writer.close();
} catch (Exception e) {
Log.error("Could not write Dimensional trasciever channels to " + getDataFile().getAbsolutePath() + " : " + e);
}
}
private static File getDataFile() {
return new File(DimensionManager.getCurrentSaveRootDirectory(), "enderio/dimensionalTransceiver.json");
}
}
@@ -0,0 +1,139 @@
package crazypants.enderio.machine.transceiver;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
import crazypants.enderio.machine.SlotDefinition;
public class TileTransceiver extends AbstractPoweredTaskEntity {
private final EnumMap<ChannelType, List<Channel>> sendChannels = new EnumMap<ChannelType, List<Channel>>(ChannelType.class);
private final EnumMap<ChannelType, List<Channel>> recieveChannels = new EnumMap<ChannelType, List<Channel>>(ChannelType.class);
private boolean channelsDirty = false;
public TileTransceiver() {
super(new SlotDefinition(0, 0, 0));
for (ChannelType type : ChannelType.values()) {
sendChannels.put(type, new ArrayList<Channel>());
recieveChannels.put(type, new ArrayList<Channel>());
}
}
@Override
public String getMachineName() {
return ModObject.blockTransceiver.unlocalisedName;
}
@Override
protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) {
return true;
}
public List<Channel> getSendChannels(ChannelType type) {
return sendChannels.get(type);
}
public List<Channel> getRecieveChannels(ChannelType type) {
return recieveChannels.get(type);
}
public void addSendChanel(Channel channel) {
addChannel(channel, sendChannels);
}
public void addRecieveChanel(Channel channel) {
addChannel(channel, recieveChannels);
}
public void removeSendChanel(Channel channel) {
removeChannel(channel, sendChannels);
}
public void removeRecieveChanel(Channel channel) {
removeChannel(channel, recieveChannels);
}
private void addChannel(Channel channel, EnumMap<ChannelType, List<Channel>> channels) {
if(channel == null) {
return;
}
List<Channel> chans = channels.get(channel.getType());
if(!chans.contains(channel)) {
chans.add(channel);
channelsDirty = true;
}
}
private void removeChannel(Channel channel, EnumMap<ChannelType, List<Channel>> channels) {
if(channel == null) {
return;
}
List<Channel> chans = channels.get(channel.getType());
chans.remove(channel);
channelsDirty = true;
}
@Override
public void readCustomNBT(NBTTagCompound nbtRoot) {
super.readCustomNBT(nbtRoot);
readChannels(nbtRoot, sendChannels, "sendChannels");
readChannels(nbtRoot, recieveChannels, "recieveChannels");
}
private void readChannels(NBTTagCompound nbtRoot, EnumMap<ChannelType, List<Channel>> readInto, String key) {
readInto.clear();
for (ChannelType type : ChannelType.values()) {
readInto.put(type, new ArrayList<Channel>());
}
if(!nbtRoot.hasKey(key)) {
return;
}
NBTTagList tags = (NBTTagList)nbtRoot.getTag(key);
for(int i=0;i<tags.tagCount();i++) {
NBTTagCompound chanelTag = tags.getCompoundTagAt(i);
Channel channel = Channel.readFromNBT(chanelTag);
if(channel != null) {
readInto.get(channel.getType()).add(channel);
}
}
}
@Override
public void writeCustomNBT(NBTTagCompound nbtRoot) {
super.writeCustomNBT(nbtRoot);
NBTTagList channelTags = createTagList(sendChannels);
nbtRoot.setTag("sendChannels", channelTags);
channelTags = createTagList(recieveChannels);
nbtRoot.setTag("recieveChannels", channelTags);
}
private NBTTagList createTagList(EnumMap<ChannelType, List<Channel>> chans) {
NBTTagList res = new NBTTagList();
for(List<Channel> chanList : chans.values()) {
for(Channel channel : chanList) {
NBTTagCompound chanTag = new NBTTagCompound();
channel.writeToNBT(chanTag);
res.appendTag(chanTag);
}
}
return res;
}
}
@@ -0,0 +1,262 @@
package crazypants.enderio.machine.transceiver.gui;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import crazypants.enderio.gui.ITabPanel;
import crazypants.enderio.gui.IconButtonEIO;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.gui.ToggleButtonEIO;
import crazypants.enderio.machine.transceiver.Channel;
import crazypants.enderio.machine.transceiver.ChannelType;
import crazypants.enderio.machine.transceiver.ClientChannelRegister;
import crazypants.enderio.machine.transceiver.PacketAddRemoveChannel;
import crazypants.enderio.machine.transceiver.PacketSendRecieveChannel;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.enderio.network.PacketHandler;
import crazypants.gui.GuiScrollableList;
import crazypants.gui.ListSelectionListener;
import crazypants.render.ColorUtil;
import crazypants.util.Lang;
public class AbstractChannelTab implements ITabPanel {
protected static final int ADD_BUTTON_ID = 3;
protected static final int PRIVATE_BUTTON_ID = 4;
private static final int DELETE_CHANNEL_BUTTON_ID = 5;
private static final int SEND_BUTTON_ID = 6;
private static final int RECIEVE_BUTTON_ID = 7;
ChannelType type;
GuiTransceiver parent;
IconButtonEIO addButton;
ToggleButtonEIO privateButton;
GuiTextField newChannelTF;
GuiChannelList channelList;
GuiChannelList sendChannels;
GuiChannelList recieveChannels;
IconButtonEIO deleteChannelB;
IconButtonEIO sendB;
IconButtonEIO recieveB;
ListSelectionListener<Channel> selectionListener;
TileTransceiver transceiver;
public AbstractChannelTab(GuiTransceiver guiTransceiver, ChannelType type) {
parent = guiTransceiver;
this.type = type;
transceiver = guiTransceiver.transceiver;
newChannelTF = new GuiTextField(parent.getFontRenderer(), 7, 12, 103, 16);
addButton = new IconButtonEIO(parent, ADD_BUTTON_ID, 137, 12, IconEIO.PLUS);
addButton.setToolTip(Lang.localize("gui.trans.addChannel"));
addButton.enabled = false;
privateButton = new ToggleButtonEIO(parent, PRIVATE_BUTTON_ID, 118, 12, IconEIO.PUBLIC, IconEIO.PRIVATE);
privateButton.setSelectedToolTip(Lang.localize("gui.trans.privateChannel"));
privateButton.setUnselectedToolTip(Lang.localize("gui.trans.publicChannel"));
int w = 104;
int h = 90;
int x = 7;
int y = 48;
channelList = new GuiChannelList(parent, w, h, x, y);
channelList.setChannels(ClientChannelRegister.instance.getChannelsForType(type));
channelList.setShowSelectionBox(true);
channelList.setScrollButtonIds(100, 101);
deleteChannelB = new IconButtonEIO(parent, DELETE_CHANNEL_BUTTON_ID, x + w - 20, y + h + 4, IconEIO.MINUS);
deleteChannelB.setToolTip(Lang.localize("gui.trans.deleteChannel"));
x += w + 32;
h = 35;
sendChannels = new GuiChannelList(parent, w, h, x, y);
sendChannels.setChannels(transceiver.getSendChannels(type));
sendChannels.setShowSelectionBox(true);
sendChannels.setScrollButtonIds(200, 201);
sendB = new IconButtonEIO(parent,SEND_BUTTON_ID,x -24, y + h/2 - 9, IconEIO.ARROWS);
y += h + 20;
recieveChannels = new GuiChannelList(parent, w, h, x, y);
recieveChannels.setChannels(transceiver.getRecieveChannels(type));
recieveChannels.setShowSelectionBox(true);
recieveChannels.setScrollButtonIds(300, 301);
recieveB = new IconButtonEIO(parent,RECIEVE_BUTTON_ID,x -24, y + h/2 - 9, IconEIO.ARROWS);
selectionListener = new ListSelectionListener<Channel>() {
@Override
public void selectionChanged(GuiScrollableList<Channel> list, int selectedIndex) {
if(selectedIndex < 0) {
return;
}
if(list != channelList) {
channelList.setSelection(-1);
}
if(list != sendChannels) {
sendChannels.setSelection(-1);
}
if(list != recieveChannels) {
recieveChannels.setSelection(-1);
}
}
};
channelList.addSelectionListener(selectionListener);
sendChannels.addSelectionListener(selectionListener);
recieveChannels.addSelectionListener(selectionListener);
}
@Override
public void onGuiInit(int x, int y, int width, int height) {
addButton.onGuiInit();
privateButton.onGuiInit();
deleteChannelB.onGuiInit();
sendB.onGuiInit();
recieveB.onGuiInit();
y = parent.getGuiTop() + 12;
x = parent.getGuiLeft() + 8;
newChannelTF.xPosition = x;
newChannelTF.yPosition = y;
newChannelTF.setCanLoseFocus(false);
newChannelTF.setMaxStringLength(32);
newChannelTF.setFocused(true);
channelList.onGuiInit(parent);
sendChannels.onGuiInit(parent);
recieveChannels.onGuiInit(parent);
}
@Override
public void deactivate() {
addButton.detach();
privateButton.detach();
deleteChannelB.detach();
sendB.detach();
recieveB.detach();
}
@Override
public void keyTyped(char par1, int par2) {
newChannelTF.textboxKeyTyped(par1, par2);
addButton.enabled = newChannelTF.getText().trim().length() > 0;
}
@Override
public IconEIO getIcon() {
switch (type) {
case FLUID:
return IconEIO.WRENCH_OVERLAY_FLUID;
case ITEM:
return IconEIO.WRENCH_OVERLAY_ITEM;
case POWER:
default:
return IconEIO.WRENCH_OVERLAY_POWER;
}
}
@Override
public void updateScreen() {
newChannelTF.updateCursorCounter();
}
@Override
public void render(float partialTick, int mouseX, int mouseY) {
newChannelTF.drawTextBox();
channelList.drawScreen(mouseX, mouseY, partialTick);
sendChannels.drawScreen(mouseX, mouseY, partialTick);
recieveChannels.drawScreen(mouseX, mouseY, partialTick);
int left = parent.getGuiLeft();
int top = parent.getGuiTop();
int x = left + 59;
int y = top + 36;
parent.drawCenteredString(parent.getFontRenderer(), "Available", x, y, ColorUtil.getRGB(Color.white));
x = left + 199;
parent.drawCenteredString(parent.getFontRenderer(), "Send", x, y, ColorUtil.getRGB(Color.white));
y += 56;
parent.drawCenteredString(parent.getFontRenderer(), "Recieve", x, y, ColorUtil.getRGB(Color.white));
}
@Override
public void actionPerformed(GuiButton guiButton) {
if(guiButton.id == ADD_BUTTON_ID) {
addChannelPressed();
} else if(guiButton.id == DELETE_CHANNEL_BUTTON_ID) {
deleteChannelPressed();
} else if(guiButton.id == SEND_BUTTON_ID) {
sendTogglePressed();
} else if(guiButton.id == RECIEVE_BUTTON_ID) {
receiveTogglePressed();
}
}
private void receiveTogglePressed() {
Channel c = channelList.getSelectedElement();
if(c != null && !transceiver.getRecieveChannels(type).contains(c)) {
transceiver.addRecieveChanel(c);
PacketHandler.INSTANCE.sendToServer(new PacketSendRecieveChannel(transceiver, false, true, c));
} else {
c = recieveChannels.getSelectedElement();
if(c != null) {
transceiver.removeRecieveChanel(c);
PacketHandler.INSTANCE.sendToServer(new PacketSendRecieveChannel(transceiver, false, false, c));
}
}
}
private void sendTogglePressed() {
Channel c = channelList.getSelectedElement();
if(c != null && !transceiver.getSendChannels(type).contains(c)) {
transceiver.addSendChanel(c);
PacketHandler.INSTANCE.sendToServer(new PacketSendRecieveChannel(transceiver, true, true, c));
} else {
c = sendChannels.getSelectedElement();
if(c != null) {
transceiver.removeSendChanel(c);
PacketHandler.INSTANCE.sendToServer(new PacketSendRecieveChannel(transceiver, true, false, c));
}
}
}
private void deleteChannelPressed() {
Channel c = channelList.getSelectedElement();
if(c != null) {
ClientChannelRegister.instance.removeChannel(c);
PacketHandler.INSTANCE.sendToServer(new PacketAddRemoveChannel(c, false));
}
}
private void addChannelPressed() {
Channel c;
if(privateButton.isSelected()) {
c = new Channel(newChannelTF.getText(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName(), type);
} else {
c = new Channel(newChannelTF.getText(), null, type);
}
ClientChannelRegister.instance.addChannel(c);
PacketHandler.INSTANCE.sendToServer(new PacketAddRemoveChannel(c, true));
channelList.setSelection(c);
newChannelTF.setText("");
}
@Override
public void mouseClicked(int x, int y, int par3) {
newChannelTF.mouseClicked(x, y, par3);
}
}
@@ -0,0 +1,40 @@
package crazypants.enderio.machine.transceiver.gui;
import java.awt.Point;
import java.util.Map.Entry;
import java.util.Set;
import crazypants.enderio.machine.AbstractMachineContainer;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
public class ContainerTransceiver extends AbstractMachineContainer {
private static final Point INV_OFFSET = new Point(47, 84);
public ContainerTransceiver(InventoryPlayer inventory, TileTransceiver te) {
super(inventory, te);
}
@Override
protected void addMachineSlots(InventoryPlayer playerInv) {
}
public void setPlayerInventoryVisible(boolean visible) {
Set<Entry<Slot, Point>> entries = playerSlotLocations.entrySet();
for(Entry<Slot, Point> entry : entries) {
entry.getKey().xDisplayPosition = visible ? entry.getValue().x : -3000;
entry.getKey().yDisplayPosition = visible ? entry.getValue().y : -3000;
}
}
@Override
public Point getPlayerInventoryOffset() {
//return INV_OFFSET;
return new Point(47, 84);
}
}
@@ -0,0 +1,59 @@
package crazypants.enderio.machine.transceiver.gui;
import java.awt.Point;
import net.minecraft.client.gui.GuiButton;
import crazypants.enderio.gui.ITabPanel;
import crazypants.enderio.gui.IconEIO;
import crazypants.render.RenderUtil;
public class GeneralTab implements ITabPanel {
ContainerTransceiver container;
GuiTransceiver parent;
public GeneralTab(GuiTransceiver guiTransceiver) {
parent = guiTransceiver;
container = parent.container;
}
@Override
public void onGuiInit(int x, int y, int width, int height) {
container.setPlayerInventoryVisible(true);
}
@Override
public void deactivate() {
container.setPlayerInventoryVisible(false);
}
@Override
public IconEIO getIcon() {
return IconEIO.IO_CONFIG_UP;
}
@Override
public void render(float par1, int par2, int par3) {
RenderUtil.bindTexture("enderio:textures/gui/transceiver.png");
Point invRoot = container.getPlayerInventoryOffset();
parent.drawTexturedModalRect(parent.getGuiLeft() + invRoot.x - 1, parent.getGuiTop() + invRoot.y - 1, 24, 180, 162, 76);
}
@Override
public void actionPerformed(GuiButton guiButton) {
}
@Override
public void mouseClicked(int x, int y, int par3) {
}
@Override
public void updateScreen() {
}
@Override
public void keyTyped(char par1, int par2) {
}
}
@@ -0,0 +1,82 @@
package crazypants.enderio.machine.transceiver.gui;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.event.terraingen.BiomeEvent.GetWaterColor;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.machine.hypercube.GuiHyperCube;
import crazypants.enderio.machine.transceiver.Channel;
import crazypants.gui.GuiScrollableList;
import crazypants.render.ColorUtil;
public class GuiChannelList extends GuiScrollableList<Channel> {
private List<Channel> channels = new ArrayList<Channel>();
// private Channel activeChannel;
private final GuiTransceiver parent;
public GuiChannelList(GuiTransceiver parent, int width, int height, int originX, int originY) {
super(width, height, originX, originY, Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 4);
this.parent = parent;
}
void setChannels(List<Channel> val) {
if(val == null) {
channels = Collections.emptyList();
}
channels = val;
}
// void setActiveChannel(Channel channel) {
// activeChannel = channel;
// }
@Override
public int getNumElements() {
return channels.size();
}
@Override
public Channel getElementAt(int index) {
if(index < 0 || index >= channels.size()) {
return null;
}
return channels.get(index);
}
@Override
protected boolean elementClicked(int i, boolean flag) {
if(getElementAt(i) == null) {
return false;
} else {
return true;
}
}
@Override
protected void drawElement(int index, int xPosition, int yPosition, int rowHeight, Tessellator tessellator) {
if(index < 0 || index >= channels.size()) {
return;
}
Channel c = getElementAt(index);
if(c == null) {
return;
}
int col = ColorUtil.getRGB(Color.white);
// if(c.equals(activeChannel)) {
// col = ColorUtil.getRGB(Color.cyan);
// }
parent.drawString(parent.getFontRenderer(), c.getName(), xPosition + margin, yPosition + margin / 2, col);
if(!c.isPublic()) {
IconEIO.PRIVATE.renderIcon(xPosition + width - 18, yPosition - 3, 16, 15, 0, true);
}
}
}
@@ -0,0 +1,208 @@
package crazypants.enderio.machine.transceiver.gui;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.gui.IGuiOverlay;
import crazypants.enderio.gui.ITabPanel;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.machine.GuiMachineBase;
import crazypants.enderio.machine.generator.stirling.StirlingGeneratorContainer;
import crazypants.enderio.machine.generator.stirling.TileEntityStirlingGenerator;
import crazypants.enderio.machine.power.PowerDisplayUtil;
import crazypants.enderio.machine.transceiver.ChannelType;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.render.ColorUtil;
import crazypants.render.RenderUtil;
import crazypants.util.Lang;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.InventoryPlayer;
public class GuiTransceiver extends GuiMachineBase {
private static final int TAB_HEIGHT = 24;
private TileTransceiver entity;
private int activeTab = 0;
private final List<ITabPanel> tabs = new ArrayList<ITabPanel>();
private int tabYOffset = 4;
ContainerTransceiver container;
TileTransceiver transceiver;
public GuiTransceiver(InventoryPlayer par1InventoryPlayer, TileTransceiver te) {
super(te, new ContainerTransceiver(par1InventoryPlayer, te));
this.entity = te;
container = (ContainerTransceiver)inventorySlots;
transceiver = te;
tabs.add(new GeneralTab(this));
tabs.add(new AbstractChannelTab(this, ChannelType.POWER));
tabs.add(new AbstractChannelTab(this, ChannelType.ITEM));
tabs.add(new AbstractChannelTab(this, ChannelType.FLUID));
}
@Override
protected boolean showRecipeButton() {
return false;
}
@Override
public int getXSize() {
return 256;
}
@Override
public void updateScreen() {
for (int i = 0; i < tabs.size(); i++) {
if(i == activeTab) {
tabs.get(i).updateScreen();
return;
}
}
}
@Override
protected void keyTyped(char par1, int par2) {
if(par2 == 1) {
for (IGuiOverlay overlay : overlays) {
if(overlay.isVisible()) {
overlay.setVisible(false);
return;
}
}
this.mc.thePlayer.closeScreen();
}
for (int i = 0; i < tabs.size(); i++) {
if(i == activeTab) {
tabs.get(i).keyTyped(par1, par2);
return;
}
}
}
@Override
public void initGui() {
super.initGui();
for (int i = 0; i < tabs.size(); i++) {
if(i == activeTab) {
tabs.get(i).onGuiInit(guiLeft + 10, guiTop, xSize - 20, ySize - 20);
} else {
tabs.get(i).deactivate();
}
}
configB.visible = activeTab == 0;
redstoneButton.visible = activeTab == 0;
}
@Override
protected boolean renderPowerBar() {
return activeTab == 0;
}
@Override
protected int getPowerX() {
return super.getPowerX() - 4;
}
@Override
protected int getPowerHeight() {
return 58;
}
@Override
protected int getPowerY() {
return super.getPowerY();
}
@Override
protected int getPowerV() {
return 196;
}
@Override
protected int getPowerU() {
return 246;
}
@Override
protected void mouseClicked(int x, int y, int par3) {
super.mouseClicked(x, y, par3);
int tabLeftX = xSize;
int tabRightX = tabLeftX + 22;
int minY = tabYOffset;
int maxY = minY + (tabs.size() * TAB_HEIGHT);
x = (x - guiLeft);
y = (y - guiTop);
if(x > tabLeftX && x < tabRightX + 24) {
if(y > minY && y < maxY) {
activeTab = (y - minY) / 24;
initGui();
return;
}
}
tabs.get(activeTab).mouseClicked(x, y, par3);
}
@Override
protected void actionPerformed(GuiButton guiButton) {
super.actionPerformed(guiButton);
tabs.get(activeTab).actionPerformed(guiButton);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int sx = (width - xSize) / 2;
int sy = (height - ySize) / 2;
int tabX = sx + xSize - 3;
Tessellator tes = Tessellator.instance;
tes.startDrawingQuads();
for (int i = 0; i < tabs.size(); i++) {
if(i != activeTab) {
RenderUtil.bindTexture(IconEIO.TEXTURE);
IconEIO.INACTIVE_TAB.renderIcon(tabX, sy + tabYOffset + (i * 24));
IconEIO icon = tabs.get(i).getIcon();
icon.renderIcon(tabX + 4, sy + tabYOffset + (i * TAB_HEIGHT) + 7, 10, 10, 0, false);
}
}
tes.draw();
RenderUtil.bindTexture("enderio:textures/gui/transceiver.png");
drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize);
if(renderPowerBar()) {
drawTexturedModalRect(getGuiLeft() + getPowerX() - 1, getGuiTop() + getPowerY() - 1, 233, 196, 12, getPowerHeight() + 2);
}
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
RenderUtil.bindTexture(IconEIO.TEXTURE);
tes.startDrawingQuads();
IconEIO.ACTIVE_TAB.renderIcon(tabX, sy + tabYOffset + (activeTab * TAB_HEIGHT));
if(tabs.size() > 0) {
IconEIO icon = tabs.get(activeTab).getIcon();
icon.renderIcon(tabX + 4, sy + tabYOffset + (activeTab * TAB_HEIGHT) + 7, 10, 10, 0, false);
tes.draw();
tabs.get(activeTab).render(par1, par2, par3);
} else {
tes.draw();
}
}
}
@@ -0,0 +1,11 @@
package crazypants.enderio.machine.transceiver.render;
import crazypants.enderio.machine.transceiver.TileTransceiver;
public interface IModel {
void render(TileTransceiver cube, double x, double y, double z);
void render();
}
@@ -0,0 +1,42 @@
package crazypants.enderio.machine.transceiver.render;
import net.minecraft.client.model.ModelBase;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.render.RenderUtil;
public class TransceiverModel extends ModelBase implements IModel {
public static final float SCALE = 1 / 16f;
private static final String TEXTURE = "enderio:models/transceiver.png";
private static final String MODEL = "enderio:models/transceiver.obj";
private IModelCustom model;
public TransceiverModel() {
model = AdvancedModelLoader.loadModel(new ResourceLocation(MODEL));
}
@Override
public void render() {
GL11.glPushMatrix();
GL11.glScalef(SCALE, SCALE, SCALE);
RenderUtil.bindTexture(TEXTURE);
model.renderAll();
GL11.glPopMatrix();
}
@Override
public void render(TileTransceiver cube, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
render();
GL11.glPopMatrix();
}
}
@@ -0,0 +1,251 @@
package crazypants.enderio.machine.transceiver.render;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.render.RenderUtil;
public class TransceiverModelAlt extends ModelBase implements IModel {
private static final String TEXTURE = "enderio:models/transceiverAlt.png";
ModelRenderer Shape1;
ModelRenderer Shape2;
ModelRenderer Shape3;
ModelRenderer Shape4;
ModelRenderer Shape5;
ModelRenderer Shape6;
ModelRenderer Shape7;
ModelRenderer Shape8;
ModelRenderer Shape9;
ModelRenderer Shape10;
ModelRenderer Shape11;
ModelRenderer Shape12;
ModelRenderer Shape13;
ModelRenderer Shape14;
ModelRenderer Shape15;
ModelRenderer Shape16;
ModelRenderer Shape17;
ModelRenderer Shape18;
ModelRenderer Shape19;
ModelRenderer Shape20;
ModelRenderer Shape21;
ModelRenderer Shape22;
ModelRenderer Shape23;
ModelRenderer Shape24;
ModelRenderer Shape25;
public TransceiverModelAlt() {
textureWidth = 32;
textureHeight = 32;
Shape1 = new ModelRenderer(this, 0, 7);
Shape1.addBox(0F, 0F, 0F, 6, 1, 6);
Shape1.setRotationPoint(-3F, 24F, -8F);
Shape1.setTextureSize(32, 32);
Shape1.mirror = true;
setRotation(Shape1, 1.570796F, 0F, 0F);
Shape2 = new ModelRenderer(this, 0, 0);
Shape2.addBox(0F, 0F, 0F, 6, 1, 5);
Shape2.setRotationPoint(7F, 23F, 3F);
Shape2.setTextureSize(32, 32);
Shape2.mirror = true;
setRotation(Shape2, 1.570796F, 1.570796F, 0F);
Shape3 = new ModelRenderer(this, 0, 0);
Shape3.addBox(0F, 0F, 0F, 6, 1, 5);
Shape3.setRotationPoint(-3F, 23F, 7F);
Shape3.setTextureSize(32, 32);
Shape3.mirror = true;
setRotation(Shape3, 1.570796F, 0F, 0F);
Shape4 = new ModelRenderer(this, 0, 7);
Shape4.addBox(0F, 0F, 0F, 6, 1, 6);
Shape4.setRotationPoint(-8F, 24F, 3F);
Shape4.setTextureSize(32, 32);
Shape4.mirror = true;
setRotation(Shape4, 1.570796F, 1.570796F, 0F);
Shape5 = new ModelRenderer(this, 0, 0);
Shape5.addBox(0F, 0F, 0F, 6, 1, 5);
Shape5.setRotationPoint(-3F, 14F, -8F);
Shape5.setTextureSize(32, 32);
Shape5.mirror = true;
setRotation(Shape5, 1.570796F, 0F, 0F);
Shape6 = new ModelRenderer(this, 0, 7);
Shape6.addBox(0F, 0F, 0F, 6, 1, 6);
Shape6.setRotationPoint(-7F, 13F, 8F);
Shape6.setTextureSize(32, 32);
Shape6.mirror = true;
//setRotation(Shape6, 1.570796F, 1.570796F, 1.570796F);
setRotation(Shape6, 0F, 1.570796F, 1.570796F);
Shape7 = new ModelRenderer(this, 0, 7);
Shape7.addBox(0F, 0F, 0F, 6, 1, 6);
Shape7.setRotationPoint(-8F, 13F, -8F);
Shape7.setTextureSize(32, 32);
Shape7.mirror = true;
setRotation(Shape7, 1.570796F, 0F, 1.570796F);
Shape8 = new ModelRenderer(this, 0, 0);
Shape8.addBox(0F, 0F, 0F, 6, 1, 5);
Shape8.setRotationPoint(-8F, 14F, 3F);
Shape8.setTextureSize(32, 32);
Shape8.mirror = true;
setRotation(Shape8, 1.570796F, 1.570796F, 0F);
Shape9 = new ModelRenderer(this, 0, 7);
Shape9.addBox(0F, 0F, 0F, 6, 1, 6);
Shape9.setRotationPoint(-3F, 23F, 2F);
Shape9.setTextureSize(32, 32);
Shape9.mirror = true;
setRotation(Shape9, 0F, 0F, 0F);
Shape10 = new ModelRenderer(this, 0, 7);
Shape10.addBox(0F, 0F, 0F, 6, 1, 6);
Shape10.setRotationPoint(2F, 23F, 3F);
Shape10.setTextureSize(32, 32);
Shape10.mirror = true;
setRotation(Shape10, 0F, 1.570796F, 0F);
Shape11 = new ModelRenderer(this, 0, 7);
Shape11.addBox(0F, 0F, 0F, 6, 1, 6);
Shape11.setRotationPoint(-3F, 23F, -8F);
Shape11.setTextureSize(32, 32);
Shape11.mirror = true;
setRotation(Shape11, 0F, 0F, 0F);
Shape12 = new ModelRenderer(this, 0, 7);
Shape12.addBox(0F, 0F, 0F, 6, 1, 6);
Shape12.setRotationPoint(-8F, 23F, 3F);
Shape12.setTextureSize(32, 32);
Shape12.mirror = true;
setRotation(Shape12, 0F, 1.570796F, 0F);
Shape13 = new ModelRenderer(this, 0, 7);
Shape13.addBox(0F, 0F, 0F, 6, 1, 6);
Shape13.setRotationPoint(-8F, 8F, 3F);
Shape13.setTextureSize(32, 32);
Shape13.mirror = true;
setRotation(Shape13, 0F, 1.570796F, 0F);
Shape14 = new ModelRenderer(this, 0, 7);
Shape14.addBox(0F, 0F, 0F, 6, 1, 6);
Shape14.setRotationPoint(-3F, 8F, 2F);
Shape14.setTextureSize(32, 32);
Shape14.mirror = true;
setRotation(Shape14, 0F, 0F, 0F);
Shape15 = new ModelRenderer(this, 0, 7);
Shape15.addBox(0F, 0F, 0F, 6, 1, 6);
Shape15.setRotationPoint(-3F, 8F, -8F);
Shape15.setTextureSize(32, 32);
Shape15.mirror = true;
setRotation(Shape15, 0F, 0F, 0F);
Shape16 = new ModelRenderer(this, 0, 7);
Shape16.addBox(0F, 0F, 0F, 6, 1, 6);
Shape16.setRotationPoint(2F, 8F, 3F);
Shape16.setTextureSize(32, 32);
Shape16.mirror = true;
setRotation(Shape16, 0F, 1.570796F, 0F);
Shape17 = new ModelRenderer(this, 0, 7);
Shape17.addBox(0F, 0F, 0F, 6, 1, 6);
Shape17.setRotationPoint(7F, 14F, 3F);
Shape17.setTextureSize(32, 32);
Shape17.mirror = true;
setRotation(Shape17, 1.570796F, 1.570796F, 0F);
Shape18 = new ModelRenderer(this, 0, 7);
Shape18.addBox(0F, 0F, 0F, 6, 1, 6);
Shape18.setRotationPoint(-7F, 13F, -2F);
Shape18.setTextureSize(32, 32);
Shape18.mirror = true;
setRotation(Shape18, 0F, 1.570796F, 1.570796F);
Shape19 = new ModelRenderer(this, 0, 7);
Shape19.addBox(0F, 0F, 0F, 6, 1, 6);
Shape19.setRotationPoint(8F, 13F, -2F);
Shape19.setTextureSize(32, 32);
Shape19.mirror = true;
setRotation(Shape19, 0F, 1.570796F, 1.570796F);
Shape20 = new ModelRenderer(this, 0, 7);
Shape20.addBox(0F, 0F, 0F, 6, 1, 6);
Shape20.setRotationPoint(8F, 13F, 8F);
Shape20.setTextureSize(32, 32);
Shape20.mirror = true;
setRotation(Shape20, 0F, 1.570796F, 1.570796F);
Shape21 = new ModelRenderer(this, 0, 7);
Shape21.addBox(0F, 0F, 0F, 6, 1, 6);
Shape21.setRotationPoint(-3F, 14F, 7F);
Shape21.setTextureSize(32, 32);
Shape21.mirror = true;
setRotation(Shape21, 1.570796F, 0F, 0F);
Shape22 = new ModelRenderer(this, 0, 7);
Shape22.addBox(0F, 0F, 0F, 6, 1, 6);
Shape22.setRotationPoint(2F, 13F, -8F);
Shape22.setTextureSize(32, 32);
Shape22.mirror = true;
setRotation(Shape22, 1.570796F, 0F, 1.570796F);
Shape23 = new ModelRenderer(this, 0, 0);
Shape23.addBox(0F, 0F, 0F, 6, 1, 5);
Shape23.setRotationPoint(-8F, 13F, 7F);
Shape23.setTextureSize(32, 32);
Shape23.mirror = true;
setRotation(Shape23, 1.570796F, 0F, 1.570796F);
Shape24 = new ModelRenderer(this, 0, 7);
Shape24.addBox(0F, 0F, 0F, 6, 1, 6);
Shape24.setRotationPoint(2F, 13F, 7F);
Shape24.setTextureSize(32, 32);
Shape24.mirror = true;
setRotation(Shape24, 1.570796F, 0F, 1.570796F);
Shape25 = new ModelRenderer(this, 0, 15);
Shape25.addBox(0F, 0F, 0F, 8, 8, 8);
Shape25.setRotationPoint(-4F, 12F, -4F);
Shape25.setTextureSize(32, 32);
Shape25.mirror = true;
setRotation(Shape25, 0F, 0F, 0F);
}
@Override
public void render() {
RenderUtil.bindTexture(TEXTURE);
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, -1.5f, 0.5f);
GL11.glPushMatrix();
float f5 = 0.0625f;
Shape1.render(f5);
Shape2.render(f5);
Shape3.render(f5);
Shape4.render(f5);
Shape5.render(f5);
Shape6.render(f5);
Shape7.render(f5);
Shape8.render(f5);
Shape9.render(f5);
Shape10.render(f5);
Shape11.render(f5);
Shape12.render(f5);
Shape13.render(f5);
Shape14.render(f5);
Shape15.render(f5);
Shape16.render(f5);
Shape17.render(f5);
Shape18.render(f5);
Shape19.render(f5);
Shape20.render(f5);
Shape21.render(f5);
Shape22.render(f5);
Shape23.render(f5);
Shape24.render(f5);
//Shape25.render(f5);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
@Override
public void render(TileTransceiver cube, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y + 1, (float) z);
render();
GL11.glPopMatrix();
}
}
@@ -0,0 +1,130 @@
package crazypants.enderio.machine.transceiver.render;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import crazypants.enderio.EnderIO;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.transceiver.TileTransceiver;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.RenderUtil;
public class TransceiverRenderer extends TileEntitySpecialRenderer implements IItemRenderer {
private IModel model;
private BoundingBox bb;
private boolean adjustForItem = false;
public TransceiverRenderer() {
float scale = 0.7f;
if(Config.useAlternateTesseractModel) {
model = new TransceiverModelAlt();
scale = 0.8f;
adjustForItem = true;
} else {
model = new TransceiverModel();
}
bb = BoundingBox.UNIT_CUBE.scale(scale, scale, scale);
}
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float tick) {
TileTransceiver cube = (TileTransceiver) te;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
float f = cube.getWorldObj().getBlockLightValue(te.xCoord, te.yCoord, te.zCoord);
int l = cube.getWorldObj().getLightBrightnessForSkyBlocks(te.xCoord, te.yCoord, te.zCoord, 0);
int l1 = l % 65536;
int l2 = l / 65536;
Tessellator.instance.setColorOpaque_F(f, f, f);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) l1, (float) l2);
model.render(cube, x, y, z);
if(cube.isActive()) {
renderPower(te.getWorldObj(), x, y, z, true);
}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
if(adjustForItem) {
switch (type) {
case ENTITY:
renderItem(0f, 0f, 0f);
return;
case EQUIPPED:
case EQUIPPED_FIRST_PERSON:
renderItem(0f, 1f, 1f);
return;
case INVENTORY:
renderItem(0f, 0f, 0f);
return;
default:
renderItem(0f, 0f, 0f);
return;
}
} else {
renderItem(0, 0, 0);
}
}
private void renderPower(World world, double x, double y, double z, boolean isActive) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
RenderUtil.bindBlockTexture();
IIcon icon = EnderIO.blockHyperCube.getPortalIcon();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if(!isActive) {
GL11.glColor4f(0, 1, 1, 0.5f);
} else {
GL11.glColor4f(1, 1, 1, 1f);
}
CubeRenderer.render(bb, icon);
tessellator.draw();
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
private void renderItem(float x, float y, float z) {
GL11.glPushMatrix();
GL11.glTranslatef(x, y, z);
model.render();
GL11.glPopMatrix();
}
}