Calcinator network work

This commit is contained in:
pahimar 2014-01-11 17:41:28 -05:00
parent a328988b28
commit f56791ee08
10 changed files with 166 additions and 61 deletions

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.client.renderer.tileentity;
import com.pahimar.ee3.client.model.ModelCalcinator;
import com.pahimar.ee3.helper.ColourUtils;
import com.pahimar.ee3.lib.Textures;
import com.pahimar.ee3.tileentity.TileCalcinator;
import cpw.mods.fml.client.FMLClientHandler;
@ -54,7 +55,7 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer
// Render
modelCalcinator.renderPart("Calcinator");
if (tileCalcinator.getCombinedOutputSize() > 0)
if (tileCalcinator.dustStackSize > 0)
{
GL11.glPushMatrix();
@ -62,15 +63,15 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer
GL11.glRotatef(90F, 1F, 0F, 0F);
GL11.glRotatef(-45F, 0F, 1F, 0F);
float[] dustColour = tileCalcinator.getBlendedDustColour();
float[] dustColour = ColourUtils.convertByteArrayToFloatArray(new byte[]{tileCalcinator.dustColourRedChannel, tileCalcinator.dustColourGreenChannel, tileCalcinator.dustColourBlueChannel});
GL11.glColor4f(dustColour[0], dustColour[1], dustColour[2], 1F);
if (tileCalcinator.getCombinedOutputSize() <= 32)
if (tileCalcinator.dustStackSize <= 32)
{
GL11.glScalef(0.25F, 0.25F, 0.25F);
GL11.glTranslatef(0.0F, 2.20F, -2.1125F);
}
else if (tileCalcinator.getCombinedOutputSize() <= 64)
else if (tileCalcinator.dustStackSize <= 64)
{
GL11.glScalef(0.5F, 0.5F, 0.5F);
GL11.glTranslatef(-0.0125F, 0.75F, -0.7125F);

View file

@ -1,4 +1,4 @@
package com.pahimar.ee3.client.helper;
package com.pahimar.ee3.helper;
import java.util.regex.Pattern;
@ -45,6 +45,17 @@ public class ColourUtils
return colourFloatArray;
}
public static float[] convertByteArrayToFloatArray(byte[] byteArray)
{
float[] colourFloatArray = new float[3];
colourFloatArray[0] = (float) byteArray[0] / 255F;
colourFloatArray[1] = (float) byteArray[1] / 255F;
colourFloatArray[2] = (float) byteArray[2] / 255F;
return colourFloatArray;
}
@SuppressWarnings("unused")
public static byte[] getBlendedColours(String firstColour, String secondColour)
{

View file

@ -23,7 +23,8 @@ public enum PacketTypeHandler
SPAWN_PARTICLE(PacketSpawnParticle.class),
SOUND_EVENT(PacketSoundEvent.class),
ITEM_UPDATE(PacketItemUpdate.class),
TILE_WITH_ITEM(PacketTileWithItemUpdate.class);
TILE_WITH_ITEM(PacketTileWithItemUpdate.class),
TILE_CALCINATOR(PacketTileCalcinator.class);
private Class<? extends PacketEE> clazz;

View file

@ -0,0 +1,77 @@
package com.pahimar.ee3.network.packet;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.network.PacketTypeHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.network.INetworkManager;
import net.minecraftforge.common.ForgeDirection;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class PacketTileCalcinator extends PacketEE
{
public int x, y, z;
public byte orientation;
public byte state;
public String customName;
public int dustStackSize;
public byte redChannel, greenChannel, blueChannel;
public PacketTileCalcinator()
{
super(PacketTypeHandler.TILE_CALCINATOR, true);
}
public PacketTileCalcinator(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel)
{
super(PacketTypeHandler.TILE_CALCINATOR, true);
this.x = x;
this.y = y;
this.z = z;
this.orientation = (byte) orientation.ordinal();
this.state = state;
this.customName = customName;
this.dustStackSize = dustStackSize;
this.redChannel = redChannel;
this.greenChannel = greenChannel;
this.blueChannel = blueChannel;
}
@Override
public void writeData(DataOutputStream data) throws IOException
{
data.writeInt(x);
data.writeInt(y);
data.writeInt(z);
data.writeByte(orientation);
data.writeByte(state);
data.writeUTF(customName);
data.writeInt(dustStackSize);
data.writeByte(redChannel);
data.writeByte(greenChannel);
data.writeByte(blueChannel);
}
@Override
public void readData(DataInputStream data) throws IOException
{
x = data.readInt();
y = data.readInt();
z = data.readInt();
orientation = data.readByte();
state = data.readByte();
customName = data.readUTF();
dustStackSize = data.readInt();
redChannel = data.readByte();
greenChannel = data.readByte();
blueChannel = data.readByte();
}
@Override
public void execute(INetworkManager manager, Player player)
{
EquivalentExchange3.proxy.handleTileCalcinatorPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName, dustStackSize, redChannel, greenChannel, blueChannel);
}
}

View file

@ -65,7 +65,6 @@ public class PacketTileUpdate extends PacketEE
@Override
public void execute(INetworkManager manager, Player player)
{
EquivalentExchange3.proxy.handleTileEntityPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName);
}
}

View file

@ -134,32 +134,45 @@ public class ClientProxy extends CommonProxy
this.handleTileEntityPacket(x, y, z, orientation, state, customName);
if (tileEntity != null)
if (tileEntity instanceof TileGlassBell)
{
if (tileEntity instanceof TileGlassBell)
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
{
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
{
ItemHelper.setColor(itemStack, color);
}
((TileGlassBell) tileEntity).setInventorySlotContents(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, itemStack);
world.updateAllLightTypes(x, y, z);
ItemHelper.setColor(itemStack, color);
}
else if (tileEntity instanceof TileAludel)
((TileGlassBell) tileEntity).setInventorySlotContents(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, itemStack);
world.updateAllLightTypes(x, y, z);
}
else if (tileEntity instanceof TileAludel)
{
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
{
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
if (color != Integer.parseInt(Colours.PURE_WHITE, 16))
{
ItemHelper.setColor(itemStack, color);
}
((TileAludel) tileEntity).setInventorySlotContents(TileAludel.INPUT_INVENTORY_INDEX, itemStack);
world.updateAllLightTypes(x, y, z);
ItemHelper.setColor(itemStack, color);
}
((TileAludel) tileEntity).setInventorySlotContents(TileAludel.INPUT_INVENTORY_INDEX, itemStack);
world.updateAllLightTypes(x, y, z);
}
}
@Override
public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel)
{
World world = FMLClientHandler.instance().getClient().theWorld;
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
this.handleTileEntityPacket(x, y, z, orientation, state, customName);
if (tileEntity instanceof TileCalcinator)
{
((TileCalcinator) tileEntity).dustStackSize = dustStackSize;
((TileCalcinator) tileEntity).dustColourRedChannel = redChannel;
((TileCalcinator) tileEntity).dustColourGreenChannel = greenChannel;
((TileCalcinator) tileEntity).dustColourBlueChannel = blueChannel;
world.updateAllLightTypes(x, y, z);
}
}

View file

@ -29,5 +29,7 @@ public interface IProxy
public abstract void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color);
public abstract void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel);
public abstract void transmuteBlock(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int sideHit);
}

View file

@ -69,4 +69,9 @@ public class ServerProxy extends CommonProxy
{
// NOOP
}
public void handleTileCalcinatorPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int dustStackSize, byte redChannel, byte greenChannel, byte blueChannel)
{
// NOOP
}
}

View file

@ -1,7 +1,9 @@
package com.pahimar.ee3.tileentity;
import com.pahimar.ee3.client.helper.ColourUtils;
import com.pahimar.ee3.helper.ColourUtils;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.network.PacketTypeHandler;
import com.pahimar.ee3.network.packet.PacketTileCalcinator;
import com.pahimar.ee3.recipe.CalcinationManager;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -9,6 +11,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntityFurnace;
/**
@ -36,8 +39,8 @@ public class TileCalcinator extends TileEE implements IInventory
public int fuelBurnTime; // The fuel value for the currently burning fuel
public int itemCookTime; // How long the current item has been "cooking"
public String dustColour;
public int dustPileSize;
public int dustStackSize;
public byte dustColourRedChannel, dustColourGreenChannel, dustColourBlueChannel;
public TileCalcinator()
{
@ -199,8 +202,7 @@ public class TileCalcinator extends TileEE implements IInventory
public void updateEntity()
{
boolean isBurning = this.deviceCookTime > 0;
this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0;
boolean inventoryChanged = false;
boolean sendUpdate = false;
// If the Calcinator still has burn time, decrement it
if (this.deviceCookTime > 0)
@ -208,11 +210,9 @@ public class TileCalcinator extends TileEE implements IInventory
this.deviceCookTime--;
}
// TODO Make this less network spammy
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 1, this.state);
if (!this.worldObj.isRemote)
{
// Start "cooking" a new item, if we can
if (this.deviceCookTime == 0 && this.canCalcinate())
{
// TODO Effect burn speed by fuel quality
@ -220,7 +220,7 @@ public class TileCalcinator extends TileEE implements IInventory
if (this.deviceCookTime > 0)
{
inventoryChanged = true;
sendUpdate = true;
if (this.inventory[FUEL_INVENTORY_INDEX] != null)
{
@ -234,6 +234,7 @@ public class TileCalcinator extends TileEE implements IInventory
}
}
// Continue "cooking" the same item, if we can
if (this.deviceCookTime > 0 && this.canCalcinate())
{
this.itemCookTime++;
@ -242,7 +243,7 @@ public class TileCalcinator extends TileEE implements IInventory
{
this.itemCookTime = 0;
this.calcinateItem();
inventoryChanged = true;
sendUpdate = true;
}
}
else
@ -250,15 +251,18 @@ public class TileCalcinator extends TileEE implements IInventory
this.itemCookTime = 0;
}
// If the state has changed, catch that something changed
if (isBurning != this.deviceCookTime > 0)
{
inventoryChanged = true;
sendUpdate = true;
}
}
if (inventoryChanged)
if (sendUpdate)
{
this.onInventoryChanged();
this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0;
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType().blockID, 1, this.state);
}
}
@ -383,7 +387,7 @@ public class TileCalcinator extends TileEE implements IInventory
}
@SideOnly(Side.CLIENT)
public float[] getBlendedDustColour()
public byte[] getBlendedDustColour()
{
if (inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null && inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null)
{
@ -393,21 +397,28 @@ public class TileCalcinator extends TileEE implements IInventory
int stackSizeStepRange = 8;
int leftStackSize = inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize / stackSizeStepRange;
int rightStackSize = inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize / stackSizeStepRange;
float[][] blendedColours = ColourUtils.getFloatBlendedColours(leftStackColour, rightStackColour, 2 * stackSizeStepRange - 1);
byte[][] blendedByteColours = ColourUtils.getByteBlendedColours(ColourUtils.convertIntColourToByteArray(leftStackColour), ColourUtils.convertIntColourToByteArray(rightStackColour), 2 * stackSizeStepRange - 1);
return blendedColours[stackSizeStepRange + (leftStackSize - rightStackSize)];
return blendedByteColours[stackSizeStepRange + (leftStackSize - rightStackSize)];
}
else if (inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null)
{
return ColourUtils.convertIntColourToFloatArray(inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1));
return ColourUtils.convertIntColourToByteArray(inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_LEFT_INVENTORY_INDEX], 1));
}
else if (inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null)
{
return ColourUtils.convertIntColourToFloatArray(inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1));
return ColourUtils.convertIntColourToByteArray(inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItem().getColorFromItemStack(inventory[OUTPUT_RIGHT_INVENTORY_INDEX], 1));
}
else
{
return new float[]{1F, 1F, 1F};
return new byte[]{(byte) 255, (byte) 255, (byte) 255};
}
}
@Override
public Packet getDescriptionPacket()
{
byte[] colourChannels = getBlendedDustColour();
return PacketTypeHandler.populatePacket(new PacketTileCalcinator(xCoord, yCoord, zCoord, orientation, state, customName, getCombinedOutputSize(), colourChannels[0], colourChannels[1], colourChannels[2]));
}
}

View file

@ -12,7 +12,6 @@ import net.minecraft.network.packet.Packet;
public class TileGlassBell extends TileEE implements IInventory
{
/**
* The ItemStacks that hold the items currently being used in the Glass Bell
*/
@ -24,7 +23,6 @@ public class TileGlassBell extends TileEE implements IInventory
public TileGlassBell()
{
inventory = new ItemStack[INVENTORY_SIZE];
}
@ -38,14 +36,12 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public ItemStack getStackInSlot(int slotIndex)
{
return inventory[slotIndex];
}
@Override
public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{
ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null)
{
@ -69,7 +65,6 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex)
{
ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null)
{
@ -81,7 +76,6 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
@ -92,14 +86,12 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public String getInvName()
{
return this.hasCustomName() ? this.getCustomName() : Strings.CONTAINER_GLASS_BELL_NAME;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@ -118,7 +110,6 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
// Read in the ItemStacks in the inventory from NBT
@ -138,7 +129,6 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
// Write the ItemStacks in the inventory to NBT
@ -159,21 +149,18 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public boolean isInvNameLocalized()
{
return this.hasCustomName();
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{
return true;
}
@Override
public Packet getDescriptionPacket()
{
ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX);
if (itemStack != null && itemStack.stackSize > 0)
@ -189,14 +176,12 @@ public class TileGlassBell extends TileEE implements IInventory
@Override
public void onInventoryChanged()
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
}
@Override
public String toString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(super.toString());