Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Add Silk Touch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethryan committed May 22, 2024
1 parent c96e5b1 commit b678f26
Showing 1 changed file with 50 additions and 32 deletions.
82 changes: 50 additions & 32 deletions src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand All @@ -152,45 +164,51 @@ public void harvestBlock(World worldIn, EntityPlayer player, int x, int y, int z
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> 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;
Expand Down

0 comments on commit b678f26

Please sign in to comment.