Fixed silk touch crash.
This commit is contained in:
parent
5d05ee5117
commit
f08ff511c8
|
@ -3,11 +3,17 @@ package com.legacy.aether.items.util;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.stats.StatList;
|
import net.minecraft.stats.StatList;
|
||||||
|
|
||||||
import com.legacy.aether.items.tools.ItemSkyrootTool;
|
import com.legacy.aether.items.tools.ItemSkyrootTool;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.event.ForgeEventFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class DoubleDropHelper {
|
public class DoubleDropHelper {
|
||||||
|
|
||||||
|
@ -24,7 +30,16 @@ public class DoubleDropHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.canSilkHarvest(player.worldObj, player, x, y, z, meta) && EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0) {
|
if (block.canSilkHarvest(player.worldObj, player, x, y, z, meta) && EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0) {
|
||||||
block.harvestBlock(player.worldObj, player, x, y, z, meta);
|
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
ItemStack itemstack = createStackedBlock(meta, block);
|
||||||
|
|
||||||
|
items.add(itemstack);
|
||||||
|
|
||||||
|
ForgeEventFactory.fireBlockHarvesting(items, player.worldObj, block, x, y, z, meta, 0, 1.0f, true, player);
|
||||||
|
for (ItemStack is : items)
|
||||||
|
{
|
||||||
|
dropBlockAsItem(player.worldObj, x, y, z, is);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -46,4 +61,30 @@ public class DoubleDropHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static ItemStack createStackedBlock(int p_149644_1_, Block block)
|
||||||
|
{
|
||||||
|
int j = 0;
|
||||||
|
Item item = Item.getItemFromBlock(block);
|
||||||
|
|
||||||
|
if (item != null && item.getHasSubtypes())
|
||||||
|
{
|
||||||
|
j = p_149644_1_;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemStack(item, 1, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void dropBlockAsItem(World p_149642_1_, int p_149642_2_, int p_149642_3_, int p_149642_4_, ItemStack p_149642_5_)
|
||||||
|
{
|
||||||
|
if (!p_149642_1_.isRemote && p_149642_1_.getGameRules().getGameRuleBooleanValue("doTileDrops") && !p_149642_1_.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
|
||||||
|
{
|
||||||
|
float f = 0.7F;
|
||||||
|
double d0 = (double)(p_149642_1_.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||||
|
double d1 = (double)(p_149642_1_.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||||
|
double d2 = (double)(p_149642_1_.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||||
|
EntityItem entityitem = new EntityItem(p_149642_1_, (double)p_149642_2_ + d0, (double)p_149642_3_ + d1, (double)p_149642_4_ + d2, p_149642_5_);
|
||||||
|
entityitem.delayBeforeCanPickup = 10;
|
||||||
|
p_149642_1_.spawnEntityInWorld(entityitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue