Net sync for item rendering in the Glass Bell. Light levels still not immediately synced though. Working on that.

This commit is contained in:
pahimar 2013-05-07 15:44:39 -04:00
parent 4e5c5ecff1
commit dbf52792b3
17 changed files with 189 additions and 88 deletions

View file

@ -1,3 +1,3 @@
#Tue, 16 Apr 2013 14:01:55 -0400
#Tue, 07 May 2013 09:17:43 -0400
build_number=6
build_number=10

View file

@ -2,8 +2,6 @@ package com.pahimar.ee3.block;
import java.util.Random;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLiving;
@ -13,7 +11,6 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
@ -116,7 +113,6 @@ public class BlockGlassBell extends BlockEE {
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 startVec, Vec3 endVec)
{
int metaData = world.getBlockMetadata(x, y, z) & 7;
float f = 0.15F;
switch (ForgeDirection.getOrientation(metaData)) {
case DOWN: {
@ -143,6 +139,9 @@ public class BlockGlassBell extends BlockEE {
this.setBlockBounds(0.33F, 0.125F, 0.125F, 1.0F, 0.875F, 0.875F);
break;
}
case UNKNOWN: {
break;
}
}
return super.collisionRayTrace(world, x, y, z, startVec, endVec);

View file

@ -45,7 +45,6 @@ public class ModBlocks {
//GameRegistry.registerBlock(redWaterFlowing, Strings.RED_WATER_FLOWING_NAME);
initBlockRecipes();
}
private static void initBlockRecipes() {

View file

@ -76,10 +76,11 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
* Render the ghost item inside of the Glass Bell, slowly spinning
*/
GL11.glPushMatrix();
for (int i = 0; i < tileGlassBell.getSizeInventory(); i++) {
if (tileGlassBell.getStackInSlot(i) != null) {
float scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(i));
float rotationAngle = (float) (720.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
@ -93,7 +94,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
customRenderItem.doRenderItem(ghostEntityItem, 0, 0, 0, 0, 0);
}
}
GL11.glPopMatrix();
@ -143,6 +143,12 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
GL11.glRotatef(-90F, 1F, 0F, 0F);
return;
}
case UNKNOWN: {
return;
}
default: {
return;
}
}
}
@ -175,6 +181,12 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
GL11.glTranslatef((float) x + 0.70F, (float) y + 0.5F, (float) z + 0.5F);
return;
}
case UNKNOWN: {
return;
}
default: {
return;
}
}
}
else {
@ -203,6 +215,12 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
GL11.glTranslatef((float) x + 0.70F, (float) y + 0.4F, (float) z + 0.5F);
return;
}
case UNKNOWN: {
return;
}
default: {
return;
}
}
}
}

View file

@ -45,7 +45,7 @@ public class DrawBlockHighlightHandler {
if (event.target.typeOfHit == EnumMovingObjectType.TILE) {
TransmutationHelper.updateTargetBlock(event.player.worldObj, event.target.blockX, event.target.blockY, event.target.blockZ);
if (minecraft.isGuiEnabled() && minecraft.inGameHasFocus) {
if (Minecraft.isGuiEnabled() && minecraft.inGameHasFocus) {
if (ConfigurationSettings.ENABLE_OVERLAY_WORLD_TRANSMUTATION) {
drawInWorldTransmutationOverlay(event);
}

View file

@ -6,7 +6,7 @@ import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import com.pahimar.ee3.core.helper.ItemDropHelper;
import com.pahimar.ee3.core.helper.ItemHelper;
/**
* Equivalent-Exchange-3
@ -28,12 +28,12 @@ public class EntityLivingHandler {
public void onEntityLivingDeath(LivingDeathEvent event) {
if (event.source.getDamageType().equals("player")) {
ItemDropHelper.dropMiniumShard((EntityPlayer) event.source.getSourceOfDamage(), event.entityLiving);
ItemHelper.dropMiniumShard((EntityPlayer) event.source.getSourceOfDamage(), event.entityLiving);
}
if (event.source.getSourceOfDamage() instanceof EntityArrow) {
if (((EntityArrow) event.source.getSourceOfDamage()).shootingEntity != null) {
if (((EntityArrow) event.source.getSourceOfDamage()).shootingEntity instanceof EntityPlayer) {
ItemDropHelper.dropMiniumShard((EntityPlayer) ((EntityArrow) event.source.getSourceOfDamage()).shootingEntity, event.entityLiving);
ItemHelper.dropMiniumShard((EntityPlayer) ((EntityArrow) event.source.getSourceOfDamage()).shootingEntity, event.entityLiving);
}
}
}

View file

@ -52,7 +52,7 @@ public class TransmutationTargetOverlayHandler implements ITickHandler {
if (player != null) {
currentItemStack = player.inventory.getCurrentItem();
if (minecraft.isGuiEnabled() && minecraft.inGameHasFocus) {
if (Minecraft.isGuiEnabled() && minecraft.inGameHasFocus) {
if (currentItemStack != null && currentItemStack.getItem() instanceof ITransmutationStone && ConfigurationSettings.ENABLE_OVERLAY_WORLD_TRANSMUTATION) {
renderStoneHUD(minecraft, player, currentItemStack, (Float) tickData[0]);
}

View file

@ -1,32 +0,0 @@
package com.pahimar.ee3.core.helper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import com.pahimar.ee3.item.ModItems;
/**
* Equivalent-Exchange-3
*
* ItemDropHelper
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class ItemDropHelper {
private static double rand;
public static void dropMiniumShard(EntityPlayer player, EntityLiving entity) {
if (GeneralHelper.isHostileEntity(entity)) {
rand = Math.random();
if (rand < 0.15d) {
entity.dropItem(ModItems.miniumShard.itemID, 1);
}
}
}
}

View file

@ -0,0 +1,76 @@
package com.pahimar.ee3.core.helper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.Strings;
/**
* Equivalent-Exchange-3
*
* ItemDropHelper
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
public class ItemHelper {
private static double rand;
public static boolean hasColor(ItemStack itemStack) {
return !itemStack.hasTagCompound() ? false : !itemStack.getTagCompound().hasKey(Strings.NBT_ITEM_DISPLAY) ? false : itemStack.getTagCompound().getCompoundTag(Strings.NBT_ITEM_DISPLAY).hasKey(Strings.NBT_ITEM_COLOR);
}
public static int getColor(ItemStack itemStack) {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null)
return Integer.parseInt(Colours.PURE_WHITE, 16);
else {
NBTTagCompound displayTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
return displayTagCompound == null ? Integer.parseInt(Colours.PURE_WHITE, 16) : displayTagCompound.hasKey(Strings.NBT_ITEM_COLOR) ? displayTagCompound.getInteger(Strings.NBT_ITEM_COLOR) : Integer.parseInt(Colours.PURE_WHITE, 16);
}
}
public static void setColor(ItemStack itemStack, int color) {
if (itemStack != null) {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null) {
nbtTagCompound = new NBTTagCompound();
itemStack.setTagCompound(nbtTagCompound);
}
NBTTagCompound colourTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
if (!nbtTagCompound.hasKey(Strings.NBT_ITEM_DISPLAY)) {
nbtTagCompound.setCompoundTag(Strings.NBT_ITEM_DISPLAY, colourTagCompound);
}
colourTagCompound.setInteger(Strings.NBT_ITEM_COLOR, color);
}
}
public static void dropMiniumShard(EntityPlayer player, EntityLiving entity) {
if (GeneralHelper.isHostileEntity(entity)) {
rand = Math.random();
if (rand < 0.15d) {
entity.dropItem(ModItems.miniumShard.itemID, 1);
}
}
}
}

View file

@ -21,6 +21,7 @@ import com.pahimar.ee3.client.renderer.tileentity.TileEntityGlassBellRenderer;
import com.pahimar.ee3.core.handlers.DrawBlockHighlightHandler;
import com.pahimar.ee3.core.handlers.KeyBindingHandler;
import com.pahimar.ee3.core.handlers.TransmutationTargetOverlayHandler;
import com.pahimar.ee3.core.helper.ItemHelper;
import com.pahimar.ee3.core.helper.KeyBindingHelper;
import com.pahimar.ee3.core.helper.TransmutationHelper;
import com.pahimar.ee3.item.IChargeable;
@ -131,8 +132,21 @@ public class ClientProxy extends CommonProxy {
}
@Override
public void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData) {
public void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color) {
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getBlockTileEntity(x, y, z);
this.handleTileEntityPacket(x, y, z, orientation, state, customName);
if (tileEntity != null) {
if (tileEntity instanceof TileGlassBell) {
ItemStack itemStack = new ItemStack(itemID, stackSize, metaData);
ItemHelper.setColor(itemStack, color);
((TileGlassBell) tileEntity).setInventorySlotContents(0, itemStack);
}
}
}
@Override

View file

@ -84,7 +84,7 @@ public class CommonProxy implements IGuiHandler {
}
public void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData) {
public void handleTileWithItemPacket(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color) {
}

View file

@ -8,6 +8,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.World;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.core.helper.ItemHelper;
import com.pahimar.ee3.core.helper.NBTHelper;
import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.GuiIds;
@ -113,20 +114,12 @@ public class ItemAlchemicalBag extends ItemEE {
public boolean hasColor(ItemStack itemStack) {
return !itemStack.hasTagCompound() ? false : !itemStack.getTagCompound().hasKey(Strings.NBT_ITEM_DISPLAY) ? false : itemStack.getTagCompound().getCompoundTag(Strings.NBT_ITEM_DISPLAY).hasKey(Strings.NBT_ITEM_COLOR);
return ItemHelper.hasColor(itemStack);
}
public int getColor(ItemStack itemStack) {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null)
return Integer.parseInt(Colours.PURE_WHITE, 16);
else {
NBTTagCompound displayTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
return displayTagCompound == null ? Integer.parseInt(Colours.PURE_WHITE, 16) : displayTagCompound.hasKey(Strings.NBT_ITEM_COLOR) ? displayTagCompound.getInteger(Strings.NBT_ITEM_COLOR) : Integer.parseInt(Colours.PURE_WHITE, 16);
}
return ItemHelper.getColor(itemStack);
}
public void setColor(ItemStack itemStack, int color) {
@ -136,22 +129,7 @@ public class ItemAlchemicalBag extends ItemEE {
// TODO Localize
throw new UnsupportedOperationException("Can\'t dye non-bags!");
else {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null) {
nbtTagCompound = new NBTTagCompound();
itemStack.setTagCompound(nbtTagCompound);
}
NBTTagCompound colourTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
if (!nbtTagCompound.hasKey(Strings.NBT_ITEM_DISPLAY)) {
nbtTagCompound.setCompoundTag(Strings.NBT_ITEM_DISPLAY, colourTagCompound);
}
colourTagCompound.setInteger(Strings.NBT_ITEM_COLOR, color);
ItemHelper.setColor(itemStack, color);
}
}
}

View file

@ -14,6 +14,7 @@ import com.pahimar.ee3.network.packet.PacketRequestEvent;
import com.pahimar.ee3.network.packet.PacketSoundEvent;
import com.pahimar.ee3.network.packet.PacketSpawnParticle;
import com.pahimar.ee3.network.packet.PacketTileUpdate;
import com.pahimar.ee3.network.packet.PacketTileWithItemUpdate;
/**
* Equivalent-Exchange-3
@ -25,9 +26,13 @@ import com.pahimar.ee3.network.packet.PacketTileUpdate;
*
*/
public enum PacketTypeHandler {
KEY(PacketKeyPressed.class), TILE(PacketTileUpdate.class), REQUEST_EVENT(
PacketRequestEvent.class), SPAWN_PARTICLE(PacketSpawnParticle.class), SOUND_EVENT(
PacketSoundEvent.class), ITEM_UPDATE(PacketItemUpdate.class);
KEY(PacketKeyPressed.class),
TILE(PacketTileUpdate.class),
REQUEST_EVENT(PacketRequestEvent.class),
SPAWN_PARTICLE(PacketSpawnParticle.class),
SOUND_EVENT(PacketSoundEvent.class),
ITEM_UPDATE(PacketItemUpdate.class),
TILE_WITH_ITEM(PacketTileWithItemUpdate.class);
private Class<? extends PacketEE> clazz;

View file

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

View file

@ -13,21 +13,32 @@ import com.pahimar.ee3.network.PacketTypeHandler;
import cpw.mods.fml.common.network.Player;
public class PacketTileWithItemUpdate extends PacketTileUpdate {
public class PacketTileWithItemUpdate extends PacketEE {
public int itemID;
public int metaData;
public int x, y, z;
public byte orientation;
public byte state;
public String customName;
public int itemID, metaData, stackSize, color;
public PacketTileWithItemUpdate() {
super();
super(PacketTypeHandler.TILE_WITH_ITEM, true);
}
public PacketTileWithItemUpdate(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData) {
public PacketTileWithItemUpdate(int x, int y, int z, ForgeDirection orientation, byte state, String customName, int itemID, int metaData, int stackSize, int color) {
super(x, y, z, orientation, state, customName);
super(PacketTypeHandler.TILE_WITH_ITEM, true);
this.x = x;
this.y = y;
this.z = z;
this.orientation = (byte) orientation.ordinal();
this.state = state;
this.customName = customName;
this.itemID = itemID;
this.metaData = metaData;
this.stackSize = stackSize;
this.color = color;
}
@Override
@ -41,6 +52,8 @@ public class PacketTileWithItemUpdate extends PacketTileUpdate {
data.writeUTF(customName);
data.writeInt(itemID);
data.writeInt(metaData);
data.writeInt(stackSize);
data.writeInt(color);
}
@Override
@ -54,11 +67,14 @@ public class PacketTileWithItemUpdate extends PacketTileUpdate {
customName = data.readUTF();
itemID = data.readInt();
metaData = data.readInt();
stackSize = data.readInt();
color = data.readInt();
}
@Override
public void execute(INetworkManager manager, Player player) {
EquivalentExchange3.proxy.handleTileWithItemPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName, itemID, metaData);
System.out.println("PacketTileWithItemUpdate - Execute");
EquivalentExchange3.proxy.handleTileWithItemPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, customName, itemID, metaData, stackSize, color);
}
}

View file

@ -21,9 +21,9 @@ import com.pahimar.ee3.network.packet.PacketTileUpdate;
*/
public class TileEE extends TileEntity {
private ForgeDirection orientation;
private byte state;
private String customName;
protected ForgeDirection orientation;
protected byte state;
protected String customName;
public TileEE() {

View file

@ -4,8 +4,12 @@ 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 com.pahimar.ee3.core.helper.ItemHelper;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.network.PacketTypeHandler;
import com.pahimar.ee3.network.packet.PacketTileWithItemUpdate;
public class TileGlassBell extends TileEE implements IInventory {
@ -13,6 +17,7 @@ public class TileGlassBell extends TileEE implements IInventory {
* The ItemStacks that hold the items currently being used in the Glass Bell
*/
private ItemStack[] inventory;
private ItemStack ghostItemStack;
private final int INVENTORY_SIZE = 1;
@ -21,6 +26,7 @@ public class TileGlassBell extends TileEE implements IInventory {
public TileGlassBell() {
inventory = new ItemStack[INVENTORY_SIZE];
ghostItemStack = null;
}
@Override
@ -94,6 +100,16 @@ public class TileGlassBell extends TileEE implements IInventory {
public void closeChest() {
}
public ItemStack getGhostItemStack() {
return ghostItemStack;
}
public void setGhostItemStack(ItemStack ghostItemStack) {
this.ghostItemStack = ghostItemStack;
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
@ -141,4 +157,15 @@ public class TileGlassBell extends TileEE implements IInventory {
return true;
}
@Override
public Packet getDescriptionPacket() {
if ((inventory[0] != null) && (inventory[0].stackSize > 0)) {
return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, inventory[0].itemID, inventory[0].getItemDamage(), inventory[0].stackSize, ItemHelper.getColor(inventory[0])));
}
else {
return super.getDescriptionPacket();
}
}
}