Optimized and updated Bound Tools (#1500)
Signed-off-by: tobias <angryaeon@icloud.com>
This commit is contained in:
parent
297771af81
commit
4f04fde127
|
@ -3,7 +3,6 @@ package WayofTime.bloodmagic.item;
|
|||
import WayofTime.bloodmagic.client.IMeshProvider;
|
||||
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
|
||||
import WayofTime.bloodmagic.core.data.SoulTicket;
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
|
@ -68,26 +67,25 @@ public class ItemBoundAxe extends ItemBoundTool implements IMeshProvider {
|
|||
for (int j = 0; j <= 2 * range; j++) {
|
||||
for (int k = -range; k <= range; k++) {
|
||||
BlockPos blockPos = playerPos.add(i, j, k);
|
||||
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
|
||||
IBlockState blockState = world.getBlockState(blockPos);
|
||||
|
||||
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
|
||||
if (world.isAirBlock(blockPos))
|
||||
continue;
|
||||
|
||||
if (blockStack.getState().getMaterial() != Material.WOOD && !EFFECTIVE_ON.contains(blockStack.getBlock()))
|
||||
if (blockState.getMaterial() != Material.WOOD && !EFFECTIVE_ON.contains(blockState.getBlock()))
|
||||
continue;
|
||||
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockState, player);
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
continue;
|
||||
|
||||
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
|
||||
sharedHarvest(stack, world, player, blockPos, blockState, silkTouch, fortuneLvl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, (int) (charge * charge * charge / 2.7)));
|
||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
|
||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,9 @@ package WayofTime.bloodmagic.item;
|
|||
import WayofTime.bloodmagic.client.IMeshProvider;
|
||||
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
|
||||
import WayofTime.bloodmagic.core.data.SoulTicket;
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -73,34 +72,31 @@ public class ItemBoundPickaxe extends ItemBoundTool implements IMeshProvider {
|
|||
|
||||
int range = (charge / 6); //Charge is a max of 30 - want 5 to be the max
|
||||
|
||||
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
|
||||
|
||||
BlockPos playerPos = player.getPosition();
|
||||
|
||||
for (int i = -range; i <= range; i++) {
|
||||
for (int j = 0; j <= 2 * range; j++) {
|
||||
for (int k = -range; k <= range; k++) {
|
||||
BlockPos blockPos = playerPos.add(i, j, k);
|
||||
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
|
||||
IBlockState blockState = world.getBlockState(blockPos);
|
||||
|
||||
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
|
||||
if (world.isAirBlock(blockPos))
|
||||
continue;
|
||||
|
||||
if (blockStack.getState().getMaterial() != Material.ROCK && !EFFECTIVE_ON.contains(blockStack.getBlock()))
|
||||
if (blockState.getMaterial() != Material.ROCK && !EFFECTIVE_ON.contains(blockState.getBlock()))
|
||||
continue;
|
||||
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockState, player);
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
continue;
|
||||
|
||||
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
|
||||
sharedHarvest(stack, world, player, blockPos, blockState, silkTouch, fortuneLvl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, (int) (charge * charge * charge / 2.7)));
|
||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,11 @@ package WayofTime.bloodmagic.item;
|
|||
import WayofTime.bloodmagic.client.IMeshProvider;
|
||||
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
|
||||
import WayofTime.bloodmagic.core.data.SoulTicket;
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -66,27 +67,26 @@ public class ItemBoundShovel extends ItemBoundTool implements IMeshProvider {
|
|||
for (int j = 0; j <= 2 * range; j++) {
|
||||
for (int k = -range; k <= range; k++) {
|
||||
BlockPos blockPos = playerPos.add(i, j, k);
|
||||
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
|
||||
IBlockState blockState = world.getBlockState(blockPos);
|
||||
|
||||
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
|
||||
if (world.isAirBlock(blockPos))
|
||||
continue;
|
||||
|
||||
Material material = blockStack.getState().getMaterial();
|
||||
if (material != Material.GROUND && material != Material.CLAY && material != Material.GRASS && !EFFECTIVE_ON.contains(blockStack.getBlock()))
|
||||
Material material = blockState.getMaterial();
|
||||
if (material != Material.GROUND && material != Material.CLAY && material != Material.GRASS && !EFFECTIVE_ON.contains(blockState.getBlock()))
|
||||
continue;
|
||||
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockState, player);
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
continue;
|
||||
|
||||
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
|
||||
sharedHarvest(stack, world, player, blockPos, blockState, silkTouch, fortuneLvl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, SoulTicket.item(stack, world, player, (int) (charge * charge * charge / 2.7)));
|
||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,16 +4,15 @@ import WayofTime.bloodmagic.BloodMagic;
|
|||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import WayofTime.bloodmagic.core.data.Binding;
|
||||
import WayofTime.bloodmagic.core.data.SoulTicket;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.event.BoundToolEvent;
|
||||
import WayofTime.bloodmagic.iface.IActivatable;
|
||||
import WayofTime.bloodmagic.iface.IBindable;
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import WayofTime.bloodmagic.util.helper.NetworkHelper;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
|
@ -21,10 +20,10 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
@ -36,6 +35,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -235,36 +235,21 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
|
|||
return chargeTime;
|
||||
}
|
||||
|
||||
protected static void dropStacks(Multiset<ItemStackWrapper> drops, World world, BlockPos posToDrop) {
|
||||
for (Multiset.Entry<ItemStackWrapper> entry : drops.entrySet()) {
|
||||
int count = entry.getCount();
|
||||
ItemStackWrapper stack = entry.getElement();
|
||||
int maxStackSize = stack.item.getItemStackLimit(stack.toStack(1));
|
||||
protected void sharedHarvest(ItemStack stack, World world, EntityPlayer player, BlockPos blockPos, IBlockState blockState, boolean silkTouch, int fortuneLvl) {
|
||||
|
||||
while (count >= maxStackSize) {
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(maxStackSize)));
|
||||
count -= maxStackSize;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
|
||||
}
|
||||
}
|
||||
|
||||
protected void sharedHarvest(ItemStack stack, World world, EntityPlayer player, BlockPos blockPos, BlockStack blockStack, HashMultiset drops, boolean silkTouch, int fortuneLvl){
|
||||
|
||||
if (blockStack.getBlock() != null && blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
|
||||
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
|
||||
if (blockState.getBlockHardness(world, blockPos) != -1.0F) {
|
||||
float strengthVsBlock = getDestroySpeed(stack, blockState);
|
||||
|
||||
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
|
||||
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
|
||||
drops.add(new ItemStackWrapper(blockStack));
|
||||
if (silkTouch && blockState.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
|
||||
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Item.getItemFromBlock(blockState.getBlock())));
|
||||
else {
|
||||
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
|
||||
NonNullList<ItemStack> itemDrops = new NonNullList<>();
|
||||
blockState.getBlock().getDrops(itemDrops, world, blockPos, world.getBlockState(blockPos), fortuneLvl);
|
||||
for (ItemStack stacks : itemDrops)
|
||||
drops.add(ItemStackWrapper.getHolder(stacks));
|
||||
ItemHandlerHelper.giveItemToPlayer(player, stacks);
|
||||
}
|
||||
blockStack.getBlock().removedByPlayer(world.getBlockState(blockPos), world, blockPos,player, false);
|
||||
blockState.getBlock().removedByPlayer(world.getBlockState(blockPos), world, blockPos, player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue