use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian in project MineFactoryReloaded by powercrystals.
the class BlockRedNetPanel method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
return false;
}
ItemStack s = player.inventory.getCurrentItem();
TileEntity te = world.getBlockTileEntity(x, y, z);
if (MFRUtil.isHoldingHammer(player) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
((TileEntityFactory) te).rotate();
world.markBlockForUpdate(x, y, z);
return true;
} else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(player.inventory) != null) {
player.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
return true;
} else if (te instanceof TileEntityRedNetHistorian && s != null && s.itemID == Item.dyePowder.itemID) {
((TileEntityRedNetHistorian) te).setSelectedSubnet(15 - s.getItemDamage());
world.markBlockForUpdate(x, y, z);
return true;
}
return false;
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian in project MineFactoryReloaded by powercrystals.
the class RedNetHistorianRenderer method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTicks) {
RenderEngine renderengine = Minecraft.getMinecraft().renderEngine;
TileEntityRedNetHistorian historian = (TileEntityRedNetHistorian) tileentity;
if (renderengine != null) {
renderengine.bindTexture(MineFactoryReloadedCore.tileEntityFolder + "historian.png");
}
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
if (historian.getDirectionFacing() == ForgeDirection.EAST) {
GL11.glTranslatef(1, 0, 0);
GL11.glRotatef(270, 0, 1, 0);
} else if (historian.getDirectionFacing() == ForgeDirection.SOUTH) {
GL11.glTranslatef(1, 0, 1);
GL11.glRotatef(180, 0, 1, 0);
} else if (historian.getDirectionFacing() == ForgeDirection.WEST) {
GL11.glTranslatef(0, 0, 1);
GL11.glRotatef(90, 0, 1, 0);
}
_model.render((TileEntityRedNetHistorian) tileentity);
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
RenderHelper.disableStandardItemLighting();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
Tessellator t = Tessellator.instance;
t.startDrawing(GL11.GL_LINES);
GL11.glLineWidth(2.0F);
Integer[] values = historian.getValues();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int yMin = Integer.MAX_VALUE;
int yMax = Integer.MIN_VALUE;
for (int i = 0; i < values.length; i++) {
Integer v = values[i];
if (v == null) {
continue;
}
if (v > yMax) {
yMax = v;
}
if (v < yMin) {
yMin = v;
}
}
yMax = Math.max(yMax, 15);
yMin = Math.min(yMin, 0);
Integer lastValue = null;
int lastX = 0;
for (int i = 1; i < values.length; i++) {
if (values[i] == null) {
continue;
}
if (lastValue == null) {
lastValue = values[i];
lastX = i;
} else {
double x1 = (14.0 / 16.0) / values.length * lastX + (1.0 / 16.0);
double x2 = (14.0 / 16.0) / values.length * (i) + (1.0 / 16.0);
double y1 = (values[i - 1] - yMin) * (_renderMax - _renderMin) / (yMax - yMin) + _renderMin;
double y2 = (values[i] - yMin) * (_renderMax - _renderMin) / (yMax - yMin) + _renderMin;
t.addVertex(x1, y1, 0.253);
t.addVertex(x2, y2, 0.253);
lastValue = values[i];
lastX = i;
}
}
t.draw();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
use of powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian in project MineFactoryReloaded by powercrystals.
the class ClientPacketHandler method onPacketData.
@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
int packetType = PacketWrapper.readPacketID(data);
if (// server -> client; server propagating machine rotation; args X Y Z rotation isActive
packetType == Packets.TileDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityFactory) {
TileEntityFactory tef = (TileEntityFactory) te;
tef.rotateDirectlyTo((Integer) packetReadout[3]);
tef.setIsActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server propagating conveyor color, activity state
packetType == Packets.ConveyorDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityConveyor) {
TileEntityConveyor tec = (TileEntityConveyor) te;
tec.setDyeColor((Integer) packetReadout[3]);
tec.setConveyorActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server playing a record
packetType == Packets.AutoJukeboxPlay) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoJukebox) {
Minecraft.getMinecraft().ingameGUI.setRecordPlayingMessage(((ItemRecord) Item.itemsList[(Integer) packetReadout[3]]).recordName);
}
} else if (// server -> client; road block light changed
packetType == Packets.RoadBlockUpdate) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
((EntityPlayer) player).worldObj.setBlock((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2], MineFactoryReloadedCore.factoryRoadBlock.blockID, (Integer) packetReadout[3], 6);
((EntityPlayer) player).worldObj.markBlockForRenderUpdate((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
} else if (// server -> client; cable side colors
packetType == Packets.CableDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Byte.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable tec = (TileEntityRedNetCable) te;
tec.setSideColor(ForgeDirection.DOWN, (Integer) packetReadout[3]);
tec.setSideColor(ForgeDirection.UP, (Integer) packetReadout[4]);
tec.setSideColor(ForgeDirection.NORTH, (Integer) packetReadout[5]);
tec.setSideColor(ForgeDirection.SOUTH, (Integer) packetReadout[6]);
tec.setSideColor(ForgeDirection.WEST, (Integer) packetReadout[7]);
tec.setSideColor(ForgeDirection.EAST, (Integer) packetReadout[8]);
tec.setMode((Byte) packetReadout[9]);
}
} else if (// server -> client: logic circuit (class and pins)
packetType == Packets.LogicCircuitDefinition) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).setCircuitFromPacket(data);
}
} else if (packetType == Packets.HistorianValueChanged) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetHistorian) {
((TileEntityRedNetHistorian) te).setClientValue((Integer) packetReadout[3]);
}
}
}
Aggregations