Add support for wrenches from other mods.
This commit is contained in:
parent
ffe13d0c79
commit
2e1c469524
3 changed files with 39 additions and 7 deletions
|
@ -46,7 +46,7 @@ import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraftforge.energy.CapabilityEnergy;
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
import reborncore.api.IToolHandler;
|
import reborncore.api.ToolManager;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.init.ModSounds;
|
import techreborn.init.ModSounds;
|
||||||
|
@ -89,9 +89,8 @@ public class BlockCable extends BlockContainer {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||||
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
if (!stack.isEmpty() && stack.getItem() instanceof IToolHandler && playerIn.isSneaking()) {
|
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack) && playerIn.isSneaking()) {
|
||||||
IToolHandler toolHandler = (IToolHandler) stack.getItem();
|
if (ToolManager.INSTANCE.handleTool(stack, pos, world, playerIn, facing, false)) {
|
||||||
if (toolHandler.handleTool(stack, pos, world, playerIn, facing, false)) {
|
|
||||||
ItemStack drop = state.getValue(TYPE).getStack();
|
ItemStack drop = state.getValue(TYPE).getStack();
|
||||||
if (drop == null) {
|
if (drop == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -39,7 +39,7 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
import reborncore.api.IToolHandler;
|
import reborncore.api.ToolManager;
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.common.BaseTileBlock;
|
||||||
import techreborn.Core;
|
import techreborn.Core;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
|
@ -70,8 +70,8 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
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);
|
ItemStack heldStack = player.getHeldItem(hand);
|
||||||
if(heldStack.getItem() instanceof IToolHandler){
|
if(ToolManager.INSTANCE.canHandleTool(heldStack)){
|
||||||
if(((IToolHandler) heldStack.getItem()).handleTool(heldStack, pos, world, player, side, true)){
|
if(ToolManager.INSTANCE.handleTool(heldStack, pos, world, player, side, true)){
|
||||||
if (state.getBlock() instanceof BlockEnergyStorage) {
|
if (state.getBlock() instanceof BlockEnergyStorage) {
|
||||||
EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
|
EnumFacing facing2 = state.getValue(BlockEnergyStorage.FACING);
|
||||||
if (facing2.getOpposite() == side) {
|
if (facing2.getOpposite() == side) {
|
||||||
|
|
33
src/main/java/techreborn/utils/GenericWrenchHelper.java
Normal file
33
src/main/java/techreborn/utils/GenericWrenchHelper.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package techreborn.utils;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import reborncore.api.ICustomToolHandler;
|
||||||
|
|
||||||
|
public class GenericWrenchHelper implements ICustomToolHandler {
|
||||||
|
|
||||||
|
ResourceLocation itemLocation;
|
||||||
|
boolean damage;
|
||||||
|
|
||||||
|
public GenericWrenchHelper(ResourceLocation itemLocation, boolean damage) {
|
||||||
|
this.itemLocation = itemLocation;
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canHandleTool(ItemStack stack) {
|
||||||
|
return stack.getItem().getRegistryName().equals(itemLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleTool(ItemStack stack, BlockPos pos, World world, EntityPlayer player, EnumFacing side, boolean damage) {
|
||||||
|
if(this.damage && damage){
|
||||||
|
stack.damageItem(1, player);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue