Merge pull request #4801 from thiakil/wrench-compat

Wrench compat
This commit is contained in:
Aidan authored and GitHub committed 2017-11-16 12:11:48 -05:00
commit 09e8e9aed7
17 files changed
+484 -127

No files matched your search

@@ -0,0 +1,51 @@
package cofh.api.item;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
/**
* Implement this interface on subclasses of Item to have that item work as a tool for CoFH mods.
*/
public interface IToolHammer {
/**
* Called to ensure that the tool can be used on a block.
*
* @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools).
* @param user The entity using the tool.
* @param pos Coordinates of the block.
* @return True if this tool can be used.
*/
boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos);
/**
* Called to ensure that the tool can be used on an entity.
*
* @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools).
* @param user The entity using the tool.
* @param entity The entity the tool is being used on.
* @return True if this tool can be used.
*/
boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity);
/**
* Callback for when the tool has been used reactively.
*
* @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools).
* @param user The entity using the tool.
* @param pos Coordinates of the block.
*/
void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos);
/**
* Callback for when the tool has been used reactively.
*
* @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools).
* @param user The entity using the tool.
* @param entity The entity the tool is being used on.
*/
void toolUsed(ItemStack item, EntityLivingBase user, Entity entity);
}
@@ -2,9 +2,19 @@ package mekanism.api;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
public interface IMekWrench
{
boolean canUseWrench(ItemStack stack, EntityPlayer player, BlockPos pos);
/* easier compat with BC */
default boolean canUseWrench(EntityPlayer player, EnumHand hand, ItemStack stack, RayTraceResult rayTrace)
{
return canUseWrench(stack, player, rayTrace.getBlockPos() != null ? rayTrace.getBlockPos() : BlockPos.ORIGIN);
}
default void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace){}
}
@@ -4,6 +4,7 @@ import java.util.Random;
import java.util.UUID;
import mekanism.api.Coord4D;
import mekanism.api.IMekWrench;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.common.Mekanism;
@@ -17,6 +18,7 @@ import mekanism.common.block.states.BlockStateBasic.BasicBlockType;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.content.boiler.SynchronizedBoilerData;
import mekanism.common.content.tank.TankUpdateProtocol;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.inventory.InventoryBin;
import mekanism.common.item.ItemBlockBasic;
import mekanism.common.multiblock.IMultiblock;
@@ -434,30 +436,31 @@ public abstract class BlockBasic extends Block
{
TileEntityBin bin = (TileEntityBin)tile;
if(!stack.isEmpty() && MekanismUtils.hasUsableWrench(entityplayer, pos))
IMekWrench wrenchHandler;
if(!stack.isEmpty() && (wrenchHandler = Wrenches.getHandler(stack)) != null)
{
if(!world.isRemote)
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
if (wrenchHandler.canUseWrench(entityplayer, hand, stack, raytrace))
{
Item tool = stack.getItem();
if(entityplayer.isSneaking())
if(!world.isRemote)
{
dismantleBlock(state, world, pos, false);
return true;
wrenchHandler.wrenchUsed(entityplayer, hand, stack, raytrace);
if(entityplayer.isSneaking())
{
dismantleBlock(state, world, pos, false);
return true;
}
int change = bin.facing.rotateY().ordinal();
bin.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
}
int change = bin.facing.rotateY().ordinal();
bin.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
return true;
}
return true;
}
if(!world.isRemote)
@@ -2,6 +2,7 @@ package mekanism.common.block;
import java.util.Random;
import mekanism.api.IMekWrench;
import mekanism.api.energy.IEnergizedItem;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
@@ -11,6 +12,7 @@ import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ITierItem;
import mekanism.common.block.states.BlockStateEnergyCube;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.item.ItemBlockEnergyCube;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
@@ -197,34 +199,34 @@ public class BlockEnergyCube extends BlockContainer
if(!stack.isEmpty())
{
Item tool = stack.getItem();
IMekWrench wrenchHandler = Wrenches.getHandler(stack);
if (wrenchHandler != null) {
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
if(wrenchHandler.canUseWrench(entityplayer, hand, stack, raytrace)) {
if(SecurityUtils.canAccess(entityplayer, tileEntity)) {
if(MekanismUtils.hasUsableWrench(entityplayer, pos))
{
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
if(entityplayer.isSneaking())
{
dismantleBlock(state, world, pos, false);
return true;
wrenchHandler.wrenchUsed(entityplayer, hand, stack, raytrace);
if(entityplayer.isSneaking())
{
dismantleBlock(state, world, pos, false);
return true;
}
if(tileEntity != null)
{
int change = tileEntity.facing.rotateAround(side.getAxis()).ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
} else {
SecurityUtils.displayNoAccess(entityplayer);
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
}
int change = tileEntity.facing.rotateAround(side.getAxis()).ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
return true;
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}
@@ -2,6 +2,7 @@ package mekanism.common.block;
import java.util.Random;
import mekanism.api.IMekWrench;
import mekanism.api.gas.IGasItem;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
@@ -10,6 +11,7 @@ import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ITierItem;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.block.states.BlockStateGasTank;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tile.TileEntityGasTank;
@@ -149,34 +151,37 @@ public class BlockGasTank extends BlockContainer
if(!stack.isEmpty())
{
Item tool = stack.getItem();
if(MekanismUtils.hasUsableWrench(entityplayer, pos))
IMekWrench wrenchHandler = Wrenches.getHandler(stack);
if (wrenchHandler != null)
{
if(SecurityUtils.canAccess(entityplayer, tileEntity))
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
if (wrenchHandler.canUseWrench(entityplayer, hand, stack, raytrace))
{
if(entityplayer.isSneaking())
if (SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(state, world, pos, false);
return true;
wrenchHandler.wrenchUsed(entityplayer, hand, stack, raytrace);
if(entityplayer.isSneaking())
{
dismantleBlock(state, world, pos, false);
return true;
}
if(tileEntity != null)
{
int change = tileEntity.facing.rotateY().ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
else {
SecurityUtils.displayNoAccess(entityplayer);
}
int change = tileEntity.facing.rotateY().ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
return true;
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}
@@ -4,6 +4,7 @@ import java.util.Random;
import java.util.UUID;
import mekanism.api.Coord4D;
import mekanism.api.IMekWrench;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.common.Mekanism;
@@ -25,6 +26,7 @@ import mekanism.common.block.states.BlockStateMachine.MachineBlock;
import mekanism.common.block.states.BlockStateMachine.MachineType;
import mekanism.common.config.MekanismConfig.client;
import mekanism.common.content.entangloporter.InventoryFrequency;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.item.ItemBlockMachine;
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
@@ -420,51 +422,55 @@ public abstract class BlockMachine extends BlockContainer
if(!stack.isEmpty())
{
Item tool = stack.getItem();
if(MekanismUtils.hasUsableWrench(entityplayer, pos))
IMekWrench wrenchHandler = Wrenches.getHandler(stack);
if(wrenchHandler != null)
{
if(SecurityUtils.canAccess(entityplayer, tileEntity))
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
if(wrenchHandler.canUseWrench(entityplayer, hand, stack, raytrace))
{
if(entityplayer.isSneaking())
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(state, world, pos, false);
wrenchHandler.wrenchUsed(entityplayer, hand, stack, raytrace);
return true;
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
}
int change = tileEntity.facing.rotateY().ordinal();
if(tileEntity instanceof TileEntityLogisticalSorter)
{
if(!((TileEntityLogisticalSorter)tileEntity).hasInventory())
if(entityplayer.isSneaking())
{
for(EnumFacing dir : EnumFacing.VALUES)
{
TileEntity tile = Coord4D.get(tileEntity).offset(dir).getTileEntity(world);
dismantleBlock(state, world, pos, false);
if(tile instanceof IInventory)
return true;
}
if(tileEntity != null)
{
int change = tileEntity.facing.rotateY().ordinal();
if(tileEntity instanceof TileEntityLogisticalSorter)
{
if(!((TileEntityLogisticalSorter)tileEntity).hasInventory())
{
change = dir.getOpposite().ordinal();
break;
for(EnumFacing dir : EnumFacing.VALUES)
{
TileEntity tile = Coord4D.get(tileEntity).offset(dir).getTileEntity(world);
if(tile instanceof IInventory)
{
change = dir.getOpposite().ordinal();
break;
}
}
}
}
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
}
else
{
SecurityUtils.displayNoAccess(entityplayer);
}
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
return true;
}
return true;
}
}
@@ -6,6 +6,7 @@ import java.util.Random;
import javax.annotation.Nullable;
import mekanism.api.IMekWrench;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.Tier.BaseTier;
@@ -15,6 +16,7 @@ import mekanism.common.block.states.BlockStateTransmitter;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.tile.transmitter.TileEntityDiversionTransporter;
import mekanism.common.tile.transmitter.TileEntityLogisticalTransporter;
import mekanism.common.tile.transmitter.TileEntityMechanicalPipe;
@@ -212,14 +214,19 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
return false;
}
if(MekanismUtils.hasUsableWrench(player, pos) && player.isSneaking())
IMekWrench wrenchHandler = Wrenches.getHandler(stack);
if(wrenchHandler != null)
{
if(!world.isRemote)
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos);
if(wrenchHandler.canUseWrench(player, hand, stack, raytrace) && player.isSneaking())
{
dismantleBlock(state, world, pos, false);
}
if(!world.isRemote)
{
dismantleBlock(state, world, pos, false);
}
return true;
return true;
}
}
return false;
@@ -17,6 +17,7 @@ import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.integration.computer.CCPeripheral;
import mekanism.common.integration.computer.OCDriver;
import mekanism.common.integration.crafttweaker.CrafttweakerIntegration;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.util.MekanismUtils;
import net.minecraft.init.Items;
@@ -35,6 +36,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
public final class MekanismHooks
{
public static final String COFH_CORE_MOD_ID = "cofhcore";
public static final String COFH_API_MOD_ID = "cofhapi";
public static final String IC2_MOD_ID = "ic2";
public static final String RAILCRAFT_MOD_ID = "railcraft";
public static final String THERMALEXPANSION_MOD_ID = "thermalexpansion";
@@ -97,6 +99,8 @@ public final class MekanismHooks
{
CrafttweakerIntegration.applyRecipeChanges();
}
Wrenches.initialise();
}
@Method(modid = MekanismHooks.IC2_MOD_ID)
@@ -0,0 +1,44 @@
package mekanism.common.integration.wrenches;
import buildcraft.api.tools.IToolWrench;
import mekanism.api.IMekWrench;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
/**
* Translates to Buildcraft's IToolWrench
*/
public class BuildCraftProxy implements MekWrenchProxy, IMekWrench
{
public static final String BUILDCRAFT_WRENCH_CLASS = "buildcraft.api.tools.IToolWrench";
@Override
public IMekWrench get(ItemStack stack)
{
return stack.getItem() instanceof IToolWrench ? this : null;
}
@Override
public boolean canUseWrench(ItemStack stack, EntityPlayer player, BlockPos pos)
{
return false;//compat only, needs raytrace
}
@Override
public boolean canUseWrench(EntityPlayer player, EnumHand hand, ItemStack stack, RayTraceResult rayTrace)
{
return stack.getItem() instanceof IToolWrench && ((IToolWrench)stack.getItem()).canWrench(player, hand, stack, rayTrace);
}
@Override
public void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack stack, RayTraceResult rayTrace)
{
if(stack.getItem() instanceof IToolWrench)
{
((IToolWrench)stack.getItem()).wrenchUsed(player, hand, stack, rayTrace);
}
}
}
@@ -0,0 +1,44 @@
package mekanism.common.integration.wrenches;
import cofh.api.item.IToolHammer;
import mekanism.api.IMekWrench;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
/**
* Translates to COFH's IToolHammer
*/
public class CofhProxy implements MekWrenchProxy, IMekWrench
{
public static final String COFH_HAMMER_CLASS = "cofh.api.item.IToolHammer";
@Override
public IMekWrench get(ItemStack stack)
{
return stack.getItem() instanceof IToolHammer ? this : null;
}
@Override
public boolean canUseWrench(ItemStack stack, EntityPlayer player, BlockPos pos)
{
return stack.getItem() instanceof IToolHammer && ((IToolHammer)stack.getItem()).isUsable(stack, player, pos);
}
// uses default method
//@Override
//public boolean canUseWrench(EntityPlayer player, EnumHand hand, ItemStack stack, RayTraceResult rayTrace) {
// return false;
//}
@Override
public void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace)
{
if(wrench.getItem() instanceof IToolHammer)
{
((IToolHammer)wrench.getItem()).toolUsed(wrench, player, rayTrace.getBlockPos() != null ? rayTrace.getBlockPos() : BlockPos.ORIGIN);
}
}
}
@@ -0,0 +1,41 @@
package mekanism.common.integration.wrenches;
import mekanism.api.IMekWrench;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
/**
* Translates to IC2's wrench via reflection as it's an internal class.
*/
public class IC2Proxy implements MekWrenchProxy, IMekWrench
{
public static final String IC2_WRENCH_CLASS = "ic2.core.item.tool.ItemToolWrench";
private final Class<?> wrenchClass;
public IC2Proxy(){
Class<?> w = null;
try
{
w = Class.forName(IC2_WRENCH_CLASS);
}
catch(ClassNotFoundException e)
{
//no-op
}
this.wrenchClass = w;
}
@Override
public boolean canUseWrench(ItemStack stack, EntityPlayer player, BlockPos pos)
{
return this.wrenchClass != null && this.wrenchClass.isInstance(stack.getItem());
}
@Override
public IMekWrench get(ItemStack stack)
{
return this.wrenchClass != null && this.wrenchClass.isInstance(stack.getItem()) ? this : null;
}
}
@@ -0,0 +1,16 @@
package mekanism.common.integration.wrenches;
import mekanism.api.IMekWrench;
import net.minecraft.item.ItemStack;
/**
* Default handler for IMekWrench items, returns the Itemstack#item
*/
public class MekPassthrough implements MekWrenchProxy
{
@Override
public IMekWrench get(ItemStack stack)
{
return stack.getItem() instanceof IMekWrench ? (IMekWrench)stack.getItem() : null;
}
}
@@ -0,0 +1,17 @@
package mekanism.common.integration.wrenches;
import mekanism.api.IMekWrench;
import net.minecraft.item.ItemStack;
/**
* Abstraction for non-Mek wrench providers.
*/
public interface MekWrenchProxy
{
/**
* Get a handler for the wrench
* @param stack the instance to be used.
* @return a IMekWrench instance that can handle translation to the external provider.
*/
IMekWrench get(ItemStack stack);
}
@@ -0,0 +1,76 @@
package mekanism.common.integration.wrenches;
import mekanism.api.IMekWrench;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.function.Supplier;
/**
* Generic handler for wrenches, exposed as {@link IMekWrench}.
* Generally you don't want to use the enum directly, instead use {@link Wrenches#getHandler(ItemStack)},
* and check for nullability.
*/
public enum Wrenches
{
MEKANISM_PASSTHROUGH(IMekWrench.class.getName(), MekPassthrough::new),
BUILDCRAFT(BuildCraftProxy.BUILDCRAFT_WRENCH_CLASS, BuildCraftProxy::new),
COFH(CofhProxy.COFH_HAMMER_CLASS, CofhProxy::new),
IC2(IC2Proxy.IC2_WRENCH_CLASS, IC2Proxy::new),
;
private final String classname;
private Class<?> itemClass;
private final Supplier<MekWrenchProxy> mekProxy;
private boolean enabled;
private MekWrenchProxy provider;
Wrenches(String clazz, Supplier<MekWrenchProxy> mekProxy)
{
this.classname = clazz;
this.mekProxy = mekProxy;
}
private boolean canHandle(ItemStack it)
{
return (enabled && provider != null && itemClass != null && itemClass.isInstance(it.getItem()));
}
public static void initialise()
{
for(Wrenches w : values())
{
try
{
w.itemClass = Class.forName(w.classname);
} catch(ClassNotFoundException e)
{
w.enabled = false;
w.provider = null;
w.itemClass = null;
continue;
}
try
{
w.provider = w.mekProxy.get();
} catch(Exception e)
{
w.enabled = false;
w.provider = null;
}
}
}
public static @Nullable
IMekWrench getHandler(ItemStack it)
{
for(Wrenches w : values())
{
if(w.canHandle(it))
{
return w.provider.get(it);
}
}
return null;
}
}
@@ -1,5 +1,6 @@
package mekanism.common.item;
import cofh.api.item.IToolHammer;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@@ -31,6 +32,8 @@ import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -54,9 +57,10 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@InterfaceList({
@Interface(iface = "buildcraft.api.tools.IToolWrench", modid = MekanismHooks.BUILDCRAFT_MOD_ID)
@Interface(iface = "buildcraft.api.tools.IToolWrench", modid = MekanismHooks.BUILDCRAFT_MOD_ID),
@Interface(iface = "cofh.api.item.IToolHammer", modid = MekanismHooks.COFH_API_MOD_ID)
})
public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench, IItemNetwork
public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench, IItemNetwork, IToolHammer
{
public final int ENERGY_PER_CONFIGURE = 400;
public final int ENERGY_PER_ITEM_DUMP = 8;
@@ -283,7 +287,25 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool
{
return getState(stack) == ConfiguratorMode.WRENCH;
}
/*cofh IToolHammer */
@Override
public boolean isUsable(ItemStack stack, EntityLivingBase user, BlockPos pos) {
return getState(stack) == ConfiguratorMode.WRENCH;
}
@Override
public boolean isUsable(ItemStack stack, EntityLivingBase user, Entity entity) {
return getState(stack) == ConfiguratorMode.WRENCH;
}
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos) {}
@Override
public void toolUsed(ItemStack item, EntityLivingBase user, Entity entity) {}
/*end cofh IToolHammer */
public enum ConfiguratorMode
{
CONFIGURATE_ITEMS("configurate", "(" + TransmissionType.ITEM.localize() + ")", EnumColor.BRIGHT_GREEN, true),
@@ -1496,7 +1496,10 @@ public final class MekanismUtils
* @param player - the player using the wrench
* @param pos - the coordinate of the block being wrenched
* @return if the player can use the wrench
*
* @deprecated use {@link mekanism.common.integration.wrenches.Wrenches#getHandler(ItemStack)}
*/
@Deprecated
public static boolean hasUsableWrench(EntityPlayer player, BlockPos pos)
{
ItemStack tool = player.inventory.getCurrentItem();
@@ -2,6 +2,7 @@ package mekanism.generators.common.block;
import java.util.Random;
import mekanism.api.IMekWrench;
import mekanism.api.energy.IEnergizedItem;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
@@ -11,6 +12,7 @@ import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ISustainedTank;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.config.MekanismConfig.client;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.multiblock.IMultiblock;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
@@ -378,34 +380,38 @@ public abstract class BlockGenerator extends BlockContainer
if(!stack.isEmpty())
{
Item tool = stack.getItem();
if(MekanismUtils.hasUsableWrench(entityplayer, pos))
IMekWrench wrenchHandler = Wrenches.getHandler(stack);
if(wrenchHandler != null)
{
if(SecurityUtils.canAccess(entityplayer, tileEntity))
RayTraceResult raytrace = new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos);
if(wrenchHandler.canUseWrench(entityplayer, hand, stack, raytrace))
{
if(entityplayer.isSneaking())
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(state, world, pos, false);
return true;
wrenchHandler.wrenchUsed(entityplayer, hand, stack, raytrace);
if(entityplayer.isSneaking())
{
dismantleBlock(state, world, pos, false);
return true;
}
if(tileEntity != null)
{
int change = tileEntity.facing.rotateY().ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
}
}
if(MekanismUtils.isBCWrench(tool))
else
{
((IToolWrench)tool).wrenchUsed(entityplayer, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
SecurityUtils.displayNoAccess(entityplayer);
}
int change = tileEntity.facing.rotateY().ordinal();
tileEntity.setFacing((short)change);
world.notifyNeighborsOfStateChange(pos, this, true);
return true;
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}