Skip to content

Commit

Permalink
More tool compat
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 13, 2023
1 parent fff0028 commit 4c7cb71
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
78 changes: 78 additions & 0 deletions src/api/java/mods/railcraft/api/items/IToolCrowbar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*------------------------------------------------------------------------------
Copyright (c) CovertJaguar, 2011-2020
This work (the API) is licensed under the "MIT" License,
see LICENSE.md for details.
-----------------------------------------------------------------------------*/
package mods.railcraft.api.items;

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

/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface IToolCrowbar {
String ORE_TAG = "toolCrowbar";

/**
* Controls non-rotational interactions with blocks. Crowbar specific stuff.
* <p/>
* Rotational interaction is handled by the Block.rotateBlock() function,
* which should be called from the Item.onUseFirst() function of your tool.
*
* @param player the player
* @param crowbar the crowbar
* @param pos the block @return true if can whack a block
*/
boolean canWhack(EntityPlayer player, EnumHand hand, ItemStack crowbar, BlockPos pos);

/**
* Callback to do damage to the item.
*
* @param player the player
* @param crowbar the crowbar
* @param pos the block
*/
void onWhack(EntityPlayer player, EnumHand hand, ItemStack crowbar, BlockPos pos);

/**
* Controls whether you can link a cart.
*
* @param player the player
* @param crowbar the crowbar
* @param cart the cart @return true if can link a cart
*/
boolean canLink(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart);

/**
* Callback to do damage.
*
* @param player the player
* @param crowbar the crowbar
* @param cart the cart
*/
void onLink(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart);

/**
* Controls whether you can boost a cart.
*
* @param player the player
* @param crowbar the crowbar
* @param cart the cart @return true if can boost a cart
*/
boolean canBoost(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart);

/**
* Callback to do damage, boosting a cart usually does more damage than
* normal usage.
*
* @param player the player
* @param crowbar the crowbar
* @param cart the cart
*/
void onBoost(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart);
}
11 changes: 11 additions & 0 deletions src/api/java/mrtjp/projectred/api/IScrewdriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mrtjp.projectred.api;

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

public interface IScrewdriver {

boolean canUse(EntityPlayer player, ItemStack stack);

void damageScrewdriver(EntityPlayer player, ItemStack stack); // Damage the item on usage
}
4 changes: 3 additions & 1 deletion src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public class GTValues {
MODID_ET = "extratrees",
MODID_GENETICS = "genetics",
MODID_BOP = "biomesoplenty",
MODID_TCON = "tconstruct";
MODID_TCON = "tconstruct",
MODID_PROJRED_CORE = "projectred-core",
MODID_RC = "railcraft";

private static Boolean isClient;

Expand Down
52 changes: 51 additions & 1 deletion src/main/java/gregtech/api/items/toolitem/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import gregtech.client.utils.TooltipHelper;
import gregtech.common.ConfigHolder;

import mods.railcraft.api.items.IToolCrowbar;
import mrtjp.projectred.api.IScrewdriver;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.I18n;
Expand All @@ -40,6 +43,7 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.EntityEquipmentSlot;
Expand Down Expand Up @@ -91,10 +95,12 @@
@Optional.Interface(modid = GTValues.MODID_COFH, iface = "cofh.api.item.IToolHammer"),
@Optional.Interface(modid = GTValues.MODID_EIO, iface = "crazypants.enderio.api.tool.ITool"),
@Optional.Interface(modid = GTValues.MODID_FR, iface = "forestry.api.arboriculture.IToolGrafter"),
@Optional.Interface(modid = GTValues.MODID_PROJRED_CORE, iface = "mrtjp.projectred.api.IScrewdriver"),
@Optional.Interface(modid = GTValues.MODID_RC, iface = "mods.railcraft.api.items.IToolCrowbar"),
@Optional.Interface(modid = GTValues.MODID_ECORE,
iface = "com.enderio.core.common.interfaces.IOverlayRenderAware") })
public interface IGTTool extends ItemUIFactory, IAEWrench, IToolWrench, IToolHammer, ITool, IToolGrafter,
IOverlayRenderAware {
IOverlayRenderAware, IScrewdriver, IToolCrowbar {

/**
* @return the modid of the tool
Expand Down Expand Up @@ -1042,4 +1048,48 @@ default float getSaplingModifier(ItemStack stack, World world, EntityPlayer play
default void renderItemOverlayIntoGUI(@NotNull ItemStack stack, int xPosition, int yPosition) {
ToolChargeBarRenderer.renderBarsTool(this, stack, xPosition, yPosition);
}

// IScrewdriver
@Override
default boolean canUse(EntityPlayer player, ItemStack stack) {
return get().getToolClasses(stack).contains(ToolClasses.SCREWDRIVER);
}

@Override
default void damageScrewdriver(EntityPlayer player, ItemStack stack) {
damageItem(stack, player);
}

// IToolCrowbar

@Override
default boolean canWhack(EntityPlayer player, EnumHand hand, ItemStack crowbar, BlockPos pos) {
return get().getToolClasses(crowbar).contains(ToolClasses.CROWBAR);
}

@Override
default void onWhack(EntityPlayer player, EnumHand hand, ItemStack crowbar, BlockPos pos) {
damageItem(crowbar, player);
}

@Override
default boolean canLink(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart) {
return get().getToolClasses(crowbar).contains(ToolClasses.CROWBAR);
}


@Override
default void onLink(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart) {
damageItem(crowbar, player);
}

@Override
default boolean canBoost(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart) {
return get().getToolClasses(crowbar).contains(ToolClasses.CROWBAR);
}

@Override
default void onBoost(EntityPlayer player, EnumHand hand, ItemStack crowbar, EntityMinecart cart) {
damageItem(crowbar, player);
}
}

0 comments on commit 4c7cb71

Please sign in to comment.