From b678f26b6639abd61c7c74b73b6f27626fba79da Mon Sep 17 00:00:00 2001 From: Ethryan <3237986+Ethryan@users.noreply.github.com> Date: Wed, 22 May 2024 16:09:14 +0200 Subject: [PATCH] Add Silk Touch --- .../core/block/base/BlockBaseOre.java | 82 +++++++++++-------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java index e0006833c..7d2b89d0b 100644 --- a/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java +++ b/src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -37,6 +38,7 @@ public class BlockBaseOre extends BasicBlock implements ITexturedBlock { private final Material blockMaterial; protected static boolean shouldFortune = false; + protected static boolean shouldSilkTouch = false; public BlockBaseOre(final Material material, final BlockTypes blockType) { super( @@ -140,6 +142,16 @@ public void registerBlockIcons(IIconRegister p_149651_1_) {} @Override public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z, int meta) { + if (EnchantmentHelper.getSilkTouchModifier(player)) { + shouldSilkTouch = true; + super.harvestBlock(worldIn, player, x, y, z, meta); + + if (shouldSilkTouch) { + shouldSilkTouch = false; + } + return; + } + if (!(player instanceof FakePlayer)) { shouldFortune = true; } @@ -152,45 +164,51 @@ public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z @Override public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList drops = new ArrayList<>(); - // TODO: Silk Touch? - switch (GT_Mod.gregtechproxy.oreDropSystem) { - case Item -> { - drops.add( - ItemUtils.getItemStackOfAmountFromOreDictNoBroken( - "oreRaw" + this.blockMaterial.getLocalizedName(), - 1)); - } - case FortuneItem -> { - // if shouldFortune and isNatural then get fortune drops - // if not shouldFortune or not isNatural then get normal drops - // if not shouldFortune and isNatural then get normal drops - // if shouldFortune and not isNatural then get normal drops - if (shouldFortune && fortune > 0) { - int aMinAmount = 1; - // Max applicable fortune - if (fortune > 3) fortune = 3; - long amount = (long) new Random().nextInt(fortune) + aMinAmount; - for (int i = 0; i < amount; i++) { + if (shouldSilkTouch) { + drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); + } else { + switch (GT_Mod.gregtechproxy.oreDropSystem) { + case Item -> { + drops.add( + ItemUtils.getItemStackOfAmountFromOreDictNoBroken( + "oreRaw" + this.blockMaterial.getLocalizedName(), + 1)); + } + case FortuneItem -> { + // if shouldFortune and isNatural then get fortune drops + // if not shouldFortune or not isNatural then get normal drops + // if not shouldFortune and isNatural then get normal drops + // if shouldFortune and not isNatural then get normal drops + if (shouldFortune && fortune > 0) { + int aMinAmount = 1; + // Max applicable fortune + if (fortune > 3) fortune = 3; + long amount = (long) new Random().nextInt(fortune) + aMinAmount; + for (int i = 0; i < amount; i++) { + drops.add( + ItemUtils.getItemStackOfAmountFromOreDictNoBroken( + "oreRaw" + this.blockMaterial.getLocalizedName(), + 1)); + } + } else { drops.add( ItemUtils.getItemStackOfAmountFromOreDictNoBroken( "oreRaw" + this.blockMaterial.getLocalizedName(), 1)); } - } else { + } + case UnifiedBlock -> { + // Unified ore + drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); + } + case PerDimBlock -> { + // Per Dimension ore + drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); + } + case Block -> { + // Regular ore drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); } - } - case UnifiedBlock -> { - // Unified ore - drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - } - case PerDimBlock -> { - // Per Dimension ore - drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); - } - case Block -> { - // Regular ore - drops.add(ItemUtils.simpleMetaStack(this, metadata, 1)); } } return drops;