mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 13:09:42 +00:00
Camo block now respects directional blocks. Closes #110
This commit is contained in:
4 files changed
+21
-33
No files matched your search
@@ -13,6 +13,7 @@ package vazkii.botania.common.block;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirectional;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -25,6 +26,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.common.block.tile.TileCamo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BlockCamo extends BlockMod {
|
||||
|
||||
protected BlockCamo(Material par2Material, String name) {
|
||||
@@ -36,37 +40,20 @@ public abstract class BlockCamo extends BlockMod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, BlockPos pos, IBlockState state, EntityPlayer par5EntityPlayer, EnumHand hand, ItemStack currentStack, EnumFacing par6, float par7, float par8, float par9) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean onBlockActivated(World par1World, BlockPos pos, IBlockState state, EntityPlayer par5EntityPlayer, EnumHand hand, ItemStack currentStack, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
TileEntity tile = par1World.getTileEntity(pos);
|
||||
|
||||
if(tile instanceof TileCamo) {
|
||||
if(par1World.isRemote)
|
||||
return true;
|
||||
|
||||
if(currentStack != null
|
||||
&& Block.getBlockFromItem(currentStack.getItem()) != null
|
||||
&& tile instanceof TileCamo) {
|
||||
TileCamo camo = (TileCamo) tile;
|
||||
IBlockState changeState = Block.getBlockFromItem(currentStack.getItem()).onBlockPlaced(par1World, pos, side, hitX, hitY, hitZ, currentStack.getItemDamage(), par5EntityPlayer);
|
||||
|
||||
if(currentStack == null)
|
||||
currentStack = new ItemStack(Block.getBlockFromName("air"), 1, 0);
|
||||
|
||||
boolean doChange = true;
|
||||
IBlockState testState = null;
|
||||
checkChange : {
|
||||
if(currentStack.getItem() != Item.getItemFromBlock(Block.getBlockFromName("air"))) {
|
||||
if(Item.getIdFromItem(currentStack.getItem()) == 0) {
|
||||
doChange = false;
|
||||
break checkChange;
|
||||
}
|
||||
|
||||
testState = Block.getBlockFromItem(currentStack.getItem()).getStateFromMeta(currentStack.getItemDamage());
|
||||
if(testState == null || !isValidBlock(testState) || testState.getBlock() instanceof BlockCamo || testState.getMaterial() == Material.air)
|
||||
doChange = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(doChange && currentStack.getItem() != null) {
|
||||
IBlockState changeState = Block.getBlockFromItem(currentStack.getItem()).getStateFromMeta(currentStack.getItemDamage());
|
||||
if(testState.getBlock() instanceof BlockDirectional) {
|
||||
if (BlockDirectional.FACING.getAllowedValues().contains(par6.getOpposite())) {
|
||||
changeState = changeState.withProperty(BlockDirectional.FACING, par6.getOpposite());
|
||||
}
|
||||
}
|
||||
if(isValidBlock(changeState) && !(changeState.getBlock() instanceof BlockCamo) && changeState.getMaterial() != Material.air) {
|
||||
camo.camoState = changeState;
|
||||
par1World.notifyBlockUpdate(pos, state, state, 8);
|
||||
|
||||
|
||||
Reference in new issue
Block a user