mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 19:59:55 +00:00
Allow Scythe to harvest IC2 crops
This commit is contained in:
1 parent
41e626e83c
commit
bcd0948f2a
6 files changed
+108
No files matched your search
@@ -15,4 +15,8 @@ dependencies {
|
||||
compileOnly("curse.maven:notenoughkeys-224614:2276280")
|
||||
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Mobs-Info:0.5.2-GTNH:dev")
|
||||
compileOnlyApi("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
|
||||
|
||||
// devOnlyNonPublishable("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package tconstruct.api.harvesting;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface CropHarvestHandler {
|
||||
|
||||
boolean couldHarvest(World world, int x, int y, int z);
|
||||
|
||||
boolean tryHarvest(ItemStack stack, EntityPlayer player, World world, int x, int y, int z);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package tconstruct.api.harvesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CropHarvestHandlers {
|
||||
|
||||
private static List<CropHarvestHandler> cropHarvestHandlers = new ArrayList<>();
|
||||
|
||||
public static void registerCropHarvestHandler(CropHarvestHandler handler) {
|
||||
cropHarvestHandlers.add(handler);
|
||||
}
|
||||
|
||||
public static List<CropHarvestHandler> getCropHarvestHandlers() {
|
||||
return Collections.unmodifiableList(cropHarvestHandlers);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import tconstruct.api.harvesting.CropHarvestHandler;
|
||||
import tconstruct.api.harvesting.CropHarvestHandlers;
|
||||
import tconstruct.library.ActiveToolMod;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.tools.AbilityHelper;
|
||||
@@ -292,4 +294,51 @@ public class Scythe extends Weapon {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
|
||||
float hitX, float hitY, float hitZ) {
|
||||
if (world.isRemote) {
|
||||
return false;
|
||||
}
|
||||
if (shouldHarvestInAoe(world, x, y, z)) {
|
||||
harvestInAoe(stack, player, world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean shouldHarvestInAoe(World world, int x, int y, int z) {
|
||||
for (CropHarvestHandler handler : CropHarvestHandlers.getCropHarvestHandlers()) {
|
||||
if (handler.couldHarvest(world, x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void harvestInAoe(ItemStack stack, EntityPlayer player, World world, int x, int y, int z) {
|
||||
for (int i = -2; i < 3; i++) {
|
||||
for (int j = -2; j < 3; j++) {
|
||||
for (int k = -2; k < 3; k++) {
|
||||
if (!(stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Broken"))) {
|
||||
harvestCrop(stack, player, world, x + i, y + j, z + k);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void harvestCrop(ItemStack stack, EntityPlayer player, World world, int x, int y, int z) {
|
||||
for (CropHarvestHandler handler : CropHarvestHandlers.getCropHarvestHandlers()) {
|
||||
if (handler.couldHarvest(world, x, y, z)) {
|
||||
boolean harvestSuccessful = handler.tryHarvest(stack, player, world, x, y, z);
|
||||
if (harvestSuccessful && !player.capabilities.isCreativeMode) {
|
||||
AbilityHelper.damageTool(stack, 1, null, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package tconstruct.plugins.ic2;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ic2.api.crops.ICropTile;
|
||||
import tconstruct.api.harvesting.CropHarvestHandler;
|
||||
|
||||
public class Ic2CropHarvestHandler implements CropHarvestHandler {
|
||||
|
||||
@Override
|
||||
public boolean couldHarvest(World world, int x, int y, int z) {
|
||||
return world.getTileEntity(x, y, z) instanceof ICropTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryHarvest(ItemStack stack, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return world.getTileEntity(x, y, z) instanceof ICropTile crop && crop.getCrop().canBeHarvested(crop)
|
||||
&& crop.harvest(true);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import mantle.pulsar.pulse.Handler;
|
||||
import mantle.pulsar.pulse.Pulse;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.api.harvesting.CropHarvestHandlers;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.crafting.LiquidCasting;
|
||||
|
||||
@@ -28,6 +29,8 @@ public class TinkerIC2 {
|
||||
public void init(FMLInitializationEvent event) {
|
||||
TConstruct.logger.info("IC2 detected. Preparing for shenanigans.");
|
||||
|
||||
CropHarvestHandlers.registerCropHarvestHandler(new Ic2CropHarvestHandler());
|
||||
|
||||
Fluid fluidUUM = FluidRegistry.getFluid(IC2_UUM_FLUIDNAME);
|
||||
if (fluidUUM == null) return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user