mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 16:27:45 +00:00
Chest commit 1
This commit is contained in:
1 parent
5fcdaf5dee
commit
37bad22041
12 files changed
+1161
-186
No files matched your search
@@ -0,0 +1,444 @@
|
||||
package info.jbcs.minecraft.chisel.block;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.api.ICarvable;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityPresent;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableVariation;
|
||||
import info.jbcs.minecraft.chisel.init.ModTabs;
|
||||
import info.jbcs.minecraft.chisel.inventory.InventoryLargePresent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.passive.EntityOcelot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockPresent extends BlockContainer implements ICarvable {
|
||||
private final Random random = new Random();
|
||||
public CarvableHelper carverHelper;
|
||||
private boolean isChristmas = true;
|
||||
|
||||
public BlockPresent() {
|
||||
super(Material.wood);
|
||||
carverHelper = new CarvableHelper();
|
||||
setCreativeTab(ModTabs.tabChiselBlocks);
|
||||
setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0875F, 0.9365F);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
if (calendar.get(2) + 1 == 12 && calendar.get(5) >= 25 && calendar.get(5) <= 26) {
|
||||
isChristmas = true;//<--- this would have been false before and it lasts for two days :)
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCatSittingOnMe(World world, int x, int y, int z) {
|
||||
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox(x, y + 1, z, x + 1, y + 2, z + 1)).iterator();
|
||||
EntityOcelot ocelot;
|
||||
|
||||
do {
|
||||
if (!iterator.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) iterator.next();
|
||||
ocelot = (EntityOcelot) entity;
|
||||
} while (!ocelot.isSitting());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceSingle(int metadata) {
|
||||
if (isChristmas) {
|
||||
switch (metadata) {
|
||||
case 1:
|
||||
return new ResourceLocation(Chisel.MOD_ID, "textures/blocks/present/red.png");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
switch (metadata) {
|
||||
case 1:
|
||||
return new ResourceLocation(Chisel.MOD_ID, "textures/blocks/present/crate.png");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceDouble(int metadata) {
|
||||
if (isChristmas) {
|
||||
switch (metadata) {
|
||||
case 1:
|
||||
return new ResourceLocation(Chisel.MOD_ID, "textures/blocks/presentDouble/red.png");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
switch (metadata) {
|
||||
case 1:
|
||||
return new ResourceLocation(Chisel.MOD_ID, "textures/blocks/presentDouble/crate.png");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack) {
|
||||
Block front = world.getBlock(x, y, z - 1);
|
||||
Block back = world.getBlock(x, y, z + 1);
|
||||
Block left = world.getBlock(x - 1, y, z);
|
||||
Block right = world.getBlock(x + 1, y, z);
|
||||
byte metadata = 0;
|
||||
int rot = MathHelper.floor_double((entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
|
||||
if (rot == 0) {
|
||||
metadata = 2;
|
||||
}
|
||||
|
||||
if (rot == 1) {
|
||||
metadata = 5;
|
||||
}
|
||||
|
||||
if (rot == 2) {
|
||||
metadata = 3;
|
||||
}
|
||||
|
||||
if (rot == 3) {
|
||||
metadata = 4;
|
||||
}
|
||||
|
||||
if (front != this && back != this && left != this && right != this) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
} else {
|
||||
if ((front == this || back == this) && (metadata == 4 || metadata == 5)) {
|
||||
if (front == this) {
|
||||
world.setBlockMetadataWithNotify(x, y, z - 1, metadata, 3);
|
||||
} else {
|
||||
world.setBlockMetadataWithNotify(x, y, z + 1, metadata, 3);
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
}
|
||||
|
||||
if ((left == this || right == this) && (metadata == 4 || metadata == 5)) {
|
||||
if (left == this) {
|
||||
world.setBlockMetadataWithNotify(x - 1, y, z, metadata, 3);
|
||||
} else {
|
||||
world.setBlockMetadataWithNotify(x + 1, y, z, metadata, 3);
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
|
||||
int l = 0;
|
||||
|
||||
if (world.getBlock(x - 1, y, z) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x + 1, y, z) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z - 1) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z + 1) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
return l > 1 ? false : (areSurroundingBlocksMe(world, x, y - 1, z) ? false : (areSurroundingBlocksMe(world, x, y + 1, z) ? false : (areSurroundingBlocksMe(world, x, y, z - 1) ? false : !areSurroundingBlocksMe(world, x, y, z + 1))));
|
||||
}
|
||||
|
||||
private boolean areSurroundingBlocksMe(World world, int x, int y, int z) {
|
||||
return world.getBlock(x, y, z) != this ? false : (world.getBlock(x - 1, y, z) == this ? true : (world.getBlock(x + 1, y, z) == this ? true : (world.getBlock(x, y, z - 1) == this ? true : world.getBlock(x, y, z + 1) == this)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
|
||||
super.onNeighborBlockChange(world, x, y, z, neighbor);
|
||||
TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
|
||||
if (tileEntityPresent != null) {
|
||||
tileEntityPresent.updateContainingBlockInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block present, int meta) {
|
||||
TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
|
||||
if (tileEntityPresent != null) {
|
||||
for (int c = 0; c < tileEntityPresent.getSizeInventory(); c++) {
|
||||
ItemStack itemStack = tileEntityPresent.getStackInSlot(c);
|
||||
|
||||
if (itemStack != null) {
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
EntityItem entityItem;
|
||||
|
||||
for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemStack.stackSize > 0; world.spawnEntityInWorld(entityItem)) {
|
||||
int stack = random.nextInt(21) + 10;
|
||||
|
||||
if (stack > itemStack.stackSize) {
|
||||
stack = itemStack.stackSize;
|
||||
}
|
||||
|
||||
itemStack.stackSize -= stack;
|
||||
entityItem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemStack.getItem(), stack, itemStack.getItemDamage()));
|
||||
float motion = 0.05F;
|
||||
entityItem.motionX = random.nextGaussian() * motion;
|
||||
entityItem.motionY = random.nextGaussian() * motion + 0.2F;
|
||||
entityItem.motionZ = random.nextGaussian() * motion;
|
||||
|
||||
if (itemStack.hasTagCompound()) {
|
||||
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.func_147453_f(x, y, z, present);
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, present, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float x1, float y1, float z1) {
|
||||
if (world.isRemote) {
|
||||
return true;
|
||||
} else {
|
||||
IInventory inventory = getInventory(world, x, y, z);
|
||||
|
||||
if (inventory != null) {
|
||||
player.openGui(Chisel.instance, 2, world, x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
|
||||
if (world.getBlock(x, y, z - 1) == this) {
|
||||
this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F);
|
||||
} else if (world.getBlock(x, y, z + 1) == this) {
|
||||
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
|
||||
} else if (world.getBlock(x - 1, y, z) == this) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F);
|
||||
} else if (world.getBlock(x + 1, y, z) == this) {
|
||||
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F);
|
||||
} else {
|
||||
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z) {
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
this.changeMetadataBasedOffSpecs(world, x, y, z);
|
||||
Block back = world.getBlock(x, y, z - 1);
|
||||
Block front = world.getBlock(x, y, z + 1);
|
||||
Block left = world.getBlock(x - 1, y, z);
|
||||
Block right = world.getBlock(x + 1, y, z);
|
||||
|
||||
if (back == this) {
|
||||
this.changeMetadataBasedOffSpecs(world, x, y, z - 1);
|
||||
}
|
||||
|
||||
if (front == this) {
|
||||
this.changeMetadataBasedOffSpecs(world, x, y, z + 1);
|
||||
}
|
||||
|
||||
if (left == this) {
|
||||
this.changeMetadataBasedOffSpecs(world, x - 1, y, z);
|
||||
}
|
||||
|
||||
if (right == this) {
|
||||
this.changeMetadataBasedOffSpecs(world, x + 1, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeMetadataBasedOffSpecs(World world, int x, int y, int z) {
|
||||
if (!world.isRemote) {
|
||||
Block back = world.getBlock(x, y, z - 1);
|
||||
Block front = world.getBlock(x, y, z + 1);
|
||||
Block left = world.getBlock(x - 1, y, z);
|
||||
Block right = world.getBlock(x + 1, y, z);
|
||||
boolean flag = true, flag1;
|
||||
byte metadata;
|
||||
int x1, blockMeta, z1;
|
||||
Block backLeft, frontRight;
|
||||
|
||||
if (front != this && back != this) {
|
||||
if (left != this && right != this) {
|
||||
metadata = 3;
|
||||
|
||||
if (front.func_149730_j() && !back.func_149730_j()) {
|
||||
metadata = 3;
|
||||
}
|
||||
|
||||
if (back.func_149730_j() && !front.func_149730_j()) {
|
||||
metadata = 2;
|
||||
}
|
||||
|
||||
if (left.func_149730_j() && !right.func_149730_j()) {
|
||||
metadata = 5;
|
||||
}
|
||||
|
||||
if (right.func_149730_j() && !left.func_149730_j()) {
|
||||
metadata = 4;
|
||||
}
|
||||
} else {
|
||||
x1 = back == this ? x - 1 : x + 1;
|
||||
backLeft = world.getBlock(x1, y, z - 1);
|
||||
z1 = back == this ? z - 1 : z + 1;
|
||||
frontRight = world.getBlock(x + 1, y, z1);
|
||||
metadata = 5;
|
||||
flag1 = true;
|
||||
|
||||
if (back == this) {
|
||||
blockMeta = world.getBlockMetadata(x, y, z - 1);
|
||||
} else {
|
||||
blockMeta = world.getBlockMetadata(x, y, z + 1);
|
||||
}
|
||||
|
||||
if (blockMeta == 4) {
|
||||
metadata = 4;
|
||||
}
|
||||
|
||||
if ((left.func_149730_j() || backLeft.func_149730_j()) && !right.func_149730_j() && !frontRight.func_149730_j()) {
|
||||
metadata = 5;
|
||||
}
|
||||
|
||||
if ((right.func_149730_j() || frontRight.func_149730_j()) && !left.func_149730_j() && !backLeft.func_149730_j()) {
|
||||
metadata = 4;
|
||||
}
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int par2) {
|
||||
return new TileEntityPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int strength) {
|
||||
if (!canProvidePower()) {
|
||||
return 0;
|
||||
} else {
|
||||
int players = ((TileEntityPresent) world.getTileEntity(x, y, z)).numPlayersUsing;
|
||||
return MathHelper.clamp_int(players, 0, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int strength) {
|
||||
return strength == 1 ? isProvidingWeakPower(world, x, y, z, strength) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int strength) {
|
||||
return Container.calcRedstoneFromInventory(getInventory(world, x, y, z));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister register) {
|
||||
this.blockIcon = register.registerIcon("planks_oak");
|
||||
}
|
||||
|
||||
public IInventory getInventory(World world, int x, int y, int z) {
|
||||
Object object = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
|
||||
if (object == null) {
|
||||
return null;
|
||||
} else if (world.isSideSolid(x, y + 1, z, ForgeDirection.DOWN)) {
|
||||
return null;
|
||||
} else if (isCatSittingOnMe(world, x, y, z)) {
|
||||
return null;
|
||||
} else if (world.getBlock(x - 1, y, z) == this && (world.isSideSolid(x - 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y - 1, z))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x + 1, y, z) == this && (world.isSideSolid(x + 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y + 1, z))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x, y, z - 1) == this && (world.isSideSolid(x, y + 1, z - 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z - 1))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x, y, z + 1) == this && (world.isSideSolid(x, y + 1, z + 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z + 1))) {
|
||||
return null;
|
||||
} else {
|
||||
if (world.getBlock(x - 1, y, z) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x - 1, y, z), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x + 1, y, z) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x + 1, y, z), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z - 1) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z - 1), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z + 1) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z + 1), (IInventory) object);
|
||||
}
|
||||
|
||||
return (IInventory) object;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvableVariation getVariation(int metadata) {
|
||||
return carverHelper.getVariation(metadata);
|
||||
}
|
||||
}
|
||||
+112
-133
@@ -2,11 +2,6 @@ package info.jbcs.minecraft.chisel.block.tileentity;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableVariation;
|
||||
import info.jbcs.minecraft.chisel.carving.Carving;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvingVariation;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -19,70 +14,84 @@ import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory{
|
||||
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
|
||||
|
||||
private ItemStack[] inventory = new ItemStack[3];
|
||||
private String name = "autoChisel";
|
||||
private static EntityItem ghostItem;
|
||||
boolean equal = false;
|
||||
private ItemStack[] inventory = new ItemStack[3];
|
||||
private String name = "autoChisel";
|
||||
|
||||
@Override
|
||||
public boolean canUpdate(){
|
||||
public boolean canUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int size) {
|
||||
if (inventory[slot] != null) {
|
||||
ItemStack is;
|
||||
if (inventory[slot].stackSize <= size) {
|
||||
is = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
} else {
|
||||
is = inventory[slot].splitStack(size);
|
||||
if (inventory[slot].stackSize == 0)
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int size) {
|
||||
if (inventory[slot] != null) {
|
||||
ItemStack is;
|
||||
if (inventory[slot].stackSize <= size) {
|
||||
is = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
} else {
|
||||
is = inventory[slot].splitStack(size);
|
||||
if (inventory[slot].stackSize == 0)
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
NBTTagList tags = nbt.getTagList("Items", 10);
|
||||
inventory = new ItemStack[getSizeInventory()];
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
NBTTagList tags = nbt.getTagList("Items", 10);
|
||||
inventory = new ItemStack[getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < tags.tagCount(); i++) {
|
||||
NBTTagCompound data = tags.getCompoundTagAt(i);
|
||||
int j = data.getByte("Slot") & 255;
|
||||
for (int i = 0; i < tags.tagCount(); i++) {
|
||||
NBTTagCompound data = tags.getCompoundTagAt(i);
|
||||
int j = data.getByte("Slot") & 255;
|
||||
|
||||
if (j >= 0 && j < inventory.length) {
|
||||
inventory[j] = ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
}
|
||||
if (j >= 0 && j < inventory.length) {
|
||||
inventory[j] = ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt.hasKey("CustomName", 8))
|
||||
{
|
||||
if (nbt.hasKey("CustomName", 8)) {
|
||||
this.name = nbt.getString("CustomName");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
|
||||
public void updateEntity() {
|
||||
if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
|
||||
if (inventory[0] != null && inventory[1] != null) {
|
||||
if(inventory[0].getItem() instanceof ItemBlock && inventory[1].getItem() instanceof ItemBlock){
|
||||
if(Carving.chisel.getOre(Block.getBlockFromItem(inventory[0].getItem()), inventory[0].getItemDamage()) == Carving.chisel.getOre(Block.getBlockFromItem(inventory[1].getItem()), inventory[1].getItemDamage()))
|
||||
if (inventory[0].getItem() instanceof ItemBlock && inventory[1].getItem() instanceof ItemBlock) {
|
||||
if (inventory[0].getItem() == inventory[1].getItem()) {
|
||||
equal = true;
|
||||
} else {
|
||||
equal = false;
|
||||
}
|
||||
if (equal) {
|
||||
if (inventory[0].stackSize < 0) {
|
||||
inventory[0] = null;
|
||||
}
|
||||
|
||||
if (inventory[1].stackSize < 0) {
|
||||
inventory[1] = null;
|
||||
}
|
||||
|
||||
if (inventory[1].stackSize < 0) {
|
||||
inventory[1] = null;
|
||||
}
|
||||
|
||||
if (inventory[2] == null) {
|
||||
setInventorySlotContents(2, new ItemStack(inventory[1].getItem(), 1, inventory[1].getItemDamage()));
|
||||
decrStackSize(0, 1);
|
||||
} else {
|
||||
if (inventory[0].stackSize != 0 && inventory[2].stackSize < getInventoryStackLimit()) {
|
||||
if (inventory[0].stackSize != 0 && inventory[2].stackSize <= getInventoryStackLimit()) {
|
||||
decrStackSize(0, 1);
|
||||
inventory[2].stackSize++;
|
||||
} else {
|
||||
@@ -97,161 +106,131 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory{
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
NBTTagList tags = new NBTTagList();
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
NBTTagList tags = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
if (inventory[i] != null) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(data);
|
||||
tags.appendTag(data);
|
||||
}
|
||||
}
|
||||
|
||||
nbt.setTag("Items", tags);
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
if (inventory[i] != null) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(data);
|
||||
tags.appendTag(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasCustomInventoryName())
|
||||
{
|
||||
nbt.setTag("Items", tags);
|
||||
|
||||
if (this.hasCustomInventoryName()) {
|
||||
nbt.setString("CustomName", this.name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory(){
|
||||
public int getSizeInventory() {
|
||||
return inventory.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot){
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inventory[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
if (inventory[slot] != null) {
|
||||
ItemStack is = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
if (inventory[slot] != null) {
|
||||
ItemStack is = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
return is;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack){
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inventory[slot] = stack;
|
||||
|
||||
if(stack != null && stack.stackSize > getInventoryStackLimit()){
|
||||
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
|
||||
stack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName(){
|
||||
public String getInventoryName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isUseableByPlayer(EntityPlayer player){
|
||||
public final boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit(){
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName(){
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side){
|
||||
int[] slots = new int[getSizeInventory()];
|
||||
|
||||
for(int c = 0; c < slots.length; c++){
|
||||
slots[c] = c;
|
||||
}
|
||||
|
||||
if(side != 0){
|
||||
return slots;
|
||||
} else if(side == 0){
|
||||
return new int[] {2};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemStack){
|
||||
return slot != 1;
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side){
|
||||
if(side != 0){
|
||||
if(slot == 0){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if(side == 0){
|
||||
if(slot == 1){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side){
|
||||
if(slot == 2){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(){}
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(){
|
||||
public void closeInventory() {
|
||||
NBTTagList tags = new NBTTagList();
|
||||
System.out.print(tags);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EntityItem getItemForRendering(int slot){
|
||||
if(ghostItem == null){
|
||||
public EntityItem getItemForRendering(int slot) {
|
||||
if (ghostItem == null) {
|
||||
ghostItem = new EntityItem(worldObj);
|
||||
ghostItem.hoverStart = 0.0F;
|
||||
}
|
||||
|
||||
if(inventory[slot] == null){
|
||||
if (inventory[slot] == null) {
|
||||
return null;
|
||||
} else {
|
||||
ghostItem.setEntityItemStack(new ItemStack(inventory[slot].getItem(), 1, inventory[slot].getItemDamage()));
|
||||
return ghostItem;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||
readFromNBT(packet.func_148857_g());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||
readFromNBT(packet.func_148857_g());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package info.jbcs.minecraft.chisel.block.tileentity;
|
||||
|
||||
import info.jbcs.minecraft.chisel.block.BlockPresent;
|
||||
import info.jbcs.minecraft.chisel.inventory.ContainerPresent;
|
||||
import info.jbcs.minecraft.chisel.inventory.InventoryLargePresent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityPresent extends TileEntityChest {
|
||||
|
||||
public TileEntityPresent() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return this.worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
public void checkIfAdjacentBlocksAreMe(TileEntityPresent tile, int meta) {
|
||||
if (tile.isInvalid()) {
|
||||
this.adjacentChestChecked = false;
|
||||
} else if (this.adjacentChestChecked) {
|
||||
switch (meta) {
|
||||
case 0:
|
||||
if (this.adjacentChestZPos != tile) {
|
||||
this.adjacentChestChecked = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if (this.adjacentChestXNeg != tile) {
|
||||
this.adjacentChestChecked = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if (this.adjacentChestZNeg != tile) {
|
||||
this.adjacentChestChecked = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
if (this.adjacentChestXPos != tile) {
|
||||
this.adjacentChestChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForAdjacentPresents() {
|
||||
if (!this.adjacentChestChecked) {
|
||||
TileEntityPresent zNeg = (TileEntityPresent) this.adjacentChestZNeg;
|
||||
TileEntityPresent xPos = (TileEntityPresent) this.adjacentChestXPos;
|
||||
TileEntityPresent xNeg = (TileEntityPresent) this.adjacentChestXNeg;
|
||||
TileEntityPresent zPos = (TileEntityPresent) this.adjacentChestZPos;
|
||||
this.adjacentChestChecked = true;
|
||||
|
||||
if (this.isBlockPresent(xCoord - 1, yCoord, zCoord)) {
|
||||
xNeg = (TileEntityPresent) this.worldObj.getTileEntity(xCoord - 1, yCoord, zCoord);
|
||||
}
|
||||
|
||||
if (this.isBlockPresent(xCoord + 1, yCoord, zCoord)) {
|
||||
xPos = (TileEntityPresent) this.worldObj.getTileEntity(xCoord + 1, yCoord, zCoord);
|
||||
}
|
||||
|
||||
if (this.isBlockPresent(xCoord, yCoord, zCoord - 1)) {
|
||||
zNeg = (TileEntityPresent) this.worldObj.getTileEntity(xCoord, yCoord, zCoord - 1);
|
||||
}
|
||||
|
||||
if (this.isBlockPresent(xCoord, yCoord, zCoord + 1)) {
|
||||
zPos = (TileEntityPresent) this.worldObj.getTileEntity(xCoord, yCoord, zCoord + 1);
|
||||
}
|
||||
|
||||
if (this.adjacentChestZNeg != null) {
|
||||
zNeg.checkIfAdjacentBlocksAreMe(this, 0);
|
||||
}
|
||||
|
||||
if (this.adjacentChestZPos != null) {
|
||||
zPos.checkIfAdjacentBlocksAreMe(this, 2);
|
||||
}
|
||||
|
||||
if (this.adjacentChestXPos != null) {
|
||||
xPos.checkIfAdjacentBlocksAreMe(this, 1);
|
||||
}
|
||||
|
||||
if (this.adjacentChestXNeg != null) {
|
||||
xNeg.checkIfAdjacentBlocksAreMe(this, 3);
|
||||
}
|
||||
|
||||
this.adjacentChestXNeg = xNeg;
|
||||
this.adjacentChestXPos = xPos;
|
||||
this.adjacentChestZPos = zPos;
|
||||
this.adjacentChestZNeg = zNeg;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBlockPresent(int x, int y, int z) {
|
||||
if (this.worldObj == null) {
|
||||
return false;
|
||||
} else {
|
||||
Block block = this.worldObj.getBlock(x, y, z);
|
||||
return block instanceof BlockPresent;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
checkForAdjacentPresents();
|
||||
float f;
|
||||
|
||||
if (!worldObj.isRemote && numPlayersUsing != 0 && (+xCoord + yCoord + zCoord) % 200 == 0) {
|
||||
numPlayersUsing = 0;
|
||||
f = 5.0F;
|
||||
List list = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - f, yCoord - f, zCoord - f, (xCoord + 1) + f, (yCoord + 1) + f, (zCoord + 1) + f));
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityPlayer player = (EntityPlayer) iterator.next();
|
||||
|
||||
if (player.openContainer instanceof ContainerPresent) {
|
||||
IInventory inventory = ((ContainerPresent) player.openContainer).getLowerPresentInventory();
|
||||
|
||||
if (inventory == this || inventory instanceof InventoryLargePresent && ((InventoryLargePresent) inventory).isPartOfLargePresent(this)) {
|
||||
++numPlayersUsing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prevLidAngle = lidAngle;
|
||||
f = 0.1F;
|
||||
double d2;
|
||||
|
||||
if (numPlayersUsing > 0 && lidAngle == 0.0F && adjacentChestZNeg == null && adjacentChestXNeg == null) {
|
||||
double d1 = xCoord + 0.5D;
|
||||
d2 = xCoord + 0.5D;
|
||||
if (adjacentChestZPos != null) {
|
||||
d2 += 0.5D;
|
||||
}
|
||||
|
||||
if (adjacentChestXPos != null) {
|
||||
d1 += 0.5D;
|
||||
}
|
||||
|
||||
worldObj.playSoundEffect(d1, yCoord + 0.5D, d2, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
if (numPlayersUsing == 0 && lidAngle > 0.0F || numPlayersUsing > 0 && lidAngle < 1.0F) {
|
||||
float f1 = lidAngle;
|
||||
|
||||
if (numPlayersUsing > 0) {
|
||||
lidAngle += f;
|
||||
} else {
|
||||
lidAngle -= f;
|
||||
}
|
||||
|
||||
if (lidAngle > 1.0F) {
|
||||
lidAngle = 1.0F;
|
||||
}
|
||||
|
||||
float f2 = 0.5F;
|
||||
|
||||
if (lidAngle < f2 && f1 >= f2 && adjacentChestZNeg == null && adjacentChestXNeg == null) {
|
||||
d2 = xCoord + 0.5D;
|
||||
double d0 = zCoord + 0.5D;
|
||||
|
||||
if (adjacentChestZPos != null) {
|
||||
d0 += 0.5D;
|
||||
}
|
||||
|
||||
if (adjacentChestXPos != null) {
|
||||
d2 += 0.5D;
|
||||
}
|
||||
|
||||
worldObj.playSoundEffect(d2, yCoord + 0.5D, d0, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
if (lidAngle < 0.0F) {
|
||||
lidAngle = 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
if (numPlayersUsing < 0) {
|
||||
numPlayersUsing = 0;
|
||||
}
|
||||
|
||||
++numPlayersUsing;
|
||||
worldObj.addBlockEvent(xCoord, yCoord, zCoord, getBlockType(), 1, numPlayersUsing);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
if (getBlockType() instanceof BlockPresent) {
|
||||
--numPlayersUsing;
|
||||
worldObj.addBlockEvent(xCoord, yCoord, zCoord, getBlockType(), 1, numPlayersUsing);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
updateContainingBlockInfo();
|
||||
checkForAdjacentPresents();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package info.jbcs.minecraft.chisel.client.render.item;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import net.minecraft.client.model.ModelChest;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class ItemPresentRenderer implements IItemRenderer {
|
||||
private final ModelChest model = new ModelChest();
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return type != ItemRenderType.FIRST_PERSON_MAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Chisel.MOD_ID, "textures/blocks/present/1.png"));
|
||||
switch (type) {
|
||||
case ENTITY:
|
||||
renderBlock(0.0F, 1.0F, 0.0F);
|
||||
break;
|
||||
case EQUIPPED:
|
||||
renderBlock(0.5F, 1.5F, 0.5F);
|
||||
break;
|
||||
case EQUIPPED_FIRST_PERSON:
|
||||
renderBlock(0.5F, 1.0F, 0.5F);
|
||||
break;
|
||||
case INVENTORY:
|
||||
renderInventory(0.0F, 0.625F, 0.0F);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderBlock(float x, float y, float z) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, z);
|
||||
GL11.glScaled(-1, -1, 1);
|
||||
model.renderAll();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void renderInventory(float x, float y, float z) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, z);
|
||||
GL11.glRotatef(180F, 1F, 0, 0);
|
||||
GL11.glRotatef(-90F, 0, 1F, 0);
|
||||
GL11.glScalef(0.8F, 0.8F, 0.8F);
|
||||
model.renderAll();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package info.jbcs.minecraft.chisel.client.render.tile;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import info.jbcs.minecraft.chisel.block.BlockPresent;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityPresent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockChest;
|
||||
import net.minecraft.client.model.ModelChest;
|
||||
import net.minecraft.client.model.ModelLargeChest;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityChestRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public class RenderPresent extends TileEntityChestRenderer {
|
||||
private ModelChest chest = new ModelChest();
|
||||
private ModelChest doubleChest = new ModelLargeChest();
|
||||
|
||||
//TODO: this will be changed so it actually chescks after I have crate textures :)
|
||||
private boolean isChristmas = true;
|
||||
|
||||
public RenderPresent() {
|
||||
|
||||
}
|
||||
|
||||
public void renderTileEntityAt(TileEntityPresent present, double x, double y, double z, float partialTicks) {
|
||||
int i;
|
||||
|
||||
if (!present.hasWorldObj()) {
|
||||
i = 0;
|
||||
} else {
|
||||
Block block = present.getBlockType();
|
||||
i = present.getBlockMetadata();
|
||||
|
||||
if (block instanceof BlockChest && i == 0) {
|
||||
try {
|
||||
((BlockChest) block).func_149954_e(present.getWorldObj(), present.xCoord, present.yCoord, present.zCoord);
|
||||
} catch (ClassCastException e) {
|
||||
FMLLog.severe("[Chisel 2] Attempted to render a present at %d, %d, %d that was not a present", present.xCoord, present.yCoord, present.zCoord);
|
||||
}
|
||||
i = present.getBlockMetadata();
|
||||
}
|
||||
|
||||
present.checkForAdjacentPresents();
|
||||
}
|
||||
|
||||
if (present.adjacentChestZNeg == null && present.adjacentChestXNeg == null) {
|
||||
BlockPresent blockPresent = (BlockPresent) present.getWorldObj().getBlock(present.xCoord, present.yCoord, present.zCoord);
|
||||
ModelChest modelchest;
|
||||
|
||||
if (present.adjacentChestXPos == null && present.adjacentChestZPos == null) {
|
||||
modelchest = this.chest;
|
||||
this.bindTexture(blockPresent.getResourceSingle(1));
|
||||
} else {
|
||||
modelchest = this.doubleChest;
|
||||
this.bindTexture(blockPresent.getResourceDouble(1));
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
|
||||
GL11.glScalef(1.0F, -1.0F, -1.0F);
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
short short1 = 0;
|
||||
|
||||
if (i == 2) {
|
||||
short1 = 180;
|
||||
}
|
||||
|
||||
if (i == 3) {
|
||||
short1 = 0;
|
||||
}
|
||||
|
||||
if (i == 4) {
|
||||
short1 = 90;
|
||||
}
|
||||
|
||||
if (i == 5) {
|
||||
short1 = -90;
|
||||
}
|
||||
|
||||
if (i == 2 && present.adjacentChestXPos != null) {
|
||||
GL11.glTranslatef(1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
if (i == 5 && present.adjacentChestZPos != null) {
|
||||
GL11.glTranslatef(0.0F, 0.0F, -1.0F);
|
||||
}
|
||||
|
||||
GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
float f1 = present.prevLidAngle + (present.lidAngle - present.prevLidAngle) * partialTicks;
|
||||
float f2;
|
||||
|
||||
if (present.adjacentChestZNeg != null) {
|
||||
f2 = present.adjacentChestZNeg.prevLidAngle + (present.adjacentChestZNeg.lidAngle - present.adjacentChestZNeg.prevLidAngle) * partialTicks;
|
||||
|
||||
if (f2 > f1) {
|
||||
f1 = f2;
|
||||
}
|
||||
}
|
||||
|
||||
if (present.adjacentChestXNeg != null) {
|
||||
f2 = present.adjacentChestXNeg.prevLidAngle + (present.adjacentChestXNeg.lidAngle - present.adjacentChestXNeg.prevLidAngle) * partialTicks;
|
||||
|
||||
if (f2 > f1) {
|
||||
f1 = f2;
|
||||
}
|
||||
}
|
||||
|
||||
f1 = 1.0F - f1;
|
||||
f1 = 1.0F - f1 * f1 * f1;
|
||||
modelchest.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F);
|
||||
modelchest.renderAll();
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTicks) {
|
||||
this.renderTileEntityAt((TileEntityPresent) tileEntity, x, y, z, partialTicks);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package info.jbcs.minecraft.chisel.init;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.Configurations;
|
||||
import info.jbcs.minecraft.chisel.block.*;
|
||||
import info.jbcs.minecraft.chisel.block.BlockVoidstone;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableVariation;
|
||||
import info.jbcs.minecraft.chisel.carving.Carving;
|
||||
@@ -14,14 +11,11 @@ import info.jbcs.minecraft.chisel.item.ItemCarvable;
|
||||
import info.jbcs.minecraft.chisel.item.ItemMarbleSlab;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class ModBlocks {
|
||||
public static BlockCarvable marble;
|
||||
public static BlockCarvable marblePillar;
|
||||
@@ -77,6 +71,7 @@ public class ModBlocks {
|
||||
public static BlockCarvable voidstone;
|
||||
public static BlockVoidstone voidstonePillar = new BlockVoidstone();
|
||||
public static Block autoChisel;
|
||||
public static BlockPresent present;
|
||||
public static BlockSnakestone snakestone;
|
||||
public static BlockSnakestone sandSnakestone;
|
||||
public static BlockSnakestoneObsidian obsidianSnakestone;
|
||||
@@ -812,9 +807,8 @@ public class ModBlocks {
|
||||
}
|
||||
planks[i].carverHelper.register(planks[i], orename);
|
||||
Carving.chisel.addVariation(orename, Blocks.planks, i, 0);
|
||||
Blocks.planks.setHarvestLevel("chisel", 0, i);
|
||||
planks[i].setHarvestLevel("axe", 0);
|
||||
|
||||
Carving.chisel.registerOre("wood", "wood");
|
||||
Carving.chisel.setVariationSound(orename, Chisel.MOD_ID+":chisel.wood");
|
||||
}
|
||||
}
|
||||
@@ -1314,6 +1308,14 @@ public class ModBlocks {
|
||||
Carving.chisel.registerOre("leaves", "leaves");
|
||||
}
|
||||
|
||||
if (Configurations.featureEnabled("chest")) {
|
||||
present = (BlockPresent) new BlockPresent().setHardness(2.5F).setStepSound(Block.soundTypeWood);
|
||||
Carving.chisel.addVariation("chest", Blocks.chest, 0, 0);
|
||||
present.carverHelper.addVariation(StatCollector.translateToLocal("tile.presetnt.1.desc"), 1, present, 1);
|
||||
present.carverHelper.register(present, "present");
|
||||
Carving.chisel.registerOre("chest", "chest");
|
||||
}
|
||||
|
||||
if(Configurations.featureEnabled("voidstone")){
|
||||
voidstone = (BlockCarvable) new BlockCarvable().setHardness(2.0F).setResistance(5F).setStepSound(Block.soundTypeStone);
|
||||
voidstone.carverHelper.addVariation(StatCollector.translateToLocal("tile.voidstone.0.desc"), 0, "voidstone/metalborder");
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ContainerAutoChisel extends Container {
|
||||
public static TileEntityAutoChisel autoChisel;
|
||||
public static EntityPlayer player;
|
||||
|
||||
public ContainerAutoChisel(InventoryPlayer player, TileEntityAutoChisel tileEntityAutoChisel){
|
||||
public ContainerAutoChisel(InventoryPlayer player, TileEntityAutoChisel tileEntityAutoChisel) {
|
||||
|
||||
this.player = player.player;
|
||||
autoChisel = tileEntityAutoChisel;
|
||||
@@ -24,14 +24,14 @@ public class ContainerAutoChisel extends Container {
|
||||
bindPlayerInventory(player);
|
||||
}
|
||||
|
||||
protected void bindPlayerInventory(InventoryPlayer invPlayer){
|
||||
for(int row = 0; row < 3; row++){
|
||||
for(int column = 0; column < 9; column++){
|
||||
protected void bindPlayerInventory(InventoryPlayer invPlayer) {
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlotToContainer(new Slot(invPlayer, column + row * 9 + 9, 8 + column * 18, 84 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int slotNumber = 0; slotNumber < 9; slotNumber++){
|
||||
for (int slotNumber = 0; slotNumber < 9; slotNumber++) {
|
||||
addSlotToContainer(new Slot(invPlayer, slotNumber, 8 + slotNumber * 18, 142));
|
||||
}
|
||||
}
|
||||
@@ -42,41 +42,47 @@ public class ContainerAutoChisel extends Container {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
|
||||
ItemStack stack = null;
|
||||
Slot slotObject = (Slot) inventorySlots.get(slot);
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
|
||||
|
||||
if(slotObject != null && slotObject.getHasStack()){
|
||||
ItemStack stackInSlot = slotObject.getStack();
|
||||
stack = stackInSlot.copy();
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemStack1 = slot.getStack();
|
||||
itemStack = itemStack1.copy();
|
||||
|
||||
if(slot == 1){
|
||||
if(!this.mergeItemStack(stackInSlot, 3, 39, true)){
|
||||
if (slotNumber == 2) {
|
||||
if (!this.mergeItemStack(itemStack1, 3, 39, true)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(slot < autoChisel.getSizeInventory()){
|
||||
if(!this.mergeItemStack(stackInSlot, 0, 35, true)){
|
||||
slot.onSlotChange(itemStack1, itemStack);
|
||||
} else if (slotNumber != 1 && slotNumber != 0) {
|
||||
if (!this.mergeItemStack(itemStack1, 0, 1, true)) {
|
||||
return null;
|
||||
} else if (slotNumber >= 3 && slotNumber < 30) {
|
||||
if (this.mergeItemStack(itemStack1, 30, 39, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if (slotNumber >= 30 && slotNumber < 39 && !this.mergeItemStack(itemStack1, 3, 30, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if(!this.mergeItemStack(stackInSlot, 0, 3, false)){
|
||||
} else if (this.mergeItemStack(itemStack1, 3, 39, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(stackInSlot.stackSize == 0){
|
||||
slotObject.putStack(null);
|
||||
if (itemStack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slotObject.onSlotChanged();
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if(stackInSlot.stackSize == stack.stackSize){
|
||||
if (itemStack1.stackSize == itemStack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
slotObject.onPickupFromSlot(player, stackInSlot);
|
||||
slot.onPickupFromSlot(player, itemStack1);
|
||||
}
|
||||
|
||||
return stack;
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package info.jbcs.minecraft.chisel.inventory;
|
||||
|
||||
import net.minecraft.inventory.ContainerChest;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ContainerPresent extends ContainerChest {
|
||||
private IInventory lower;
|
||||
private int rows;
|
||||
|
||||
public ContainerPresent(IInventory player, IInventory chest) {
|
||||
super(player, chest);
|
||||
lower = chest;
|
||||
rows = chest.getSizeInventory() / 9;
|
||||
chest.openInventory();
|
||||
int a = (rows - 4) * 18, b, c;
|
||||
|
||||
for (int d = 0; d < rows; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(chest, e + d * 9, 8 + e * 18, 18 + d * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int d = 0; d < 3; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(player, e + d * 9 + 9, 8 + e * 18, 103 + d * 18 + a));
|
||||
}
|
||||
}
|
||||
|
||||
for (int d = 0; d < 9; d++) {
|
||||
addSlotToContainer(new Slot(player, d, 8 + d * 18, 161 + a));
|
||||
}
|
||||
}
|
||||
|
||||
public IInventory getLowerPresentInventory() {
|
||||
return lower;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package info.jbcs.minecraft.chisel.inventory;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InventoryLargePresent implements IInventory {
|
||||
private String name;
|
||||
private IInventory upper, lower;
|
||||
|
||||
public InventoryLargePresent(String name, IInventory upper, IInventory lower) {
|
||||
this.name = name;
|
||||
|
||||
if (upper == null) {
|
||||
upper = lower;
|
||||
}
|
||||
|
||||
if (lower == null) {
|
||||
lower = upper;
|
||||
}
|
||||
|
||||
this.upper = upper;
|
||||
this.lower = lower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return upper.getSizeInventory() + lower.getSizeInventory();
|
||||
}
|
||||
|
||||
public boolean isPartOfLargePresent(IInventory inventory) {
|
||||
return upper == inventory || lower == inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return slot >= upper.getSizeInventory() ? lower.getStackInSlot(slot - upper.getSizeInventory()) : upper.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int size) {
|
||||
return slot >= upper.getSizeInventory() ? lower.getStackInSlot(slot - upper.getSizeInventory()) : upper.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return slot >= upper.getSizeInventory() ? lower.getStackInSlotOnClosing(slot - upper.getSizeInventory()) : upper.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
if (slot >= upper.getSizeInventory()) {
|
||||
lower.setInventorySlotContents(slot - upper.getSizeInventory(), stack);
|
||||
} else {
|
||||
upper.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return upper.hasCustomInventoryName() ? upper.getInventoryName() : (lower.hasCustomInventoryName() ? lower.getInventoryName() : name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return upper.hasCustomInventoryName() || lower.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return upper.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
upper.markDirty();
|
||||
lower.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return upper.isUseableByPlayer(player) && lower.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
upper.openInventory();
|
||||
lower.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
upper.closeInventory();
|
||||
;
|
||||
lower.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,11 @@ import net.minecraft.world.World;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemChisel extends ItemTool implements IChiselMode
|
||||
{
|
||||
public static Carving carving = Carving.chisel;
|
||||
public class ItemChisel extends ItemTool implements IChiselMode {
|
||||
private static final HashSet<String> toolSet = new HashSet<String>();
|
||||
public static Carving carving = Carving.chisel;
|
||||
|
||||
public ItemChisel()
|
||||
{
|
||||
public ItemChisel() {
|
||||
super(1, ToolMaterial.IRON, CarvableHelper.getChiselBlockSet());
|
||||
|
||||
setMaxStackSize(1);
|
||||
@@ -31,29 +29,24 @@ public class ItemChisel extends ItemTool implements IChiselMode
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack)
|
||||
{
|
||||
public Set<String> getToolClasses(ItemStack stack) {
|
||||
return toolSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
|
||||
{
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer player)
|
||||
{
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChiselMode getChiselMode(ItemStack itemStack)
|
||||
{
|
||||
//TODO
|
||||
public ChiselMode getChiselMode(ItemStack itemStack) {
|
||||
return ChiselMode.SINGLE;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package info.jbcs.minecraft.chisel.proxy;
|
||||
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityPresent;
|
||||
import info.jbcs.minecraft.chisel.client.render.*;
|
||||
import info.jbcs.minecraft.chisel.client.render.item.ItemAutoChiselRenderer;
|
||||
import info.jbcs.minecraft.chisel.client.render.item.ItemChiselRenderer;
|
||||
import info.jbcs.minecraft.chisel.client.render.item.ItemPresentRenderer;
|
||||
import info.jbcs.minecraft.chisel.client.render.tile.RenderAutoChisel;
|
||||
import info.jbcs.minecraft.chisel.client.render.tile.RenderPresent;
|
||||
import info.jbcs.minecraft.chisel.entity.EntityBallOMoss;
|
||||
import info.jbcs.minecraft.chisel.entity.EntityCloudInABottle;
|
||||
import info.jbcs.minecraft.chisel.init.ModBlocks;
|
||||
@@ -13,7 +17,6 @@ import info.jbcs.minecraft.chisel.init.ModItems;
|
||||
import net.minecraft.client.renderer.entity.RenderSnowball;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
@@ -41,8 +44,10 @@ public class ClientProxy extends CommonProxy
|
||||
RenderingRegistry.registerBlockHandler(new BlockTexturedOreRenderer());
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAutoChisel.class, new RenderAutoChisel());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPresent.class, new RenderPresent());
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.autoChisel), new ItemAutoChiselRenderer());
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.present), new ItemPresentRenderer());
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityCloudInABottle.class, new RenderSnowball(ModItems.itemCloudInABottle));
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityBallOMoss.class, new RenderSnowball(ModItems.itemBallOMoss));
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package info.jbcs.minecraft.chisel.proxy;
|
||||
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityPresent;
|
||||
|
||||
public class CommonProxy
|
||||
{
|
||||
public void registerTileEntities() {
|
||||
registerTileEntity(TileEntityAutoChisel.class, "autoChisel");
|
||||
}
|
||||
GameRegistry.registerTileEntity(TileEntityAutoChisel.class, "autoChisel");
|
||||
GameRegistry.registerTileEntity(TileEntityPresent.class, "tile.present.present");
|
||||
}
|
||||
|
||||
private void registerTileEntity(Class<? extends TileEntity> cls, String baseName) {
|
||||
GameRegistry.registerTileEntity(cls, "tile.autoChisel." + baseName);
|
||||
}
|
||||
public void preInit()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user