mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
'Fix' the vitreous pickaxe
This commit is contained in:
1 parent
073730dbcd
commit
c09915fc20
1 file changed
+41
-12
@@ -10,18 +10,26 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.tool;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.IItemTier;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import vazkii.botania.common.item.equipment.tool.manasteel.ItemManasteelPick;
|
||||
|
||||
public class ItemGlassPick extends ItemManasteelPick {
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemGlassPick extends ItemManasteelPick {
|
||||
private static final String TAG_SILK_HACK = "botania:silk_hack";
|
||||
private static final int MANA_PER_DAMAGE = 160;
|
||||
private static final IItemTier MATERIAL = new IItemTier() {
|
||||
@Override
|
||||
@@ -57,16 +65,37 @@ public class ItemGlassPick extends ItemManasteelPick {
|
||||
|
||||
public ItemGlassPick(Properties props) {
|
||||
super(MATERIAL, props, -1);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onBlockDrops);
|
||||
}
|
||||
|
||||
private void onBlockDrops(HarvestDropsEvent event) {
|
||||
// todo 1.14 need to change to fake a silk touch tool in the loot context
|
||||
if(event.getHarvester() != null && event.getState() != null && event.getDrops() != null && event.getDrops().isEmpty()
|
||||
&& !event.getHarvester().getHeldItemMainhand().isEmpty()
|
||||
&& event.getHarvester().getHeldItemMainhand().getItem() == this
|
||||
&& event.getState().getMaterial() == Material.GLASS)
|
||||
event.getDrops().add(new ItemStack(event.getState().getBlock()));
|
||||
/*
|
||||
* No way to modify the loot context so we're gonna go braindead hack workaround here:
|
||||
* - When block starting to break, if the tool doesn't have silktouch already, add it and add a "temp silk touch" flag
|
||||
* - Every tick, if the "temp silk touch" flag is present, remove it and remove any silk touch enchants from the stack
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, PlayerEntity player) {
|
||||
BlockState state = player.world.getBlockState(pos);
|
||||
boolean isGlass = state.getMaterial() == Material.GLASS || Tags.Blocks.GLASS.contains(state.getBlock());
|
||||
boolean hasSilk = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0;
|
||||
if (hasSilk || !isGlass)
|
||||
return super.onBlockStartBreak(itemstack, pos, player);
|
||||
|
||||
itemstack.addEnchantment(Enchantments.SILK_TOUCH, 1);
|
||||
itemstack.getTag().putBoolean(TAG_SILK_HACK, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World world, Entity player, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, player, slot, selected);
|
||||
if (stack.getOrCreateTag().getBoolean(TAG_SILK_HACK)) {
|
||||
stack.getTag().remove(TAG_SILK_HACK);
|
||||
Map<Enchantment, Integer> ench = EnchantmentHelper.getEnchantments(stack);
|
||||
ench.remove(Enchantments.SILK_TOUCH);
|
||||
EnchantmentHelper.setEnchantments(ench, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user