Fixes for wrenching blocks. Closes #1417 and #1418

This commit is contained in:
drcrazy 2018-01-26 12:27:58 +03:00
parent 79582cd94b
commit 73b2f36b24
4 changed files with 101 additions and 15 deletions

View file

@ -24,12 +24,23 @@
package techreborn.blocks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.api.ToolManager;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import techreborn.client.EGui;
import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModBlocks;
import techreborn.init.ModSounds;
import techreborn.lib.ModInfo;
public class BlockComputerCube extends BlockMachineBase {
@ -43,6 +54,32 @@ public class BlockComputerCube extends BlockMachineBase {
@Override
public IMachineGuiHandler getGui() {
return EGui.MANUAL;
return null;
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (!tool.isEmpty() && ToolManager.INSTANCE.canHandleTool(tool)) {
if (ToolManager.INSTANCE.handleTool(tool, pos, worldIn, playerIn, side, false)) {
if (playerIn.isSneaking()) {
ItemStack drop = new ItemStack(ModBlocks.COMPUTER_CUBE, 1);
spawnAsEntity(worldIn, pos, drop);
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, ModSounds.BLOCK_DISMANTLE,
SoundCategory.BLOCKS, 0.6F, 1F);
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
else {
rotateBlock(worldIn, pos, side);
return true;
}
}
}
return false;
}
}

View file

@ -30,6 +30,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -47,6 +48,8 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.api.IToolDrop;
import reborncore.api.ToolManager;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.blocks.PropertyString;
@ -140,22 +143,51 @@ public class BlockPlayerDetector extends BlockMachineBase {
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer,
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity == null) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
String type = state.getValue(TYPE);
String newType = type;
TextFormatting color = TextFormatting.GREEN;
if (type.equals("all")) {
newType = "others";
color = TextFormatting.RED;
} else if (type.equals("others")) {
newType = "you";
color = TextFormatting.BLUE;
} else if (type.equals("you")) {
newType = "all";
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
if (playerIn.isSneaking()) {
if (tileEntity instanceof IToolDrop) {
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
if (drop == null) {
return false;
}
if (!drop.isEmpty()) {
spawnAsEntity(worldIn, pos, drop);
}
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
return true;
}
} else {
if (type.equals("all")) {
newType = "others";
color = TextFormatting.RED;
} else if (type.equals("others")) {
newType = "you";
color = TextFormatting.BLUE;
} else if (type.equals("you")) {
newType = "all";
}
worldIn.setBlockState(pos, state.withProperty(TYPE, newType));
}
}
}
world.setBlockState(pos, state.withProperty(TYPE, newType));
if (world.isRemote) {
if (worldIn.isRemote) {
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(
TextFormatting.GRAY + I18n.format("techreborn.message.detects") + " " + color
+ StringUtils.toFirstCapital(newType)));