Optimizing a ton of stuff in the block classes

This commit is contained in:
pahimar 2014-01-02 02:21:46 -05:00
parent 2b66e13ff2
commit 898e7b44f6
11 changed files with 193 additions and 458 deletions

View file

@ -5,18 +5,13 @@ import com.pahimar.ee3.lib.GuiIds;
import com.pahimar.ee3.lib.RenderIds;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.tileentity.TileAlchemicalChest;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import java.util.Random;
/**
* Equivalent-Exchange-3
* <p/>
@ -24,14 +19,8 @@ import java.util.Random;
*
* @author pahimar
*/
public class BlockAlchemicalChest extends BlockContainerEE
public class BlockAlchemicalChest extends BlockEE implements ITileEntityProvider
{
/**
* Is the random generator used by alchemical chest to drop the inventory contents in random directions.
*/
private Random rand = new Random();
public BlockAlchemicalChest(int id)
{
super(id, Material.wood);
@ -41,12 +30,6 @@ public class BlockAlchemicalChest extends BlockContainerEE
this.setCreativeTab(EquivalentExchange3.tabsEE3);
}
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, Strings.ALCHEMICAL_CHEST_NAME);
}
@Override
public TileEntity createNewTileEntity(World world)
{
@ -72,21 +55,10 @@ public class BlockAlchemicalChest extends BlockContainerEE
return RenderIds.alchemicalChestRender;
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta)
{
dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, id, meta);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (player.isSneaking())
{
return true;
}
else if (world.isBlockSolidOnSide(x, y + 1, z, ForgeDirection.DOWN))
if (player.isSneaking() || world.isBlockSolidOnSide(x, y + 1, z, ForgeDirection.DOWN))
{
return true;
}
@ -94,9 +66,7 @@ public class BlockAlchemicalChest extends BlockContainerEE
{
if (!world.isRemote)
{
TileAlchemicalChest tileAlchemicalChest = (TileAlchemicalChest) world.getBlockTileEntity(x, y, z);
if (tileAlchemicalChest != null)
if (world.getBlockTileEntity(x, y, z) instanceof TileAlchemicalChest)
{
player.openGui(EquivalentExchange3.instance, GuiIds.ALCHEMICAL_CHEST, world, x, y, z);
}
@ -105,43 +75,4 @@ public class BlockAlchemicalChest extends BlockContainerEE
return true;
}
}
private void dropInventory(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0)
{
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
}

View file

@ -20,7 +20,7 @@ public class BlockAlchemicalFuel extends BlockEE
public BlockAlchemicalFuel(int id)
{
super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_FUEL_BLOCK_NAME);
this.setUnlocalizedName(Strings.ALCHEMICAL_FUEL_BLOCK_NAME);
this.setHardness(5.0F);
this.setResistance(10.0F);
}

View file

@ -1,22 +1,23 @@
package com.pahimar.ee3.block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class BlockAlchemySquare extends BlockContainerEE
public class BlockAlchemySquare extends BlockEE implements ITileEntityProvider
{
public BlockAlchemySquare(int id)
{
super(id);
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*
* @param world
*/
@Override
public TileEntity createNewTileEntity(World world)
{
return createTileEntity(world, 0);
}
@Override
public TileEntity createTileEntity(World world, int metadata)
{
return null;
}

View file

@ -6,20 +6,16 @@ import com.pahimar.ee3.lib.RenderIds;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.tileentity.TileAludel;
import com.pahimar.ee3.tileentity.TileGlassBell;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import java.util.Random;
/**
* Equivalent-Exchange-3
* <p/>
@ -27,30 +23,17 @@ import java.util.Random;
*
* @author pahimar
*/
public class BlockAludelBase extends BlockContainerEE
public class BlockAludelBase extends BlockEE implements ITileEntityProvider
{
/**
* Is the random generator used by aludel to drop the inventory contents in random directions.
*/
private Random rand = new Random();
public BlockAludelBase(int id)
{
super(id, Material.anvil);
this.setUnlocalizedName(Strings.ALUDEL_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 1.0F, 0.9375F);
this.setBlockBounds(0.10F, 0.0F, 0.10F, 0.90F, 1.0F, 0.90F);
this.setHardness(5F);
}
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, Strings.ALUDEL_NAME);
}
@Override
public TileEntity createNewTileEntity(World world)
{
@ -79,9 +62,6 @@ public class BlockAludelBase extends BlockContainerEE
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta)
{
dropInventory(world, x, y, z);
if (world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell)
{
world.markBlockForUpdate(x, y + 1, z);
@ -94,7 +74,6 @@ public class BlockAludelBase extends BlockContainerEE
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (player.isSneaking())
{
return false;
@ -103,9 +82,7 @@ public class BlockAludelBase extends BlockContainerEE
{
if (!world.isRemote)
{
TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y, z);
if (tileAludel != null)
if (world.getBlockTileEntity(x, y, z) instanceof TileAludel && world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell)
{
player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y, z);
}
@ -118,19 +95,16 @@ public class BlockAludelBase extends BlockContainerEE
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
if (world.getBlockTileEntity(x, y + 1, z) != null && world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell)
if (world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell)
{
TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y + 1, z);
tileGlassBell.setOrientation(ForgeDirection.UP);
if (world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof TileAludel)
if (world.getBlockTileEntity(x, y, z) instanceof TileAludel)
{
TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y, z);
ItemStack itemStackGlassBell = tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX);
@ -145,47 +119,7 @@ public class BlockAludelBase extends BlockContainerEE
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
// TODO Vary light levels depending on if we are burning or not
return 0;
}
private void dropInventory(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0)
{
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
}

View file

@ -6,13 +6,11 @@ import com.pahimar.ee3.lib.Particles;
import com.pahimar.ee3.lib.RenderIds;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.tileentity.TileCalcinator;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.Random;
@ -24,13 +22,8 @@ import java.util.Random;
*
* @author pahimar
*/
public class BlockCalcinator extends BlockContainerEE
public class BlockCalcinator extends BlockEE implements ITileEntityProvider
{
/**
* Is the random generator used by calcinator to drop the inventory contents in random directions.
*/
private Random rand = new Random();
public BlockCalcinator(int id)
{
super(id, Material.rock);
@ -40,12 +33,6 @@ public class BlockCalcinator extends BlockContainerEE
this.setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 1.0F, 0.9F);
}
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, Strings.CALCINATOR_NAME);
}
@Override
public TileEntity createNewTileEntity(World world)
{
@ -64,6 +51,13 @@ public class BlockCalcinator extends BlockContainerEE
return false;
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
// TODO Vary light levels depending on whether or not we are calcinating something
return super.getLightValue(world, x, y, z);
}
@Override
public int getRenderType()
{
@ -71,13 +65,6 @@ public class BlockCalcinator extends BlockContainerEE
return RenderIds.calcinatorRender;
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta)
{
dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, id, meta);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
@ -89,9 +76,7 @@ public class BlockCalcinator extends BlockContainerEE
{
if (!world.isRemote)
{
TileCalcinator tileCalcinator = (TileCalcinator) world.getBlockTileEntity(x, y, z);
if (tileCalcinator != null)
if (world.getBlockTileEntity(x, y, z) instanceof TileCalcinator)
{
player.openGui(EquivalentExchange3.instance, GuiIds.CALCINATOR, world, x, y, z);
}
@ -109,6 +94,7 @@ public class BlockCalcinator extends BlockContainerEE
if (((TileCalcinator) world.getBlockTileEntity(x, y, z)).isBurning())
{
// Fire pot particles
// TODO TileEntity.onClientEvent to update particles
world.spawnParticle(Particles.NORMAL_SMOKE, (double) x + 0.5F, (double) y + 0.4F, (double) ((z + 0.5F) + (random.nextFloat() * 0.5F - 0.3F)), 0.0D, 0.0D, 0.0D);
world.spawnParticle(Particles.FLAME, (double) x + 0.5F, (double) y + 0.4F, (double) z + 0.5F, 0.0D, 0.0D, 0.0D);
@ -117,43 +103,4 @@ public class BlockCalcinator extends BlockContainerEE
}
}
}
private void dropInventory(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0)
{
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
}

View file

@ -12,7 +12,7 @@ public class BlockChalk extends BlockEE
{
super(id, Material.clay);
setHardness(0.6F);
setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.CHALK_NAME);
setUnlocalizedName(Strings.CHALK_NAME);
setStepSound(soundGravelFootstep);
}

View file

@ -1,82 +0,0 @@
package com.pahimar.ee3.block;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.tileentity.TileEE;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/**
* Equivalent-Exchange-3
* <p/>
* BlockContainerEE
*
* @author pahimar
*/
public abstract class BlockContainerEE extends BlockContainer
{
public BlockContainerEE(int id)
{
this(id, Material.rock);
}
public BlockContainerEE(int id, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
blockIcon = iconRegister.registerIcon(String.format("%s:%s", Reference.MOD_ID.toLowerCase(), getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
}
protected String getUnwrappedUnlocalizedName(String unlocalizedName)
{
return unlocalizedName.substring(unlocalizedName.indexOf(":") + 1);
}
/**
* Sets the direction of the block when placed
*/
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
int direction = 0;
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (facing == 0)
{
direction = ForgeDirection.NORTH.ordinal();
}
else if (facing == 1)
{
direction = ForgeDirection.EAST.ordinal();
}
else if (facing == 2)
{
direction = ForgeDirection.SOUTH.ordinal();
}
else if (facing == 3)
{
direction = ForgeDirection.WEST.ordinal();
}
world.setBlockMetadataWithNotify(x, y, z, direction, 3);
if (itemStack.hasDisplayName())
{
((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
}
((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
}
}

View file

@ -1,11 +1,23 @@
package com.pahimar.ee3.block;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.tileentity.TileEE;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
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.world.World;
import net.minecraftforge.common.ForgeDirection;
import java.util.Random;
public class BlockEE extends Block
{
@ -17,8 +29,12 @@ public class BlockEE extends Block
public BlockEE(int id, Material material)
{
super(id, material);
setStepSound(soundStoneFootstep);
setCreativeTab(EquivalentExchange3.tabsEE3);
}
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}
@Override
@ -32,4 +48,85 @@ public class BlockEE extends Block
{
return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta)
{
dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, id, meta);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
int direction = 0;
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (facing == 0)
{
direction = ForgeDirection.NORTH.ordinal();
}
else if (facing == 1)
{
direction = ForgeDirection.EAST.ordinal();
}
else if (facing == 2)
{
direction = ForgeDirection.SOUTH.ordinal();
}
else if (facing == 3)
{
direction = ForgeDirection.WEST.ordinal();
}
world.setBlockMetadataWithNotify(x, y, z, direction, 3);
if (itemStack.hasDisplayName())
{
((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
}
((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
}
protected void dropInventory(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0)
{
Random rand = new Random();
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
}

View file

@ -8,13 +8,11 @@ import com.pahimar.ee3.tileentity.TileAludel;
import com.pahimar.ee3.tileentity.TileEE;
import com.pahimar.ee3.tileentity.TileGlassBell;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
@ -22,49 +20,31 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import java.util.Random;
public class BlockGlassBell extends BlockContainerEE
public class BlockGlassBell extends BlockEE implements ITileEntityProvider
{
/**
* Is the random generator used by glass bell to drop the inventory contents in random directions.
*/
private Random rand = new Random();
public BlockGlassBell(int id)
{
super(id, Material.glass);
this.setUnlocalizedName(Strings.GLASS_BELL_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.setHardness(1.0F);
}
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Strings.RESOURCE_PREFIX, Strings.GLASS_BELL_NAME);
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileGlassBell();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@ -78,7 +58,6 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta)
{
dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, id, meta);
}
@ -86,7 +65,6 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (player.isSneaking())
{
return false;
@ -95,18 +73,16 @@ public class BlockGlassBell extends BlockContainerEE
{
if (!world.isRemote)
{
TileEntity tileEntityGlassBell = world.getBlockTileEntity(x, y, z);
TileEntity tileEntityAludel = world.getBlockTileEntity(x, y - 1, z);
if (tileEntityAludel instanceof TileAludel && tileEntityGlassBell instanceof TileGlassBell)
if (world.getBlockTileEntity(x, y, z) instanceof TileGlassBell)
{
player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y - 1, z);
return true;
}
if (tileEntityGlassBell != null)
{
player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_BELL, world, x, y, z);
if (world.getBlockTileEntity(x, y - 1, z) instanceof TileAludel)
{
player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y - 1, z);
}
else
{
player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_BELL, world, x, y, z);
}
}
}
@ -117,7 +93,6 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
if (itemStack.hasDisplayName())
{
((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
@ -138,7 +113,6 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public int onBlockPlaced(World world, int x, int y, int z, int sideHit, float hitX, float hitY, float hitZ, int metaData)
{
return sideHit;
}
@ -149,52 +123,45 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 startVec, Vec3 endVec)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
if (world.getBlockTileEntity(x, y, z) instanceof TileGlassBell)
{
if (tileEntity instanceof TileGlassBell)
TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z);
switch (tileGlassBell.getOrientation())
{
TileGlassBell tileGlassBell = (TileGlassBell) tileEntity;
switch (tileGlassBell.getOrientation())
case DOWN:
{
case DOWN:
{
this.setBlockBounds(0.125F, 0.33F, 0.125F, 0.875F, 1.0F, 0.875F);
break;
}
case UP:
{
this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F);
break;
}
case NORTH:
{
this.setBlockBounds(0.125F, 0.125F, 0.33F, 0.875F, 0.875F, 1.0F);
break;
}
case SOUTH:
{
this.setBlockBounds(0.125F, 0.125F, 0.0F, 0.875F, 0.875F, 0.66F);
break;
}
case EAST:
{
this.setBlockBounds(0.0F, 0.125F, 0.125F, 0.66F, 0.875F, 0.875F);
break;
}
case WEST:
{
this.setBlockBounds(0.33F, 0.125F, 0.125F, 1.0F, 0.875F, 0.875F);
break;
}
case UNKNOWN:
{
break;
}
this.setBlockBounds(0.125F, 0.33F, 0.125F, 0.875F, 1.0F, 0.875F);
break;
}
case UP:
{
this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F);
break;
}
case NORTH:
{
this.setBlockBounds(0.125F, 0.125F, 0.33F, 0.875F, 0.875F, 1.0F);
break;
}
case SOUTH:
{
this.setBlockBounds(0.125F, 0.125F, 0.0F, 0.875F, 0.875F, 0.66F);
break;
}
case EAST:
{
this.setBlockBounds(0.0F, 0.125F, 0.125F, 0.66F, 0.875F, 0.875F);
break;
}
case WEST:
{
this.setBlockBounds(0.33F, 0.125F, 0.125F, 1.0F, 0.875F, 0.875F);
break;
}
case UNKNOWN:
{
break;
}
}
}
@ -205,7 +172,6 @@ public class BlockGlassBell extends BlockContainerEE
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
ItemStack itemStack;
if (world.getBlockTileEntity(x, y, z) instanceof TileGlassBell)
@ -235,44 +201,4 @@ public class BlockGlassBell extends BlockContainerEE
return 0;
}
private void dropInventory(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0)
{
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
}

View file

@ -14,32 +14,30 @@ import cpw.mods.fml.common.registry.GameRegistry;
*/
public class ModBlocks
{
public static BlockEE alchemicalChest;
public static BlockEE alchemicalFuel;
public static BlockEE alchemySquare;
public static BlockEE aludelBase;
public static BlockEE calcinator;
public static BlockEE chalk;
public static BlockContainerEE alchemySquare;
public static BlockContainerEE calcinator;
public static BlockContainerEE aludelBase;
public static BlockContainerEE alchemicalChest;
public static BlockContainerEE glassBell;
public static BlockEE glassBell;
public static void init()
{
chalk = new BlockChalk(BlockIds.CHALK);
alchemicalChest = new BlockAlchemicalChest(BlockIds.ALCHEMICAL_CHEST);
alchemicalFuel = new BlockAlchemicalFuel(BlockIds.ALCHEMICAL_FUEL);
alchemySquare = new BlockAlchemySquare(BlockIds.ALCHEMY_SQUARE);
calcinator = new BlockCalcinator(BlockIds.CALCINATOR);
aludelBase = new BlockAludelBase(BlockIds.ALUDEL_BASE);
alchemicalChest = new BlockAlchemicalChest(BlockIds.ALCHEMICAL_CHEST);
calcinator = new BlockCalcinator(BlockIds.CALCINATOR);
chalk = new BlockChalk(BlockIds.CHALK);
glassBell = new BlockGlassBell(BlockIds.GLASS_BELL);
GameRegistry.registerBlock(alchemicalFuel, ItemAlchemicalFuelBlock.class, "block." + Strings.ALCHEMICAL_FUEL_NAME);
GameRegistry.registerBlock(chalk, "block." + Strings.CHALK_NAME);
GameRegistry.registerBlock(calcinator, "block." + Strings.CALCINATOR_NAME);
GameRegistry.registerBlock(aludelBase, "block." + Strings.ALUDEL_NAME);
GameRegistry.registerBlock(alchemicalChest, "block." + Strings.ALCHEMICAL_CHEST_NAME);
GameRegistry.registerBlock(glassBell, "block." + Strings.GLASS_BELL_NAME);
GameRegistry.registerBlock(alchemicalFuel, ItemAlchemicalFuelBlock.class, "block." + Strings.ALCHEMICAL_FUEL_NAME);
GameRegistry.registerBlock(alchemySquare, "block." + Strings.ALCHEMY_SQUARE_NAME);
GameRegistry.registerBlock(aludelBase, "block." + Strings.ALUDEL_NAME);
GameRegistry.registerBlock(calcinator, "block." + Strings.CALCINATOR_NAME);
GameRegistry.registerBlock(chalk, "block." + Strings.CHALK_NAME);
GameRegistry.registerBlock(glassBell, "block." + Strings.GLASS_BELL_NAME);
}
}

View file

@ -18,7 +18,6 @@ import net.minecraft.nbt.NBTTagList;
*/
public class TileAlchemicalChest extends TileEE implements IInventory
{
/**
* The current angle of the chest lid (between 0 and 1)
*/
@ -48,7 +47,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
public TileAlchemicalChest()
{
super();
inventory = new ItemStack[INVENTORY_SIZE];
}
@ -63,14 +61,12 @@ public class TileAlchemicalChest 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)
{
@ -94,7 +90,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex)
{
if (inventory[slotIndex] != null)
{
ItemStack itemStack = inventory[slotIndex];
@ -110,7 +105,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
@ -124,14 +118,12 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public String getInvName()
{
return this.hasCustomName() ? this.getCustomName() : Strings.CONTAINER_ALCHEMICAL_CHEST_NAME;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@ -141,7 +133,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public boolean receiveClientEvent(int eventID, int numUsingPlayers)
{
if (eventID == 1)
{
this.numUsingPlayers = numUsingPlayers;
@ -156,7 +147,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void openChest()
{
++numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest.blockID, 1, numUsingPlayers);
}
@ -164,7 +154,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void closeChest()
{
--numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest.blockID, 1, numUsingPlayers);
}
@ -176,7 +165,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void updateEntity()
{
super.updateEntity();
if (++ticksSinceSync % 20 * 4 == 0)
@ -230,7 +218,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
// Read in the ItemStacks in the inventory from NBT
@ -250,7 +237,6 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
// Write the ItemStacks in the inventory to NBT
@ -271,21 +257,18 @@ public class TileAlchemicalChest extends TileEE implements IInventory
@Override
public boolean isInvNameLocalized()
{
return this.hasCustomName();
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{
return true;
}
@Override
public String toString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(super.toString());