Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tool compat #2292

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 49 additions & 1 deletion src/main/java/gregtech/api/items/toolitem/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -68,6 +69,8 @@
import forestry.api.arboriculture.IToolGrafter;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import mods.railcraft.api.items.IToolCrowbar;
import mrtjp.projectred.api.IScrewdriver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -91,10 +94,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 +1047,47 @@ 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);
}
}