Skip to content

Commit

Permalink
add BC, AE, EIO, Thermal wrench support
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 8, 2021
1 parent b95530b commit e6d8481
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 14 deletions.
22 changes: 22 additions & 0 deletions src/api/java/appeng/api/implementations/items/IAEWrench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package appeng.api.implementations.items;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

/**
* Implemented on AE's wrench(s) as a substitute for if BC's API is not
* available.
*/
public interface IAEWrench {

/**
* Check if the wrench can be used.
*
* @param player wrenching player
* @param pos of block.
*
* @return true if wrench can be used
*/
boolean canWrench(ItemStack wrench, EntityPlayer player, BlockPos pos);
}
32 changes: 32 additions & 0 deletions src/api/java/buildcraft/api/tools/IToolWrench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
package buildcraft.api.tools;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;

/*** Implement this interface on subclasses of Item to have that item work as a wrench for buildcraft */
public interface IToolWrench {

/*** Called to ensure that the wrench can be used.
*
* @param player - The player doing the wrenching
* @param hand - Which hand was holding the wrench
* @param wrench - The item stack that holds the wrench
* @param rayTrace - The object that is being wrenched
*
* @return true if wrenching is allowed, false if not */
boolean canWrench(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace);

/*** Callback after the wrench has been used. This can be used to decrease durability or for other purposes.
*
* @param player - The player doing the wrenching
* @param hand - Which hand was holding the wrench
* @param wrench - The item stack that holds the wrench
* @param rayTrace - The object that is being wrenched */
void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace);
}
14 changes: 14 additions & 0 deletions src/api/java/cofh/api/item/IToolHammer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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;

public interface IToolHammer {

boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos);
boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity);
void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos);
void toolUsed(ItemStack item, EntityLivingBase user, Entity entity);
}
20 changes: 20 additions & 0 deletions src/api/java/crazypants/enderio/api/tool/IConduitControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package crazypants.enderio.api.tool;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

public interface IConduitControl {

/**
* Controls whether the overlay is shown and the player can change the display mode.
*
* @param stack
* The itemstack
* @param player
* The player holding the itemstack
* @return True if the overlay should be rendered and the player should be able to change modes. False otherwise.
*/
boolean showOverlay(@Nonnull ItemStack stack, @Nonnull EntityPlayer player);
}
11 changes: 11 additions & 0 deletions src/api/java/crazypants/enderio/api/tool/IHideFacades.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package crazypants.enderio.api.tool;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

public interface IHideFacades {

boolean shouldHideFacades(@Nonnull ItemStack stack, @Nonnull EntityPlayer player);
}
14 changes: 14 additions & 0 deletions src/api/java/crazypants/enderio/api/tool/ITool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package crazypants.enderio.api.tool;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;

import javax.annotation.Nonnull;

public interface ITool extends IHideFacades {

boolean canUse(@Nonnull EnumHand stack, @Nonnull EntityPlayer player, @Nonnull BlockPos pos);

void used(@Nonnull EnumHand stack, @Nonnull EntityPlayer player, @Nonnull BlockPos pos);
}
6 changes: 5 additions & 1 deletion src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public class GTValues {
MODID_TOP = "theoneprobe",
MODID_CTM = "ctm",
MODID_CC = "cubicchunks",
MODID_AR = "advancedrocketry";
MODID_AR = "advancedrocketry",
MODID_EIO = "enderio",
MODID_BC = "buildcraftcore",
MODID_COFH = "cofhcore",
MODID_APPENG = "appliedenergistics2";

//because forge is too fucking retarded to cache results or at least do not create fucking
//immutable collections every time you retrieve indexed mod list
Expand Down
117 changes: 104 additions & 13 deletions src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package gregtech.api.items.toolitem;

import appeng.api.implementations.items.IAEWrench;
import buildcraft.api.tools.IToolWrench;
import cofh.api.item.IToolHammer;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import crazypants.enderio.api.tool.ITool;
import forestry.api.arboriculture.IToolGrafter;
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
Expand All @@ -23,6 +27,8 @@
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.common.ConfigHolder;
import gregtech.common.tools.DamageValues;
import gregtech.common.tools.ToolWrench;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
Expand All @@ -39,13 +45,15 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.Optional.Interface;
import net.minecraftforge.fml.common.Optional.InterfaceList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
Expand All @@ -68,8 +76,13 @@
* @see IToolStats
* @see MetaItem
*/
@Interface(modid = GTValues.MODID_FR, iface = "forestry.api.arboriculture.IToolGrafter")
public class ToolMetaItem<T extends ToolMetaItem<?>.MetaToolValueItem> extends MetaItem<T> implements IToolItem, IAOEItem, IToolGrafter {
@InterfaceList({
@Interface(modid = GTValues.MODID_FR, iface = "forestry.api.arboriculture.IToolGrafter"),
@Interface(modid = GTValues.MODID_BC, iface = "buildcraft.api.tools.IToolWrench"),
@Interface(modid = GTValues.MODID_EIO, iface = "crazypants.enderio.api.tool.ITool"),
@Interface(modid = GTValues.MODID_COFH, iface = "cofh.api.item.IToolHammer"),
@Interface(modid = GTValues.MODID_APPENG, iface = "appeng.api.implementations.items.IAEWrench")})
public class ToolMetaItem<T extends ToolMetaItem<?>.MetaToolValueItem> extends MetaItem<T> implements IToolItem, IAOEItem, IToolGrafter, IToolWrench, ITool, IToolHammer, IAEWrench {

public ToolMetaItem() {
super((short) 0);
Expand Down Expand Up @@ -617,6 +630,95 @@ public static Material getToolMaterial(ItemStack itemStack) {
return Materials.Neutronium;
}

@Override
@Nonnull
public Set<String> getToolClasses(@Nonnull ItemStack stack) {
T metaToolValueItem = getItem(stack);
if (metaToolValueItem != null) {
IToolStats toolStats = metaToolValueItem.getToolStats();
return toolStats.getToolClasses(stack);
}
return Collections.emptySet();
}

// BuildCraft Wrench Compat
@Override
public boolean canWrench(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace) {
T metaToolValueItem = getItem(player.getHeldItem(hand));
if (metaToolValueItem != null) {
return metaToolValueItem.getToolStats() instanceof ToolWrench;
}
return false;
}

@Override
public void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack wrench, RayTraceResult rayTrace) {
this.damageItem(player.getHeldItem(hand), DamageValues.DAMAGE_FOR_WRENCH, false);
}

// CoFH Hammer Compat
@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos) {
T metaToolValueItem = getItem(item);
if (metaToolValueItem != null) {
return metaToolValueItem.getToolStats() instanceof ToolWrench;
}
return false;
}

@Override
public boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity) {
T metaToolValueItem = getItem(item);
if (metaToolValueItem != null) {
return metaToolValueItem.getToolStats() instanceof ToolWrench;
}
return false;
}

@Override
public void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos) {
this.damageItem(item, DamageValues.DAMAGE_FOR_WRENCH, false);
}

@Override
public void toolUsed(ItemStack item, EntityLivingBase user, Entity entity) {
this.damageItem(item, DamageValues.DAMAGE_FOR_WRENCH, false);
}

// EIO Wrench Compat
@Override
public boolean shouldHideFacades(@Nonnull ItemStack stack, @Nonnull EntityPlayer player) {
return false;
}

@Override
public boolean canUse(@Nonnull EnumHand stack, @Nonnull EntityPlayer player, @Nonnull BlockPos pos) {
T metaToolValueItem = getItem(player.getHeldItem(stack));
if (metaToolValueItem != null) {
return metaToolValueItem.getToolStats() instanceof ToolWrench;
}
return false;
}

@Override
public void used(@Nonnull EnumHand stack, @Nonnull EntityPlayer player, @Nonnull BlockPos pos) {
this.damageItem(player.getHeldItem(stack), DamageValues.DAMAGE_FOR_WRENCH, false);
}

// Applied Energistics Wrench Compat
@Override
public boolean canWrench(ItemStack wrench, EntityPlayer player, BlockPos pos) {
T metaToolValueItem = getItem(wrench);
if (metaToolValueItem != null) {
IToolStats toolStats = metaToolValueItem.getToolStats();
if (toolStats instanceof ToolWrench) {
damageItem(wrench, DamageValues.DAMAGE_FOR_WRENCH, false);
return true;
}
}
return false;
}

public class MetaToolValueItem extends MetaValueItem {

protected IToolStats toolStats = new DummyToolStats();
Expand Down Expand Up @@ -771,15 +873,4 @@ private Map<Enchantment, Integer> bakeEnchantmentsMap(ItemStack itemStack, Colle
return enchantments;
}
}

@Override
@Nonnull
public Set<String> getToolClasses(@Nonnull ItemStack stack) {
T metaToolValueItem = getItem(stack);
if (metaToolValueItem != null) {
IToolStats toolStats = metaToolValueItem.getToolStats();
return toolStats.getToolClasses(stack);
}
return Collections.emptySet();
}
}

0 comments on commit e6d8481

Please sign in to comment.