Fix energy storage blocks not rotating

This commit is contained in:
modmuss50 2017-06-29 16:03:22 +01:00
parent 67acfaaab9
commit 81aee77869
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
3 changed files with 16 additions and 45 deletions

View file

@ -42,6 +42,7 @@ import prospector.shootingstar.model.ModelCompound;
import reborncore.common.BaseTileBlock; import reborncore.common.BaseTileBlock;
import techreborn.Core; import techreborn.Core;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.items.tools.ItemWrench;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import java.util.Iterator; import java.util.Iterator;
@ -68,6 +69,20 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing side, float hitX, float hitY, float hitZ) { EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack heldStack = player.getHeldItem(hand);
if(heldStack.getItem() instanceof ItemWrench){
if (state.getBlock() instanceof BlockEnergyStorage) {
EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
if (facing2.getOpposite() == side) {
facing2 = side;
} else {
facing2 = side.getOpposite();
}
world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing2));
return true;
}
}
if (!player.isSneaking()) if (!player.isSneaking())
player.openGui(Core.INSTANCE, guiID, world, pos.getX(), pos.getY(), pos.getZ()); player.openGui(Core.INSTANCE, guiID, world, pos.getX(), pos.getY(), pos.getZ());
return true; return true;

View file

@ -26,7 +26,6 @@ package techreborn.items.tools;
import net.minecraft.block.BlockDynamicLiquid; import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.block.BlockStaticLiquid; import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -46,10 +45,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.server.permission.PermissionAPI; import net.minecraftforge.server.permission.PermissionAPI;
import net.minecraftforge.server.permission.context.BlockPosContext; import net.minecraftforge.server.permission.context.BlockPosContext;
import reborncore.common.IWrenchable; import reborncore.common.IWrenchable;
import reborncore.common.tile.TileMachineBase;
import reborncore.common.util.RebornPermissions; import reborncore.common.util.RebornPermissions;
import techreborn.blocks.fluid.BlockFluidBase; import techreborn.blocks.fluid.BlockFluidBase;
import techreborn.blocks.storage.BlockEnergyStorage;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.compat.CompatManager; import techreborn.compat.CompatManager;
import techreborn.init.ModSounds; import techreborn.init.ModSounds;
@ -71,48 +68,6 @@ public class ItemWrench extends ItemTR {
setMaxStackSize(1); setMaxStackSize(1);
} }
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos,
EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (!PermissionAPI.hasPermission(player.getGameProfile(), RebornPermissions.WRENCH_BLOCK, new BlockPosContext(player, pos, world.getBlockState(pos), side))) {
return EnumActionResult.FAIL;
}
if (CompatManager.isIC2Loaded) {
EnumActionResult result = IC2WrenchHelper.onItemUseFirst(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ, hand);
if (result == EnumActionResult.SUCCESS) {
return result;
}
}
if (world.isAirBlock(pos)) {
return EnumActionResult.FAIL;
}
TileEntity tile = world.getTileEntity(pos);
if (tile == null) {
return EnumActionResult.FAIL;
}
if (!player.isSneaking()) {
if (tile instanceof TileMachineBase) {
if (side != EnumFacing.DOWN && side != EnumFacing.UP) {
((TileMachineBase) tile).setFacing(side);
return EnumActionResult.SUCCESS;
}
}
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockEnergyStorage) {
EnumFacing facing = state.getValue(BlockEnergyStorage.FACING);
if (facing.getOpposite() == side) {
facing = side;
} else {
facing = side.getOpposite();
}
world.setBlockState(pos, state.withProperty(BlockEnergyStorage.FACING, facing));
return EnumActionResult.SUCCESS;
}
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
@Override @Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

View file

@ -79,6 +79,7 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable,
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity();
if (inventory.getStackInSlot(0) != ItemStack.EMPTY) { if (inventory.getStackInSlot(0) != ItemStack.EMPTY) {
ItemStack stack = inventory.getStackInSlot(0); ItemStack stack = inventory.getStackInSlot(0);
if (!(stack.getItem() instanceof IEnergyItemInfo)) { if (!(stack.getItem() instanceof IEnergyItemInfo)) {