mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-10-26 14:24:32 +00:00
Sickle AoE Right Click to Harvest (#29)
Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Co-authored-by: Aleksandr Iakovlev <Aguinore@users.noreply.github.com>
This commit is contained in:
4 files changed
+116
-8
No files matched your search
@@ -4,6 +4,9 @@ dependencies {
|
||||
implementation('com.github.GTNewHorizons:GTNHLib:0.9.6:dev')
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.55-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.7.2:dev') {transitive=false}
|
||||
compileOnly("com.github.GTNewHorizons:Chisel:2.17.13-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;
|
||||
|
||||
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);
|
||||
currentPlant = null;
|
||||
event.world.setBlockMetadataWithNotify(i, y, k, info.resetMeta, 3);
|
||||
event.setCanceled(true);
|
||||
|
||||
if (!ToolUtil.damageDurability(stack, event.entityPlayer)) return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -96,4 +122,5 @@ public class RightClickCropHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
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, true)) return 1;
|
||||
else if (((ItemSickleRF) item).isEmpowered(tool)) return 5;
|
||||
}
|
||||
|
||||
if (isCoFHCoreLoaded && item instanceof ItemSickleAdv) return ((ItemSickleAdv) item).radius;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean damageDurability(ItemStack stack, EntityPlayer player) {
|
||||
if (stack != null) {
|
||||
Item tool = stack.getItem();
|
||||
if (ToolUtil.isRedstoneArsenalLoaded && tool instanceof ItemSickleRF)
|
||||
return ToolUtil.canDoEnergyOperations(stack, false);
|
||||
|
||||
if (tool instanceof ItemTool && tool.isDamageable()) {
|
||||
stack.damageItem(1, player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canDoEnergyOperations(ItemStack stack, boolean simulate) {
|
||||
ItemSickleRF sickle = (ItemSickleRF) stack.getItem();
|
||||
|
||||
if (sickle != null) {
|
||||
boolean isEmpowered = sickle.isEmpowered(stack);
|
||||
|
||||
int unbreakingLevel = MathHelper
|
||||
.clamp((EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)), 0, 4);
|
||||
|
||||
int costRF = (isEmpowered ? sickle.energyPerUseCharged : sickle.energyPerUse) * (5 - unbreakingLevel) / 5;
|
||||
|
||||
if (sickle.getEnergyStored(stack) >= costRF) {
|
||||
if (!simulate) sickle.extractEnergy(stack, costRF, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user