2015-04-11 12:30:16 +02:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
2015-06-19 01:56:07 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockContainer;
|
2015-04-11 12:30:16 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2015-11-23 20:37:39 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-06-19 01:56:07 +02:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-04-11 12:30:16 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-19 01:56:07 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-04-11 12:30:16 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-11-23 20:37:39 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-04-11 12:30:16 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import techreborn.Core;
|
|
|
|
import techreborn.client.GuiHandler;
|
2015-06-19 01:56:07 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTab;
|
2015-04-11 12:30:16 +02:00
|
|
|
import techreborn.tiles.TileQuantumChest;
|
|
|
|
|
2015-06-19 01:56:07 +02:00
|
|
|
public class BlockQuantumChest extends BlockContainer {
|
2015-04-11 12:30:16 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public BlockQuantumChest() {
|
|
|
|
super(Material.rock);
|
2015-11-23 20:19:18 +01:00
|
|
|
setUnlocalizedName("techreborn.quantumChest");
|
2015-08-09 12:05:32 +02:00
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
|
|
|
setHardness(2.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
|
|
|
return new TileQuantumChest();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 20:37:39 +01:00
|
|
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
|
|
if (!playerIn.isSneaking())
|
|
|
|
playerIn.openGui(Core.INSTANCE, GuiHandler.quantumChestID, worldIn, pos.getX(),
|
|
|
|
pos.getY(), pos.getZ());
|
2015-08-09 12:05:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-23 20:37:39 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
|
|
|
super.onBlockAdded(worldIn, pos, state);
|
|
|
|
this.setDefaultDirection(worldIn, pos);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 20:37:39 +01:00
|
|
|
private void setDefaultDirection(World world, BlockPos pos) {
|
2015-08-09 12:05:32 +02:00
|
|
|
|
|
|
|
if (!world.isRemote) {
|
2015-11-23 20:37:39 +01:00
|
|
|
Block block1 = world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getBlock();
|
|
|
|
Block block2 = world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock();
|
|
|
|
Block block3 = world.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getBlock();
|
|
|
|
Block block4 = world.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getBlock();
|
2015-08-09 12:05:32 +02:00
|
|
|
|
|
|
|
byte b = 3;
|
|
|
|
|
2015-11-23 20:37:39 +01:00
|
|
|
if (block1.isOpaqueCube() && !block2.isOpaqueCube()) {
|
2015-08-09 12:05:32 +02:00
|
|
|
b = 3;
|
|
|
|
}
|
2015-11-23 20:37:39 +01:00
|
|
|
if (block2.isOpaqueCube() && !block1.isOpaqueCube()) {
|
2015-08-09 12:05:32 +02:00
|
|
|
b = 2;
|
|
|
|
}
|
2015-11-23 20:37:39 +01:00
|
|
|
if (block3.isOpaqueCube() && !block4.isOpaqueCube()) {
|
2015-08-09 12:05:32 +02:00
|
|
|
b = 5;
|
|
|
|
}
|
2015-11-23 20:37:39 +01:00
|
|
|
if (block4.isOpaqueCube() && !block3.isOpaqueCube()) {
|
2015-08-09 12:05:32 +02:00
|
|
|
b = 4;
|
|
|
|
}
|
|
|
|
|
2015-11-23 20:37:39 +01:00
|
|
|
//TODO 1.8 meta
|
|
|
|
// world.setBlockMetadataWithNotify(x, y, z, b, 2);
|
|
|
|
// setTileRotation(world, pos, b);
|
2015-08-09 12:05:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-23 20:37:39 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
|
|
|
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
|
|
|
|
|
|
|
//TODO fix rotaion
|
|
|
|
|
|
|
|
// int l = MathHelper
|
|
|
|
// .floor_double((double) (placer.rotationYaw * 4.0F / 360F) + 0.5D) & 3;
|
|
|
|
//
|
|
|
|
// if (l == 0) {
|
|
|
|
// setTileRotation(worldIn, pos, 2);
|
|
|
|
// }
|
|
|
|
// if (l == 1) {
|
|
|
|
// setTileRotation(worldIn, pos, 5);
|
|
|
|
// }
|
|
|
|
// if (l == 2) {
|
|
|
|
// setTileRotation(worldIn, pos, 3);
|
|
|
|
// }
|
|
|
|
// if (l == 3) {
|
|
|
|
// setTileRotation(worldIn, pos, 4);
|
|
|
|
// }
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-04-11 12:30:16 +02:00
|
|
|
}
|