diff --git a/src/main/java/am2/client/blocks/render/TileCrystalMarkerRenderer.java b/src/main/java/am2/client/blocks/render/TileCrystalMarkerRenderer.java index ae170b214..dbbcf2ef6 100644 --- a/src/main/java/am2/client/blocks/render/TileCrystalMarkerRenderer.java +++ b/src/main/java/am2/client/blocks/render/TileCrystalMarkerRenderer.java @@ -1,110 +1,114 @@ -package am2.client.blocks.render; - -import org.lwjgl.opengl.GL11; - -import am2.common.blocks.BlockCrystalMarker; -import am2.common.blocks.tileentity.TileEntityCrystalMarker; -import am2.common.defs.BlockDefs; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.client.model.IModel; -import net.minecraftforge.client.model.ModelLoaderRegistry; -import net.minecraftforge.common.model.TRSRTransformation; - -public class TileCrystalMarkerRenderer extends TileEntitySpecialRenderer{ - private IModel model; - private IBakedModel bakedModel; - - private IBakedModel getBakedModel() { - try { - model = ModelLoaderRegistry.getModel(new ResourceLocation("arsmagica2", "block/crystal_marker.obj")); - } catch (Exception e) { - throw new RuntimeException(e); - } - bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); - return bakedModel; - } - - - public TileCrystalMarkerRenderer(){ - } - - public void renderTileEntityAt(TileEntityCrystalMarker tileentity, double x, double y, double z, float partialTicks, int destroyStage){ - EnumFacing facing = EnumFacing.UP; - - if (tileentity.getWorld() != null){ - facing = tileentity.getFacing(); - } - - GL11.glPushMatrix(); - GL11.glPushAttrib(GL11.GL_LIGHTING_BIT); - Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); - GL11.glDisable(GL11.GL_CULL_FACE); - RenderHelper.disableStandardItemLighting(); - - if (tileentity.getPos() != BlockPos.ORIGIN){ - switch (facing){ - case UP: //Bottom, Inventory is above - GL11.glTranslated(x + 0.5, y + 1.0 + tileentity.GetConnectedBoundingBox().minY, z + 0.5); - GL11.glRotated(90, 1, 0, 0); - break; - case DOWN: //Top, Inventory is below - GL11.glTranslated(x + 0.5, y - (1.0 - tileentity.GetConnectedBoundingBox().maxY), z + 0.5); - GL11.glRotated(270, 1, 0, 0); - break; - case SOUTH: //North, Inventory is to the south - GL11.glTranslated(x + 0.5, y + 0.5, z + 1.0 + (1.0 - tileentity.GetConnectedBoundingBox().maxZ)); - GL11.glRotated(180, 0, 1, 0); - break; - case NORTH: //South, Inventory is to the north - GL11.glTranslated(x + 0.5, y + 0.5, z - tileentity.GetConnectedBoundingBox().minZ); - break; - case EAST: //West, Inventory is to the east - GL11.glTranslated(x + 1 + tileentity.GetConnectedBoundingBox().minX, y + 0.5, z + 0.5); - GL11.glRotated(270, 0, 1, 0); - break; - case WEST: //East, Inventory is to the west - GL11.glTranslated(x - (1.0 - tileentity.GetConnectedBoundingBox().maxX), y + 0.5, z + 0.5); - GL11.glRotated(90, 0, 1, 0); - break; - } - - GL11.glScalef(0.5f, 0.5f, 0.5f); - }else{ - GL11.glTranslated(0.5, 0.5, 0.5); - GL11.glScalef(1.4f, 1.4f, 1.4f); - GL11.glRotated(180, 0, 1, 0); - } - - int blockType = 0; - - if (tileentity.getWorld() != null && destroyStage != -10){ - blockType = tileentity.getWorld().getBlockState(tileentity.getPos()).getValue(BlockCrystalMarker.TYPE); - }else{ - blockType = (int)partialTicks; - } - - GlStateManager.pushMatrix(); - GlStateManager.translate(-tileentity.getPos().getX(), -tileentity.getPos().getY(), -tileentity.getPos().getZ()); - Tessellator tesselator = Tessellator.getInstance(); - tesselator.getBuffer().begin(7, DefaultVertexFormats.BLOCK); - Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(getWorld(), getBakedModel(), BlockDefs.crystalMarker.getDefaultState().withProperty(BlockCrystalMarker.TYPE, blockType), tileentity.getPos(), tesselator.getBuffer(), false); - tesselator.draw(); - GlStateManager.popMatrix(); - RenderHelper.enableStandardItemLighting(); - GL11.glPopAttrib(); - GL11.glEnable(GL11.GL_CULL_FACE); - GlStateManager.enableBlend(); - GL11.glPopMatrix(); - } - -} +package am2.client.blocks.render; + +import org.lwjgl.opengl.GL11; + +import am2.common.blocks.BlockCrystalMarker; +import am2.common.blocks.tileentity.TileEntityCrystalMarker; +import am2.common.defs.BlockDefs; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.common.model.TRSRTransformation; + +public class TileCrystalMarkerRenderer extends TileEntitySpecialRenderer{ + private IModel model; + private IBakedModel bakedModel; + + private IBakedModel getBakedModel() { + if (bakedModel == null) { + try { + model = ModelLoaderRegistry.getModel(new ResourceLocation("arsmagica2", "block/crystal_marker.obj")); + } catch (Exception e) { + throw new RuntimeException(e); + } + bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); + } + return bakedModel; + } + + + public TileCrystalMarkerRenderer(){ + } + + @Override + public void renderTileEntityAt(TileEntityCrystalMarker tileentity, double x, double y, double z, float partialTicks, int destroyStage){ + EnumFacing facing = EnumFacing.UP; + + if (tileentity.getWorld() != null){ + facing = tileentity.getFacing(); + //facing = tileentity.getWorld().getBlockState(tileentity.getPos()).getValue(BlockCrystalMarker.FACING); + } + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib();//(GL11.GL_LIGHTING_BIT); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + GlStateManager.disableCull(); + RenderHelper.disableStandardItemLighting(); + + if (tileentity.getPos() != BlockPos.ORIGIN){ + switch (facing){ + case UP: //Bottom, Inventory is above + GL11.glTranslated(x + 0.5, y + 1.0 + tileentity.GetConnectedBoundingBox().minY, z + 0.5); + GL11.glRotated(90, 1, 0, 0); + break; + case DOWN: //Top, Inventory is below + GL11.glTranslated(x + 0.5, y - (1.0 - tileentity.GetConnectedBoundingBox().maxY), z + 0.5); + GL11.glRotated(270, 1, 0, 0); + break; + case SOUTH: //North, Inventory is to the south + GL11.glTranslated(x + 0.5, y + 0.5, z + 1.0 + (1.0 - tileentity.GetConnectedBoundingBox().maxZ)); + GL11.glRotated(180, 0, 1, 0); + break; + case NORTH: //South, Inventory is to the north + GL11.glTranslated(x + 0.5, y + 0.5, z - tileentity.GetConnectedBoundingBox().minZ); + break; + case EAST: //West, Inventory is to the east + GL11.glTranslated(x + 1 + tileentity.GetConnectedBoundingBox().minX, y + 0.5, z + 0.5); + GL11.glRotated(270, 0, 1, 0); + break; + case WEST: //East, Inventory is to the west + GL11.glTranslated(x - (1.0 - tileentity.GetConnectedBoundingBox().maxX), y + 0.5, z + 0.5); + GL11.glRotated(90, 0, 1, 0); + break; + } + + GL11.glScalef(0.5f, 0.5f, 0.5f); + }else{ + GL11.glTranslated(0.5, 0.5, 0.5); + GL11.glScalef(1.4f, 1.4f, 1.4f); + GL11.glRotated(180, 0, 1, 0); + } + + int blockType = 0; + + if (tileentity.getWorld() != null && destroyStage != -10){ + blockType = tileentity.getWorld().getBlockState(tileentity.getPos()).getValue(BlockCrystalMarker.TYPE); + }else{ + blockType = (int)partialTicks; + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(-tileentity.getPos().getX(), -tileentity.getPos().getY(), -tileentity.getPos().getZ()); + Tessellator tesselator = Tessellator.getInstance(); + tesselator.getBuffer().begin(7, DefaultVertexFormats.BLOCK); + Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(getWorld(), getBakedModel(), BlockDefs.crystalMarker.getDefaultState().withProperty(BlockCrystalMarker.TYPE, blockType), tileentity.getPos(), tesselator.getBuffer(), false); + tesselator.draw(); + GlStateManager.popMatrix(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.popAttrib(); + GlStateManager.enableCull(); + GlStateManager.enableBlend(); + GlStateManager.popMatrix(); + } + +} diff --git a/src/main/java/am2/common/blocks/tileentity/TileEntityAMPower.java b/src/main/java/am2/common/blocks/tileentity/TileEntityAMPower.java index aa1c58858..76c5818ec 100644 --- a/src/main/java/am2/common/blocks/tileentity/TileEntityAMPower.java +++ b/src/main/java/am2/common/blocks/tileentity/TileEntityAMPower.java @@ -1,7 +1,5 @@ package am2.common.blocks.tileentity; -import java.util.List; - import am2.api.power.IPowerNode; import am2.common.power.PowerNodeRegistry; import am2.common.power.PowerTypes; @@ -10,99 +8,101 @@ import net.minecraft.util.ITickable; import net.minecraft.world.World; -public abstract class TileEntityAMPower extends TileEntity implements IPowerNode, ITickable{ +import java.util.List; + +public abstract class TileEntityAMPower extends TileEntity implements IPowerNode, ITickable { protected int capacity; protected boolean canRequestPower = true; private int tickCounter; private static final int REQUEST_INTERVAL = 20; - public TileEntityAMPower(int capacity){ + public TileEntityAMPower(int capacity) { this.capacity = capacity; } - protected void setNoPowerRequests(){ - canRequestPower = false; + protected void setNoPowerRequests() { + this.canRequestPower = false; } - protected void setPowerRequests(){ - canRequestPower = true; + protected void setPowerRequests() { + this.canRequestPower = true; } /*** * Whether or not the tile entity is *capable* of providing power. */ @Override - public boolean canProvidePower(PowerTypes type){ + public boolean canProvidePower(PowerTypes type) { return false; } @Override - public void invalidate(){ + public void invalidate() { PowerNodeRegistry.For(this.worldObj).removePowerNode(this); super.invalidate(); } @Override - public void update(){ - if (!worldObj.isRemote && this.canRequestPower() && tickCounter++ >= getRequestInterval()){ - tickCounter = 0; + public void update() { + if (!this.worldObj.isRemote && this.canRequestPower() && this.tickCounter++ >= this.getRequestInterval()) { + this.tickCounter = 0; List powerTypes = this.getValidPowerTypes(); - for (PowerTypes type : powerTypes){ - float amtObtained = PowerNodeRegistry.For(worldObj).requestPower(this, type, this.getChargeRate()); + for (PowerTypes type : powerTypes) { + float amtObtained = PowerNodeRegistry.For(this.worldObj).requestPower(this, type, this.getChargeRate()); if (amtObtained > 0) - PowerNodeRegistry.For(worldObj).insertPower(this, type, amtObtained); + PowerNodeRegistry.For(this.worldObj).insertPower(this, type, amtObtained); } } //worldObj.markAndNotifyBlock(pos, worldObj.getChunkFromBlockCoords(pos), worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3); } - public int getRequestInterval(){ + public int getRequestInterval() { return REQUEST_INTERVAL; } @Override - public float particleOffset(int axis){ + public float particleOffset(int axis) { return 0.5f; } @Override - public void readFromNBT(NBTTagCompound nbttagcompound){ + public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); } @Override - public void setWorldObj(World par1World){ + public void setWorldObj(World par1World) { super.setWorldObj(par1World); PowerNodeRegistry.For(this.worldObj).registerPowerNode(this); } @Override - public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { return super.writeToNBT(nbttagcompound); } @Override - public float getCapacity(){ + public float getCapacity() { return this.capacity; } - public void setPower(PowerTypes type, float amount){ + public void setPower(PowerTypes type, float amount) { PowerNodeRegistry.For(this.worldObj).setPower(this, type, amount); } @Override - public List getValidPowerTypes(){ + public List getValidPowerTypes() { return PowerTypes.all(); } @Override - public boolean canRequestPower(){ - return canRequestPower; + public boolean canRequestPower() { + return this.canRequestPower; } @Override - public boolean isSource(){ + public boolean isSource() { return false; } } diff --git a/src/main/java/am2/common/blocks/tileentity/TileEntityCrystalMarker.java b/src/main/java/am2/common/blocks/tileentity/TileEntityCrystalMarker.java index 0701da524..90496a3b6 100644 --- a/src/main/java/am2/common/blocks/tileentity/TileEntityCrystalMarker.java +++ b/src/main/java/am2/common/blocks/tileentity/TileEntityCrystalMarker.java @@ -1,7 +1,5 @@ package am2.common.blocks.tileentity; -import java.util.List; - import am2.api.math.AMVector3; import am2.common.blocks.BlockCrystalMarker; import am2.common.utils.InventoryUtilities; @@ -24,6 +22,7 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.Constants; public class TileEntityCrystalMarker extends TileEntity implements IInventory, ISidedInventory, ITickable{ @@ -37,6 +36,7 @@ public class TileEntityCrystalMarker extends TileEntity implements IInventory, I protected ItemStack[] filterItems; private int markerType; private AxisAlignedBB connectedBoundingBox; + private int tickCount; public void setFacing(EnumFacing face){ this.facing = face; @@ -54,26 +54,26 @@ public void cyclePriority(){ this.priority++; this.priority %= TileEntityFlickerHabitat.PRIORITY_LEVELS; if (!this.worldObj.isRemote){ - for (EntityPlayerMP player : (List)this.worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB(pos).expand(64, 64, 64))){ - player.connection.sendPacket(getUpdatePacket()); + for (EntityPlayerMP player : this.worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB(this.pos).expand(64, 64, 64))){ + player.connection.sendPacket(this.getUpdatePacket()); } } } public AxisAlignedBB GetConnectedBoundingBox(){ - if (connectedBoundingBox != null){ - return connectedBoundingBox; + if (this.connectedBoundingBox != null){ + return this.connectedBoundingBox; }else{ return new AxisAlignedBB(BlockPos.ORIGIN); } } public void SetConnectedBoundingBox(AxisAlignedBB boundingBox){ - connectedBoundingBox = boundingBox; + this.connectedBoundingBox = boundingBox; } public void SetConnectedBoundingBox(double minx, double miny, double minz, double maxx, double maxy, double maxz){ - connectedBoundingBox = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); + this.connectedBoundingBox = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); } public int getMarkerType(){ @@ -81,23 +81,23 @@ public int getMarkerType(){ } public void setElementalAttuner(AMVector3 vector){ - elementalAttuner = new AMVector3(vector.x, vector.y, vector.z); + this.elementalAttuner = new AMVector3(vector.x, vector.y, vector.z); } public AMVector3 getElementalAttuner(){ - return elementalAttuner; + return this.elementalAttuner; } public void removeElementalAttuner(){ - elementalAttuner = null; + this.elementalAttuner = null; } public boolean hasFilterItems(){ boolean retVar = false; - if (filterItems != null){ - for (int i = 0; i < filterItems.length; i++){ - if (filterItems[i] != null){ + if (this.filterItems != null){ + for (int i = 0; i < this.filterItems.length; i++){ + if (this.filterItems[i] != null){ retVar = true; break; } @@ -116,9 +116,9 @@ public boolean hasFilterItems(){ public boolean filterHasItem(ItemStack stack){ boolean retVal = false; - if (stack != null && hasFilterItems()){ - for (int i = 0; i < filterItems.length; i++){ - if (filterItems[i] != null && InventoryUtilities.compareItemStacks(filterItems[i], stack, true, false, true, true)){ + if (stack != null && this.hasFilterItems()){ + for (int i = 0; i < this.filterItems.length; i++){ + if (this.filterItems[i] != null && InventoryUtilities.compareItemStacks(this.filterItems[i], stack, true, false, true, true)){ retVal = true; break; } @@ -131,10 +131,10 @@ public boolean filterHasItem(ItemStack stack){ public int getFilterCount(ItemStack stack){ int totalCount = 0; - if (hasFilterItems()){ - for (int i = 0; i < filterItems.length; i++){ - if (filterItems[i] != null && InventoryUtilities.compareItemStacks(filterItems[i], stack, true, false, true, true)){ - totalCount += filterItems[i].stackSize; + if (this.hasFilterItems()){ + for (int i = 0; i < this.filterItems.length; i++){ + if (this.filterItems[i] != null && InventoryUtilities.compareItemStacks(this.filterItems[i], stack, true, false, true, true)){ + totalCount += this.filterItems[i].stackSize; } } } @@ -147,7 +147,7 @@ public TileEntityCrystalMarker(){ } public TileEntityCrystalMarker(int markerType){ - filterItems = new ItemStack[FILTER_SIZE]; + this.filterItems = new ItemStack[FILTER_SIZE]; this.markerType = markerType; if (this.markerType == BlockCrystalMarker.META_FINAL_DEST) this.priority = TileEntityFlickerHabitat.PRIORITY_FINAL; @@ -158,13 +158,13 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ super.writeToNBT(nbttagcompound); nbttagcompound.setInteger("facing", this.facing.ordinal()); nbttagcompound.setInteger("priority", this.priority); - nbttagcompound.setInteger("markerType", markerType); + nbttagcompound.setInteger("markerType", this.markerType); - if (elementalAttuner != null){ + if (this.elementalAttuner != null){ NBTTagCompound elementalAttunerLocation = new NBTTagCompound(); - elementalAttunerLocation.setFloat("x", elementalAttuner.x); - elementalAttunerLocation.setFloat("y", elementalAttuner.y); - elementalAttunerLocation.setFloat("z", elementalAttuner.z); + elementalAttunerLocation.setFloat("x", this.elementalAttuner.x); + elementalAttunerLocation.setFloat("y", this.elementalAttuner.y); + elementalAttunerLocation.setFloat("z", this.elementalAttuner.z); nbttagcompound.setTag("elementalAttuner", elementalAttunerLocation); } @@ -172,11 +172,11 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ NBTTagList filterItemsList = new NBTTagList(); for (int i = 0; i < this.getSizeInventory(); i++){ - if (filterItems[i] != null){ + if (this.filterItems[i] != null){ String tag = String.format("ArrayIndex", i); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte(tag, (byte)i); - filterItems[i].writeToNBT(nbttagcompound1); + this.filterItems[i].writeToNBT(nbttagcompound1); filterItemsList.appendTag(nbttagcompound1); } } @@ -186,12 +186,12 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ if (this.connectedBoundingBox != null){ NBTTagCompound connectedBoundingBoxDimensions = new NBTTagCompound(); - connectedBoundingBoxDimensions.setDouble("minx", connectedBoundingBox.minX); - connectedBoundingBoxDimensions.setDouble("miny", connectedBoundingBox.minY); - connectedBoundingBoxDimensions.setDouble("minz", connectedBoundingBox.minZ); - connectedBoundingBoxDimensions.setDouble("maxx", connectedBoundingBox.maxX); - connectedBoundingBoxDimensions.setDouble("maxy", connectedBoundingBox.maxY); - connectedBoundingBoxDimensions.setDouble("maxz", connectedBoundingBox.maxZ); + connectedBoundingBoxDimensions.setDouble("minx", this.connectedBoundingBox.minX); + connectedBoundingBoxDimensions.setDouble("miny", this.connectedBoundingBox.minY); + connectedBoundingBoxDimensions.setDouble("minz", this.connectedBoundingBox.minZ); + connectedBoundingBoxDimensions.setDouble("maxx", this.connectedBoundingBox.maxX); + connectedBoundingBoxDimensions.setDouble("maxy", this.connectedBoundingBox.maxY); + connectedBoundingBoxDimensions.setDouble("maxz", this.connectedBoundingBox.maxZ); nbttagcompound.setTag("connectedBoundingBox", connectedBoundingBoxDimensions); } return nbttagcompound; @@ -200,9 +200,9 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ @Override public void readFromNBT(NBTTagCompound par1){ super.readFromNBT(par1); - filterItems = new ItemStack[FILTER_SIZE]; + this.filterItems = new ItemStack[FILTER_SIZE]; if (par1.hasKey("facing")){ - facing = EnumFacing.values()[par1.getInteger("facing")]; + this.facing = EnumFacing.values()[par1.getInteger("facing")]; } if (par1.hasKey("priority")){ @@ -242,20 +242,20 @@ public void readFromNBT(NBTTagCompound par1){ } if (success){ - elementalAttuner = new AMVector3(x, y, z); + this.elementalAttuner = new AMVector3(x, y, z); } } //Load filter items if (par1.hasKey("filterItems")){ NBTTagList filterItemsList = par1.getTagList("filterItems", Constants.NBT.TAG_COMPOUND); - filterItems = new ItemStack[getSizeInventory()]; + this.filterItems = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < filterItemsList.tagCount(); i++){ String tag = String.format("ArrayIndex", i); - NBTTagCompound nbttagcompound1 = (NBTTagCompound)filterItemsList.getCompoundTagAt(i); + NBTTagCompound nbttagcompound1 = filterItemsList.getCompoundTagAt(i); byte byte0 = nbttagcompound1.getByte(tag); - if (byte0 >= 0 && byte0 < filterItems.length){ - filterItems[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + if (byte0 >= 0 && byte0 < this.filterItems.length){ + this.filterItems[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } }//end if(par1.hasKey("filterItems")){ @@ -269,7 +269,7 @@ public void readFromNBT(NBTTagCompound par1){ double maxx = connectedBoundingBoxDimensions.getDouble("maxx"); double maxy = connectedBoundingBoxDimensions.getDouble("maxy"); double maxz = connectedBoundingBoxDimensions.getDouble("maxz"); - connectedBoundingBox = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); + this.connectedBoundingBox = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz); } } @@ -287,20 +287,20 @@ public ItemStack getStackInSlot(int i){ if (i > FILTER_SIZE){ return null; } - return filterItems[i]; + return this.filterItems[i]; } @Override public ItemStack decrStackSize(int i, int j){ - if (filterItems[i] != null){ - if (filterItems[i].stackSize <= j){ - ItemStack itemstack = filterItems[i]; - filterItems[i] = null; + if (this.filterItems[i] != null){ + if (this.filterItems[i].stackSize <= j){ + ItemStack itemstack = this.filterItems[i]; + this.filterItems[i] = null; return itemstack; } - ItemStack itemstack1 = filterItems[i].splitStack(j); - if (filterItems[i].stackSize == 0){ - filterItems[i] = null; + ItemStack itemstack1 = this.filterItems[i].splitStack(j); + if (this.filterItems[i].stackSize == 0){ + this.filterItems[i] = null; } return itemstack1; }else{ @@ -310,9 +310,9 @@ public ItemStack decrStackSize(int i, int j){ @Override public ItemStack removeStackFromSlot(int i){ - if (filterItems[i] != null){ - ItemStack itemstack = filterItems[i]; - filterItems[i] = null; + if (this.filterItems[i] != null){ + ItemStack itemstack = this.filterItems[i]; + this.filterItems[i] = null; return itemstack; }else{ return null; @@ -321,9 +321,9 @@ public ItemStack removeStackFromSlot(int i){ @Override public void setInventorySlotContents(int i, ItemStack itemstack){ - filterItems[i] = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()){ - itemstack.stackSize = getInventoryStackLimit(); + this.filterItems[i] = itemstack; + if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){ + itemstack.stackSize = this.getInventoryStackLimit(); } } @@ -348,10 +348,10 @@ public int getInventoryStackLimit(){ @Override public boolean isUseableByPlayer(EntityPlayer entityplayer){ - if (worldObj.getTileEntity(pos) != this){ + if (this.worldObj.getTileEntity(this.pos) != this){ return false; } - return entityplayer.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) <= 64D; + return entityplayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64D; } @Override @@ -373,7 +373,7 @@ public boolean isItemValidForSlot(int i, ItemStack itemstack){ public SPacketUpdateTileEntity getUpdatePacket(){ NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); - return new SPacketUpdateTileEntity(pos, 1, nbt); + return new SPacketUpdateTileEntity(this.pos, 1, nbt); } @Override @@ -383,14 +383,14 @@ public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ @Override public AxisAlignedBB getRenderBoundingBox(){ - return new AxisAlignedBB(pos); + return new AxisAlignedBB(this.pos); } public void linkToHabitat(AMVector3 habLocation, EntityPlayer player){ - TileEntity te = worldObj.getTileEntity(habLocation.toBlockPos()); + TileEntity te = this.worldObj.getTileEntity(habLocation.toBlockPos()); if (te instanceof TileEntityFlickerHabitat){ - AMVector3 myLocation = new AMVector3(pos); + AMVector3 myLocation = new AMVector3(this.pos); boolean setElementalAttuner = false; if (myLocation.distanceSqTo(habLocation) <= SEARCH_RADIUS){ @@ -452,12 +452,14 @@ public void clear() { @Override public void update() { - if (!worldObj.isRemote && worldObj.getBlockState(pos).getValue(BlockCrystalMarker.FACING) != facing) { - IBlockState prev = worldObj.getBlockState(pos); - worldObj.setBlockState(pos, prev.withProperty(BlockCrystalMarker.FACING, facing)); - for (EntityPlayerMP player : this.worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB(pos).expand(64, 64, 64))){ - player.connection.sendPacket(getUpdatePacket()); - } + if (!this.worldObj.isRemote) { + IBlockState state = this.worldObj.getBlockState(this.pos); + if (!state.getValue(BlockCrystalMarker.FACING).equals(facing)) + this.worldObj.setBlockState(this.pos, state.withProperty(BlockCrystalMarker.FACING, this.facing), 3); + //This is probably the fastest I can get it to go. + //If you know of any better way, please feel free to suggest it. + if (++tickCount % 20 == 0) + this.worldObj.notifyBlockUpdate(this.pos, state, state, 2); } } diff --git a/src/main/java/am2/common/blocks/tileentity/TileEntityInertSpawner.java b/src/main/java/am2/common/blocks/tileentity/TileEntityInertSpawner.java index 1df56766d..9a87cfdfd 100644 --- a/src/main/java/am2/common/blocks/tileentity/TileEntityInertSpawner.java +++ b/src/main/java/am2/common/blocks/tileentity/TileEntityInertSpawner.java @@ -1,267 +1,268 @@ -package am2.common.blocks.tileentity; - -import java.util.ArrayList; -import java.util.List; - -import com.google.common.collect.Lists; - -import am2.common.defs.ItemDefs; -import am2.common.items.ItemCrystalPhylactery; -import am2.common.power.PowerNodeRegistry; -import am2.common.power.PowerTypes; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.server.SPacketUpdateTileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; - -public class TileEntityInertSpawner extends TileEntityAMPower implements ISidedInventory{ - - private ItemStack phylactery; - private float powerConsumed = 0.0f; - - private static final ArrayList valid = Lists.newArrayList(PowerTypes.DARK); - - private static final float SUMMON_REQ = 6000; - - public TileEntityInertSpawner(){ - super(500); - } - - @Override - public boolean canRelayPower(PowerTypes type){ - return false; - } - - @Override - public int getChargeRate(){ - return 100; - } - - @Override - public int getSizeInventory(){ - return 1; - } - - @Override - public ItemStack getStackInSlot(int i){ - if (i < getSizeInventory() && phylactery != null){ - return phylactery; - } - - return null; - } - - @Override - public ItemStack decrStackSize(int i, int j){ - if (i < getSizeInventory() && phylactery != null){ - ItemStack jar = phylactery; - phylactery = null; - return jar; - } - return null; - } - - @Override - public ItemStack removeStackFromSlot(int i){ - if (i < getSizeInventory() && phylactery != null){ - ItemStack jar = phylactery; - phylactery = null; - return jar; - } - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack){ - phylactery = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()){ - itemstack.stackSize = getInventoryStackLimit(); - } - - } - - @Override - public String getName(){ - return "Inert Spawner"; - } - - @Override - public int getInventoryStackLimit(){ - return 1; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer){ - if (worldObj.getTileEntity(pos) != this){ - return false; - } - - return entityplayer.getDistanceSqToCenter(pos) <= 64D; - } - - @Override - public void openInventory(EntityPlayer player){ - } - - @Override - public void closeInventory(EntityPlayer player){ - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack stack){ - return i == 0 && stack != null && stack.getItem() == ItemDefs.crystalPhylactery; - } - - @Override - public boolean hasCustomName(){ - return false; - } - - @Override - public int[] getSlotsForFace(EnumFacing p_94128_1_){ - return new int[]{0}; - } - - @Override - public boolean canInsertItem(int i, ItemStack stack, EnumFacing face){ - return - i == 0 && - this.getStackInSlot(0) == null && - stack != null && - stack.getItem() == ItemDefs.crystalPhylactery && - stack.stackSize == 1 && - ((ItemCrystalPhylactery)stack.getItem()).isFull(stack); - } - - @Override - public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, EnumFacing p_102008_3_){ - return true; - } - - @Override - public SPacketUpdateTileEntity getUpdatePacket(){ - NBTTagCompound nbt = new NBTTagCompound(); - this.writeToNBT(nbt); - return new SPacketUpdateTileEntity(pos, 1, nbt); - } - - @Override - public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ - this.readFromNBT(pkt.getNbtCompound()); - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ - super.writeToNBT(nbttagcompound); - - if (phylactery != null){ - NBTTagCompound phy = new NBTTagCompound(); - phylactery.writeToNBT(phy); - nbttagcompound.setTag("phylactery", phy); - } - - nbttagcompound.setFloat("powerConsumed", powerConsumed); - return nbttagcompound; - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound){ - super.readFromNBT(nbttagcompound); - - - if (nbttagcompound.hasKey("phylactery")){ - NBTTagCompound phy = nbttagcompound.getCompoundTag("phylactery"); - phylactery = ItemStack.loadItemStackFromNBT(phy); - } - - this.powerConsumed = nbttagcompound.getFloat("powerConsumed"); - } - - public void update(){ - super.update(); - - if (!worldObj.isRemote && phylactery != null && phylactery.getItem() instanceof ItemCrystalPhylactery && ((ItemCrystalPhylactery)phylactery.getItem()).isFull(phylactery) && worldObj.isBlockIndirectlyGettingPowered(pos) == 0){ - if (this.powerConsumed < TileEntityInertSpawner.SUMMON_REQ){ - this.powerConsumed += PowerNodeRegistry.For(worldObj).consumePower( - this, - PowerTypes.DARK, - Math.min(this.getCapacity(), TileEntityInertSpawner.SUMMON_REQ - this.powerConsumed) - ); - }else{ - this.powerConsumed = 0; - ItemCrystalPhylactery item = (ItemCrystalPhylactery)this.phylactery.getItem(); - if (item.isFull(phylactery)){ - String clazzName = item.getSpawnClass(phylactery); - if (clazzName != null){ - Class clazz = (Class)EntityList.NAME_TO_CLASS.get(clazzName); - if (clazz != null){ - EntityLiving entity = null; - try{ - entity = (EntityLiving)clazz.getConstructor(World.class).newInstance(worldObj); - }catch (Throwable t){ - t.printStackTrace(); - return; - } - if (entity == null) - return; - setEntityPosition(entity); - worldObj.spawnEntityInWorld(entity); - } - } - } - } - } - } - - private void setEntityPosition(EntityLiving e){ - for (EnumFacing dir : EnumFacing.values()){ - if (worldObj.isAirBlock(pos.offset(dir))){ - e.setPosition(pos.offset(dir).getX(), pos.offset(dir).getY(), pos.offset(dir).getZ()); - return; - } - } - e.setPosition(pos.getX(), pos.getY(), pos.getZ()); - } - - @Override - public List getValidPowerTypes(){ - return valid; - } - - @Override - public int getField(int id) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setField(int id, int value) { - // TODO Auto-generated method stub - - } - - @Override - public int getFieldCount() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void clear() { - // TODO Auto-generated method stub - - } - - @Override - public ITextComponent getDisplayName() { - // TODO Auto-generated method stub - return null; - } -} +package am2.common.blocks.tileentity; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.Lists; + +import am2.common.defs.ItemDefs; +import am2.common.items.ItemCrystalPhylactery; +import am2.common.power.PowerNodeRegistry; +import am2.common.power.PowerTypes; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.World; + +public class TileEntityInertSpawner extends TileEntityAMPower implements ISidedInventory{ + + private ItemStack phylactery; + private float powerConsumed = 0.0f; + + private static final ArrayList valid = Lists.newArrayList(PowerTypes.DARK); + + private static final float SUMMON_REQ = 6000; + + public TileEntityInertSpawner(){ + super(500); + } + + @Override + public boolean canRelayPower(PowerTypes type){ + return false; + } + + @Override + public int getChargeRate(){ + return 100; + } + + @Override + public int getSizeInventory(){ + return 1; + } + + @Override + public ItemStack getStackInSlot(int i){ + if (i < getSizeInventory() && phylactery != null){ + return phylactery; + } + + return null; + } + + @Override + public ItemStack decrStackSize(int i, int j){ + if (i < getSizeInventory() && phylactery != null){ + ItemStack jar = phylactery; + phylactery = null; + return jar; + } + return null; + } + + @Override + public ItemStack removeStackFromSlot(int i){ + if (i < getSizeInventory() && phylactery != null){ + ItemStack jar = phylactery; + phylactery = null; + return jar; + } + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack){ + phylactery = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()){ + itemstack.stackSize = getInventoryStackLimit(); + } + + } + + @Override + public String getName(){ + return "Inert Spawner"; + } + + @Override + public int getInventoryStackLimit(){ + return 1; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer){ + if (worldObj.getTileEntity(pos) != this){ + return false; + } + + return entityplayer.getDistanceSqToCenter(pos) <= 64D; + } + + @Override + public void openInventory(EntityPlayer player){ + } + + @Override + public void closeInventory(EntityPlayer player){ + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack stack){ + return i == 0 && stack != null && stack.getItem() == ItemDefs.crystalPhylactery; + } + + @Override + public boolean hasCustomName(){ + return false; + } + + @Override + public int[] getSlotsForFace(EnumFacing p_94128_1_){ + return new int[]{0}; + } + + @Override + public boolean canInsertItem(int i, ItemStack stack, EnumFacing face){ + return + i == 0 && + this.getStackInSlot(0) == null && + stack != null && + stack.getItem() == ItemDefs.crystalPhylactery && + stack.stackSize == 1 && + ((ItemCrystalPhylactery)stack.getItem()).isFull(stack); + } + + @Override + public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, EnumFacing p_102008_3_){ + return true; + } + + @Override + public SPacketUpdateTileEntity getUpdatePacket(){ + NBTTagCompound nbt = new NBTTagCompound(); + this.writeToNBT(nbt); + return new SPacketUpdateTileEntity(pos, 1, nbt); + } + + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ + this.readFromNBT(pkt.getNbtCompound()); + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound){ + super.writeToNBT(nbttagcompound); + + if (phylactery != null){ + NBTTagCompound phy = new NBTTagCompound(); + phylactery.writeToNBT(phy); + nbttagcompound.setTag("phylactery", phy); + } + + nbttagcompound.setFloat("powerConsumed", powerConsumed); + return nbttagcompound; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound){ + super.readFromNBT(nbttagcompound); + + + if (nbttagcompound.hasKey("phylactery")){ + NBTTagCompound phy = nbttagcompound.getCompoundTag("phylactery"); + phylactery = ItemStack.loadItemStackFromNBT(phy); + } + + this.powerConsumed = nbttagcompound.getFloat("powerConsumed"); + } + + @Override + public void update(){ + super.update(); + + if (!worldObj.isRemote && phylactery != null && phylactery.getItem() instanceof ItemCrystalPhylactery && ((ItemCrystalPhylactery)phylactery.getItem()).isFull(phylactery) && worldObj.isBlockIndirectlyGettingPowered(pos) == 0){ + if (this.powerConsumed < TileEntityInertSpawner.SUMMON_REQ){ + this.powerConsumed += PowerNodeRegistry.For(worldObj).consumePower( + this, + PowerTypes.DARK, + Math.min(this.getCapacity(), TileEntityInertSpawner.SUMMON_REQ - this.powerConsumed) + ); + }else{ + this.powerConsumed = 0; + ItemCrystalPhylactery item = (ItemCrystalPhylactery)this.phylactery.getItem(); + if (item.isFull(phylactery)){ + String clazzName = item.getSpawnClass(phylactery); + if (clazzName != null){ + Class clazz = (Class)EntityList.NAME_TO_CLASS.get(clazzName); + if (clazz != null){ + EntityLiving entity = null; + try{ + entity = (EntityLiving)clazz.getConstructor(World.class).newInstance(worldObj); + }catch (Throwable t){ + t.printStackTrace(); + return; + } + if (entity == null) + return; + setEntityPosition(entity); + worldObj.spawnEntityInWorld(entity); + } + } + } + } + } + } + + private void setEntityPosition(EntityLiving e){ + for (EnumFacing dir : EnumFacing.values()){ + if (worldObj.isAirBlock(pos.offset(dir))){ + e.setPosition(pos.offset(dir).getX(), pos.offset(dir).getY(), pos.offset(dir).getZ()); + return; + } + } + e.setPosition(pos.getX(), pos.getY(), pos.getZ()); + } + + @Override + public List getValidPowerTypes(){ + return valid; + } + + @Override + public int getField(int id) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setField(int id, int value) { + // TODO Auto-generated method stub + + } + + @Override + public int getFieldCount() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void clear() { + // TODO Auto-generated method stub + + } + + @Override + public ITextComponent getDisplayName() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/am2/common/blocks/tileentity/TileEntityLectern.java b/src/main/java/am2/common/blocks/tileentity/TileEntityLectern.java index 3c9a74921..0fb47a93f 100644 --- a/src/main/java/am2/common/blocks/tileentity/TileEntityLectern.java +++ b/src/main/java/am2/common/blocks/tileentity/TileEntityLectern.java @@ -1,229 +1,237 @@ -package am2.common.blocks.tileentity; - -import java.util.ArrayList; - -import am2.ArsMagica2; -import am2.client.particles.AMParticle; -import am2.client.particles.ParticleFadeOut; -import am2.client.particles.ParticleMoveOnHeading; -import am2.common.defs.ItemDefs; -import am2.common.packet.AMDataWriter; -import am2.common.packet.AMNetHandler; -import am2.common.packet.AMPacketIDs; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.server.SPacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntityEnchantmentTable; -import net.minecraft.util.ITickable; -import net.minecraft.util.math.MathHelper; - -public class TileEntityLectern extends TileEntityEnchantmentTable implements ITickable{ - private ItemStack stack; - private ItemStack tooltipStack; - private boolean needsBook; - private boolean overPowered; - public int particleAge; - public int particleMaxAge = 150; - private boolean increasing = true; - - public TileEntityLectern(){ - - } - - public void resetParticleAge(){ - particleAge = 0; - increasing = true; - } - - public ItemStack getTooltipStack(){ - return tooltipStack; - } - - public void setTooltipStack(ItemStack stack){ - this.tooltipStack = stack; - } - - @Override - public void update(){ - if (worldObj.isRemote){ - updateBookRender(); - if (tooltipStack != null && tickCount % 2 == 0){ - AMParticle particle = (AMParticle)ArsMagica2.proxy.particleManager.spawn(worldObj, "sparkle", pos.getX() + 0.5 + ((worldObj.rand.nextDouble() * 0.2) - 0.1), pos.getY() + 1, pos.getZ() + 0.5 + ((worldObj.rand.nextDouble() * 0.2) - 0.1)); - if (particle != null){ - particle.AddParticleController(new ParticleMoveOnHeading(particle, worldObj.rand.nextDouble() * 360, -45 - worldObj.rand.nextInt(90), 0.05f, 1, false)); - particle.AddParticleController(new ParticleFadeOut(particle, 2, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true)); - particle.setIgnoreMaxAge(true); - if (getOverpowered()){ - particle.setRGBColorF(1.0f, 0.2f, 0.2f); - } - } - } - } - } - - private void updateBookRender() { - particleAge++; - if (increasing){ - particleMaxAge += 2; - if (particleMaxAge - particleAge > 120) - increasing = false; - }else{ - if (particleMaxAge - particleAge < 5) - increasing = true; - } - this.bookSpreadPrev = this.bookSpread; - this.bookRotationPrev = this.bookRotation; - - this.bookSpread += 0.1F; - - if (this.bookSpread < 0.5F || worldObj.rand.nextInt(40) == 0){ - float f1 = this.flipT; - - do{ - this.flipT += (float)(worldObj.rand.nextInt(4) - worldObj.rand.nextInt(4)); - } - while (f1 == this.flipT); - } - - while (this.bookRotation >= (float)Math.PI){ - this.bookRotation -= ((float)Math.PI * 2F); - } - - while (this.bookRotation < -(float)Math.PI){ - this.bookRotation += ((float)Math.PI * 2F); - } - - while (this.tRot >= (float)Math.PI){ - this.tRot -= ((float)Math.PI * 2F); - } - - while (this.tRot < -(float)Math.PI){ - this.tRot += ((float)Math.PI * 2F); - } - - float f2; - - for (f2 = this.tRot - this.bookRotation; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F)); - - while (f2 < -(float)Math.PI){ - f2 += ((float)Math.PI * 2F); - } - - this.bookRotation += f2 * 0.4F; - - if (this.bookSpread < 0.0F){ - this.bookSpread = 0.0F; - } - - if (this.bookSpread > 1.0F){ - this.bookSpread = 1.0F; - } - - ++this.tickCount; - this.pageFlipPrev = this.pageFlip; - float f = (this.flipT - this.pageFlip) * 0.4F; - float f3 = 0.2F; - f = MathHelper.clamp_float(f, -f3, f3); - this.flipA += (f - this.flipA) * 0.9F; - this.pageFlip += this.flipA; - } - - public ItemStack getStack(){ - return stack; - } - - public boolean setStack(ItemStack stack){ - if (stack == null || getValidItems().contains(stack.getItem())){ - if (stack != null) - stack.stackSize = 1; - this.stack = stack; - if (!this.worldObj.isRemote){ - AMDataWriter writer = new AMDataWriter(); - writer.add(pos.getX()); - writer.add(pos.getY()); - writer.add(pos.getZ()); - if (stack == null){ - writer.add(false); - }else{ - writer.add(true); - writer.add(stack); - } - AMNetHandler.INSTANCE.sendPacketToAllClientsNear(worldObj.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 32, AMPacketIDs.LECTERN_DATA, writer.generate()); - } - return true; - } - return false; - } - - public boolean hasStack(){ - return stack != null; - } - - @Override - public SPacketUpdateTileEntity getUpdatePacket(){ - NBTTagCompound compound = new NBTTagCompound(); - writeToNBT(compound); - SPacketUpdateTileEntity packet = new SPacketUpdateTileEntity(pos, getBlockMetadata(), compound); - return packet; - } - - @Override - public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ - this.readFromNBT(pkt.getNbtCompound()); - } - - private ArrayList getValidItems(){ - ArrayList validItems = new ArrayList(); - - validItems.add(Items.WRITTEN_BOOK); - validItems.add(ItemDefs.arcaneCompendium); - -// if (Loader.isModLoaded("Thaumcraft")){ -// ItemStack item = thaumcraft.api.ItemApi.getItem("itemThaumonomicon", 0); -// if (item != null){ -// validItems.add(item.getItem()); -// } -// } - - return validItems; - } - - @Override - public void readFromNBT(NBTTagCompound comp){ - super.readFromNBT(comp); - if (comp.hasKey("placedBook")){ - NBTTagCompound bewk = comp.getCompoundTag("placedBook"); - stack = ItemStack.loadItemStackFromNBT(bewk); - } - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound comp){ - super.writeToNBT(comp); - if (stack != null){ - NBTTagCompound bewk = new NBTTagCompound(); - stack.writeToNBT(bewk); - comp.setTag("placedBook", bewk); - } - return comp; - } - - public void setNeedsBook(boolean b){ - this.needsBook = b; - } - - public boolean getNeedsBook(){ - return this.needsBook; - } - - public void setOverpowered(boolean b){ - this.overPowered = b; - } - - public boolean getOverpowered(){ - return this.overPowered; - } -} +package am2.common.blocks.tileentity; + +import java.util.ArrayList; + +import am2.ArsMagica2; +import am2.client.particles.AMParticle; +import am2.client.particles.ParticleFadeOut; +import am2.client.particles.ParticleMoveOnHeading; +import am2.common.defs.ItemDefs; +import am2.common.packet.AMDataWriter; +import am2.common.packet.AMNetHandler; +import am2.common.packet.AMPacketIDs; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntityEnchantmentTable; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.MathHelper; + +public class TileEntityLectern extends TileEntityEnchantmentTable implements ITickable{ + private ItemStack stack; + private ItemStack tooltipStack; + private boolean needsBook; + private boolean overPowered; + public int particleAge; + public int particleMaxAge = 150; + private boolean increasing = true; + + public TileEntityLectern(){ + + } + + public void resetParticleAge(){ + particleAge = 0; + increasing = true; + } + + public ItemStack getTooltipStack(){ + return tooltipStack; + } + + public void setTooltipStack(ItemStack stack){ + this.tooltipStack = stack; + } + + @Override + public void update(){ + if (worldObj.isRemote){ + updateBookRender(); + if (tooltipStack != null && tickCount % 2 == 0){ + AMParticle particle = (AMParticle)ArsMagica2.proxy.particleManager.spawn(worldObj, "sparkle", pos.getX() + 0.5 + ((worldObj.rand.nextDouble() * 0.2) - 0.1), pos.getY() + 1, pos.getZ() + 0.5 + ((worldObj.rand.nextDouble() * 0.2) - 0.1)); + if (particle != null){ + particle.AddParticleController(new ParticleMoveOnHeading(particle, worldObj.rand.nextDouble() * 360, -45 - worldObj.rand.nextInt(90), 0.05f, 1, false)); + particle.AddParticleController(new ParticleFadeOut(particle, 2, false).setFadeSpeed(0.05f).setKillParticleOnFinish(true)); + particle.setIgnoreMaxAge(true); + if (getOverpowered()){ + particle.setRGBColorF(1.0f, 0.2f, 0.2f); + } + } + } + } else if (tickCount % 20 == 0){ + IBlockState state = this.worldObj.getBlockState(this.pos); + //This is probably the fastest I can get it to go. + //If you know of any better way, please feel free to suggest it. + this.worldObj.notifyBlockUpdate(this.pos, state, state, 2); + } + } + + private void updateBookRender() { + particleAge++; + if (increasing){ + particleMaxAge += 2; + if (particleMaxAge - particleAge > 120) + increasing = false; + }else{ + if (particleMaxAge - particleAge < 5) + increasing = true; + } + this.bookSpreadPrev = this.bookSpread; + this.bookRotationPrev = this.bookRotation; + + this.bookSpread += 0.1F; + + if (this.bookSpread < 0.5F || worldObj.rand.nextInt(40) == 0){ + float f1 = this.flipT; + + do{ + this.flipT += (float)(worldObj.rand.nextInt(4) - worldObj.rand.nextInt(4)); + } + while (f1 == this.flipT); + } + + while (this.bookRotation >= (float)Math.PI){ + this.bookRotation -= ((float)Math.PI * 2F); + } + + while (this.bookRotation < -(float)Math.PI){ + this.bookRotation += ((float)Math.PI * 2F); + } + + while (this.tRot >= (float)Math.PI){ + this.tRot -= ((float)Math.PI * 2F); + } + + while (this.tRot < -(float)Math.PI){ + this.tRot += ((float)Math.PI * 2F); + } + + float f2; + + for (f2 = this.tRot - this.bookRotation; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F)); + + while (f2 < -(float)Math.PI){ + f2 += ((float)Math.PI * 2F); + } + + this.bookRotation += f2 * 0.4F; + + if (this.bookSpread < 0.0F){ + this.bookSpread = 0.0F; + } + + if (this.bookSpread > 1.0F){ + this.bookSpread = 1.0F; + } + + ++this.tickCount; + this.pageFlipPrev = this.pageFlip; + float f = (this.flipT - this.pageFlip) * 0.4F; + float f3 = 0.2F; + f = MathHelper.clamp_float(f, -f3, f3); + this.flipA += (f - this.flipA) * 0.9F; + this.pageFlip += this.flipA; + } + + public ItemStack getStack(){ + return stack; + } + + public boolean setStack(ItemStack stack){ + if (stack == null || getValidItems().contains(stack.getItem())){ + if (stack != null) + stack.stackSize = 1; + this.stack = stack; + if (!this.worldObj.isRemote){ + AMDataWriter writer = new AMDataWriter(); + writer.add(pos.getX()); + writer.add(pos.getY()); + writer.add(pos.getZ()); + if (stack == null){ + writer.add(false); + }else{ + writer.add(true); + writer.add(stack); + } + AMNetHandler.INSTANCE.sendPacketToAllClientsNear(worldObj.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 32, AMPacketIDs.LECTERN_DATA, writer.generate()); + } + return true; + } + return false; + } + + public boolean hasStack(){ + return stack != null; + } + + @Override + public SPacketUpdateTileEntity getUpdatePacket(){ + NBTTagCompound compound = new NBTTagCompound(); + writeToNBT(compound); + SPacketUpdateTileEntity packet = new SPacketUpdateTileEntity(pos, getBlockMetadata(), compound); + return packet; + } + + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){ + this.readFromNBT(pkt.getNbtCompound()); + } + + private ArrayList getValidItems(){ + ArrayList validItems = new ArrayList(); + + validItems.add(Items.WRITTEN_BOOK); + validItems.add(ItemDefs.arcaneCompendium); + +// if (Loader.isModLoaded("Thaumcraft")){ +// ItemStack item = thaumcraft.api.ItemApi.getItem("itemThaumonomicon", 0); +// if (item != null){ +// validItems.add(item.getItem()); +// } +// } + + return validItems; + } + + @Override + public void readFromNBT(NBTTagCompound comp){ + super.readFromNBT(comp); + if (comp.hasKey("placedBook")){ + NBTTagCompound bewk = comp.getCompoundTag("placedBook"); + stack = ItemStack.loadItemStackFromNBT(bewk); + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound comp){ + super.writeToNBT(comp); + if (stack != null){ + NBTTagCompound bewk = new NBTTagCompound(); + stack.writeToNBT(bewk); + comp.setTag("placedBook", bewk); + } + return comp; + } + + public void setNeedsBook(boolean b){ + this.needsBook = b; + } + + public boolean getNeedsBook(){ + return this.needsBook; + } + + public void setOverpowered(boolean b){ + this.overPowered = b; + } + + public boolean getOverpowered(){ + return this.overPowered; + } +}