Skip to content

Instantly share code, notes, and snippets.

@witchica
Created August 21, 2014 21:40
Show Gist options
  • Save witchica/0755753544eeea4f7f66 to your computer and use it in GitHub Desktop.
Save witchica/0755753544eeea4f7f66 to your computer and use it in GitHub Desktop.
package me.modforgery.cc.block;
import me.modforgery.cc.CompactChests;
import me.modforgery.cc.tileentity.TileEntityDoubleChest;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
/**
* Created by Toby on 19/08/2014.
*/
public class BlockDoubleChest extends Block implements ITileEntityProvider
{
public BlockDoubleChest()
{
super(Material.wood);
setBlockName("doublechest");
setHardness(1f);
setResistance(1f);
setCreativeTab(CreativeTabs.tabDecorations);
}
@Override
public TileEntity createNewTileEntity(World world, int dim)
{
return new TileEntityDoubleChest();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float j, float k, float l)
{
player.openGui(CompactChests.instance(), 0, world, x, y, z);
return true;
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
this.rotateChest(world, x, y, z);
}
private void rotateChest(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte metadata = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
metadata = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
metadata = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
metadata = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
metadata = 4;
}
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
{
super.onBlockPlacedBy(world, x, y, z, entity, stack);
rotateChest(world, x, y, z);
}
@Override
public int onBlockPlaced(World world, int x, int y, int z, int i, float j, float k, float l, int o)
{
rotateChest(world, x, y, z);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment