Merge remote-tracking branch 'DrParadox7/GTPR' into dev

This commit is contained in:
Martin Robertz committed 2026-01-24 19:57:05 +01:00
commit 0fbca804cc
4 files changed
+123 -8

No files matched your search

+3
View File
@@ -4,6 +4,9 @@ dependencies {
implementation('com.github.GTNewHorizons:GTNHLib:0.9.0:dev')
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.50-GTNH:dev")
compileOnly("curse.maven:cofh-core-69162:2388750-dev:dev")
compileOnly("curse.maven:redstone-arsenal-70631:2277490-dev:dev")
compileOnly("curse.maven:magia-naturalis-1365176:7156285-dev")
compileOnly('com.github.GTNewHorizons:ForgeMultipart:1.6.4:dev') {transitive=false}
compileOnly("com.github.GTNewHorizons:Chisel:2.16.5-GTNH:dev") { transitive = false }
// for testing
@@ -49,9 +49,13 @@ public class ConfigHandler extends AbstractConfigHandler implements ITweakConfig
public static boolean betterAchievements = true;
@Config
@Comment("Disabling this option will prevent any crops added to the config json from being right clickable.")
@Comment("Disabling this option will prevent any crops added to the config json from being right clickable with an empty hand.")
public static boolean allowCropRC = true;
@Config
@Comment("Enabling this option will allow Sickle tools to AoE right click harvest any crops added to the config json.")
public static boolean allowSickleRC = false;
@Config
@Comment("Prevent tick speedup (i.e. torcherino) on any TE that uses the base TE class from EnderCore")
public static boolean allowExternalTickSpeedup = false;
@@ -3,7 +3,10 @@ package com.enderio.core.common.handlers;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
@@ -12,6 +15,7 @@ import net.minecraftforge.oredict.OreDictionary;
import com.enderio.core.common.Handlers.Handler;
import com.enderio.core.common.config.ConfigHandler;
import com.enderio.core.common.util.ItemUtil;
import com.enderio.core.common.util.ToolUtil;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -63,18 +67,40 @@ public class RightClickCropHandler {
int x = event.x, y = event.y, z = event.z;
Block block = event.world.getBlock(x, y, z);
int meta = event.world.getBlockMetadata(x, y, z);
if (ConfigHandler.allowCropRC && event.action == Action.RIGHT_CLICK_BLOCK
&& (event.entityPlayer.getHeldItem() == null || !event.entityPlayer.isSneaking())) {
ItemStack stack = event.entityPlayer.getHeldItem();
int range = ToolUtil.getRange(stack);
boolean handHarvest = ConfigHandler.allowCropRC && (stack == null && !event.entityPlayer.isSneaking());
boolean sickleHarvest = ConfigHandler.allowSickleRC && range > 0;
if ((handHarvest || sickleHarvest) && event.action == Action.RIGHT_CLICK_BLOCK
&& !(event.entityPlayer instanceof FakePlayer)) {
for (PlantInfo info : plants) {
if (info.blockInst == block && meta == info.meta) {
if (event.world.isRemote) {
event.entityPlayer.swingItem();
} else {
currentPlant = info;
block.dropBlockAsItem(event.world, x, y, z, meta, 0);
currentPlant = null;
event.world.setBlockMetadataWithNotify(x, y, z, info.resetMeta, 3);
event.setCanceled(true);
int fortune = 0;
int cropsHarvested = 0;
if (sickleHarvest) {
fortune = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
}
for (int i = x - range; i <= x + range; i++) {
for (int k = z - range; k <= z + range; k++)
if (info.blockInst == event.world.getBlock(i, y, k)
&& event.world.getBlockMetadata(i, y, k) == info.meta) {
currentPlant = info;
block.dropBlockAsItem(event.world, i, y, k, meta, fortune);
cropsHarvested++;
currentPlant = null;
event.world.setBlockMetadataWithNotify(i, y, k, info.resetMeta, 3);
event.setCanceled(true);
}
}
ToolUtil.damageDurability(stack, cropsHarvested, event.entityPlayer);
}
break;
}
@@ -96,4 +122,5 @@ public class RightClickCropHandler {
}
}
}
}
@@ -0,0 +1,81 @@
package com.enderio.core.common.util;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import com.github.elenterius.magianaturalis.item.artifact.SickleItem;
import cofh.core.item.tool.ItemSickleAdv;
import cofh.lib.util.helpers.MathHelper;
import cofh.redstonearsenal.item.tool.ItemSickleRF;
import cpw.mods.fml.common.Loader;
public class ToolUtil {
public static final boolean isMagiaNaturalisLoaded = Loader.isModLoaded("magianaturalis");
public static final boolean isRedstoneArsenalLoaded = Loader.isModLoaded("RedstoneArsenal");
public static final boolean isCoFHCoreLoaded = Loader.isModLoaded("CoFHCore");
public static int getRange(ItemStack tool) {
if (tool != null) {
Item item = tool.getItem();
int defaultValue = 3;
if (isMagiaNaturalisLoaded && item instanceof SickleItem) return defaultValue;
if (isRedstoneArsenalLoaded && item instanceof ItemSickleRF) {
if (!ToolUtil.canDoEnergyOperations(tool)) return 1;
else if (((ItemSickleRF) item).isEmpowered(tool)) return 5;
}
if (isCoFHCoreLoaded && item instanceof ItemSickleAdv) return ((ItemSickleAdv) item).radius;
}
return 0;
}
public static void damageDurability(ItemStack tool, int cropsHarvested, EntityPlayer player) {
if (ToolUtil.usesEnergy(tool, cropsHarvested)) return;
if (tool.getItem() instanceof ItemTool) tool.damageItem(cropsHarvested, player);
}
public static boolean canDoEnergyOperations(ItemStack stack) {
if (ToolUtil.isRedstoneArsenalLoaded && stack.getItem() instanceof ItemSickleRF) {
ItemSickleRF sickle = (ItemSickleRF) stack.getItem();
boolean isEmpowered = sickle.isEmpowered(stack);
int unbreakingLevel = MathHelper
.clamp((EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)), 0, 4);
int costRF = sickle.energyPerUse * (5 - unbreakingLevel) / 5;
if (sickle.getEnergyStored(stack) >= costRF) {
sickle.extractEnergy(
stack,
isEmpowered ? sickle.energyPerUseCharged * (5 - unbreakingLevel) / 5
: sickle.energyPerUse * (5 - unbreakingLevel) / 5,
false);
return true;
}
}
return false;
}
public static boolean usesEnergy(ItemStack tool, int cropsHarvested) {
if (ToolUtil.isRedstoneArsenalLoaded && tool.getItem() instanceof ItemSickleRF) {
ItemSickleRF RFTool = (ItemSickleRF) tool.getItem();
int unbreakingLvl = MathHelper
.clamp(EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, tool), 0, 4);
int RFCost = RFTool.isEmpowered(tool) ? RFTool.energyPerUseCharged * (5 - unbreakingLvl) / 5
: RFTool.energyPerUse * (5 - unbreakingLvl) / 5;
RFTool.extractEnergy(tool, RFCost, false);
return true;
}
return false;
}
}