TechReborn/src/main/java/techreborn/blocks/BlockQuantumChest.java

129 lines
4.1 KiB
Java
Raw Normal View History

2015-04-11 12:30:16 +02:00
package techreborn.blocks;
2015-07-02 20:51:24 +02:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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-04-11 18:20:53 +02:00
import net.minecraft.client.renderer.texture.IIconRegister;
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-04-11 18:20:53 +02:00
import net.minecraft.util.IIcon;
2015-06-19 01:56:07 +02:00
import net.minecraft.util.MathHelper;
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
@SideOnly(Side.CLIENT)
private IIcon iconFront;
@SideOnly(Side.CLIENT)
private IIcon iconTop;
@SideOnly(Side.CLIENT)
private IIcon iconBottom;
public BlockQuantumChest() {
super(Material.rock);
setBlockName("techreborn.quantumChest");
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(2.0F);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileQuantumChest();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x,
y, z);
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
this.blockIcon = icon.registerIcon("techreborn:machine/qchest_side");
this.iconFront = icon.registerIcon("techreborn:machine/quantum_chest");
this.iconTop = icon.registerIcon("techreborn:machine/quantum_top");
this.iconBottom = icon.registerIcon("techreborn:machine/machine_bottom");
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return metadata == 0 && side == 3 ? this.iconFront
: side == 1 ? this.iconTop :
side == 0 ? this.iconBottom : (side == 0 ? this.iconTop
: (side == metadata ? this.iconFront : this.blockIcon));
}
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.setDefaultDirection(world, x, y, z);
}
private void setDefaultDirection(World world, int x, int y, int z) {
if (!world.isRemote) {
Block block1 = world.getBlock(x, y, z - 1);
Block block2 = world.getBlock(x, y, z + 1);
Block block3 = world.getBlock(x - 1, y, z);
Block block4 = world.getBlock(x + 1, y, z);
byte b = 3;
if (block1.func_149730_j() && !block2.func_149730_j()) {
b = 3;
}
if (block2.func_149730_j() && !block1.func_149730_j()) {
b = 2;
}
if (block3.func_149730_j() && !block4.func_149730_j()) {
b = 5;
}
if (block4.func_149730_j() && !block3.func_149730_j()) {
b = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b, 2);
}
}
public void onBlockPlacedBy(World world, int x, int y, int z,
EntityLivingBase player, ItemStack itemstack) {
int l = MathHelper
.floor_double((double) (player.rotationYaw * 4.0F / 360F) + 0.5D) & 3;
if (l == 0) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1) {
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2) {
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3) {
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
2015-06-19 01:56:07 +02:00
super.onBlockPlacedBy(world, x, y, z, player, itemstack);
}
2015-04-11 12:30:16 +02:00
}