I think.  This is basically the entire method from TiC, with added
boolean returns to support that the drill wanted them.  Probably also
Fixes #996
This commit is contained in:
Shadows_of_Fire 2018-01-29 02:17:31 -05:00
parent 9670fc7669
commit 227c227ddd
5 changed files with 425 additions and 383 deletions

View file

@ -681,7 +681,7 @@ public final class BlockCrafting{
RecipeHandler.addOreDictRecipe(new ItemStack(InitBlocks.blockGreenhouseGlass, 3), RecipeHandler.addOreDictRecipe(new ItemStack(InitBlocks.blockGreenhouseGlass, 3),
"GSG", "SDS", "GSG", "GSG", "SDS", "GSG",
'G', "blockGlass", 'G', "blockGlass",
'D', new ItemStack(InitBlocks.blockCrystalEmpowered, 1, TheCrystals.LAPIS.ordinal()), 'D', new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.LAPIS.ordinal()),
'S', "treeSapling"); 'S', "treeSapling");
recipeGlass = RecipeUtil.lastIRecipe(); recipeGlass = RecipeUtil.lastIRecipe();

View file

@ -10,7 +10,12 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
@ -18,7 +23,11 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.*; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerCustom;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -34,18 +43,19 @@ import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ItemDrill extends ItemEnergy{ public class ItemDrill extends ItemEnergy{
public static final int HARVEST_LEVEL = 4; public static final int HARVEST_LEVEL = 4;
@ -55,13 +65,6 @@ public class ItemDrill extends ItemEnergy{
super(250000, 1000, name); super(250000, 1000, name);
this.setMaxDamage(0); this.setMaxDamage(0);
this.setHasSubtypes(true); this.setHasSubtypes(true);
//For Iguana Tweaks author
//
//You know what? It's bad, when you know
//There is already getHarvestLevel(), yo
//But then Iguana comes and fucks with you
//So that you need to use setHarvestLevel() too.
this.setHarvestLevel("shovel", HARVEST_LEVEL); this.setHarvestLevel("shovel", HARVEST_LEVEL);
this.setHarvestLevel("pickaxe", HARVEST_LEVEL); this.setHarvestLevel("pickaxe", HARVEST_LEVEL);
} }
@ -221,19 +224,18 @@ public class ItemDrill extends ItemEnergy{
//Block hit //Block hit
RayTraceResult ray = WorldUtil.getNearestBlockWithDefaultReachDistance(player.world, player); RayTraceResult ray = WorldUtil.getNearestBlockWithDefaultReachDistance(player.world, player);
if(ray != null){ if(ray != null){
int side = ray.sideHit.ordinal();
//Breaks the Blocks //Breaks the Blocks
if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){ if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
toReturn = this.breakBlocks(stack, 2, player.world, side != 0 && side != 1 ? pos.up() : pos, side, player); toReturn = this.breakBlocks(stack, 2, player.world, pos, ray.sideHit, player);
} }
else{ else{
toReturn = this.breakBlocks(stack, 1, player.world, pos, side, player); toReturn = this.breakBlocks(stack, 1, player.world, pos, ray.sideHit, player);
} }
} }
else{ else{
toReturn = this.breakBlocks(stack, 0, player.world, pos, side, player); toReturn = this.breakBlocks(stack, 0, player.world, pos, ray.sideHit, player);
} }
//Removes Enchantments added above //Removes Enchantments added above
@ -385,17 +387,17 @@ public class ItemDrill extends ItemEnergy{
* @param world The World * @param world The World
* @param player The Player who breaks the Blocks * @param player The Player who breaks the Blocks
*/ */
public boolean breakBlocks(ItemStack stack, int radius, World world, BlockPos aPos, int side, EntityPlayer player){ public boolean breakBlocks(ItemStack stack, int radius, World world, BlockPos aPos, EnumFacing side, EntityPlayer player){
int xRange = radius; int xRange = radius;
int yRange = radius; int yRange = radius;
int zRange = 0; int zRange = 0;
//Corrects Blocks to hit depending on Side of original Block hit //Corrects Blocks to hit depending on Side of original Block hit
if(side == 0 || side == 1){ if(side.getAxis() == Axis.Y){
zRange = radius; zRange = radius;
yRange = 0; yRange = 0;
} }
if(side == 4 || side == 5){ if(side.getAxis() == Axis.X){
xRange = 0; xRange = 0;
zRange = radius; zRange = radius;
} }
@ -415,6 +417,14 @@ public class ItemDrill extends ItemEnergy{
return false; return false;
} }
if(radius == 2 && side.getAxis() != Axis.Y) {
aPos = aPos.up();
IBlockState theState = world.getBlockState(aPos);
if(theState.getBlockHardness(world, aPos) <= mainHardness+5.0F){
this.tryHarvestBlock(world, aPos, true, stack, player, use);
}
}
//Break Blocks around //Break Blocks around
if(radius > 0 && mainHardness >= 0.2F){ if(radius > 0 && mainHardness >= 0.2F){
for(int xPos = aPos.getX()-xRange; xPos <= aPos.getX()+xRange; xPos++){ for(int xPos = aPos.getX()-xRange; xPos <= aPos.getX()+xRange; xPos++){
@ -455,13 +465,13 @@ public class ItemDrill extends ItemEnergy{
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
float hardness = state.getBlockHardness(world, pos); float hardness = state.getBlockHardness(world, pos);
boolean canHarvest = (ForgeHooks.canHarvestBlock(block, player, world, pos) || this.canHarvestBlock(state, stack)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F); boolean canHarvest = WorldUtil.canBreakExtraBlock(stack, world, player, pos);
if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(world.getBlockState(pos))))){ if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(world.getBlockState(pos))))){
if(!player.capabilities.isCreativeMode){ if(!player.capabilities.isCreativeMode){
this.extractEnergyInternal(stack, use, false); this.extractEnergyInternal(stack, use, false);
} }
//Break the Block //Break the Block
return WorldUtil.playerHarvestBlock(stack, world, player, pos); return WorldUtil.breakExtraBlock(stack, world, player, pos);
} }
return false; return false;
} }

View file

@ -11,33 +11,54 @@
package de.ellpeck.actuallyadditions.mod.proxy; package de.ellpeck.actuallyadditions.mod.proxy;
import java.util.ArrayList;
import java.util.List;
import de.ellpeck.actuallyadditions.mod.ClientRegistryHandler; import de.ellpeck.actuallyadditions.mod.ClientRegistryHandler;
import de.ellpeck.actuallyadditions.mod.blocks.render.*; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderCompost;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderEmpowerer;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderLaserRelay;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud;
import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.entity.InitEntities;
import de.ellpeck.actuallyadditions.mod.entity.RenderWorm; import de.ellpeck.actuallyadditions.mod.entity.RenderWorm;
import de.ellpeck.actuallyadditions.mod.event.ClientEvents; import de.ellpeck.actuallyadditions.mod.event.ClientEvents;
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;
import de.ellpeck.actuallyadditions.mod.tile.*; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBatteryBox;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergyAdvanced;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergyExtreme;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayFluids;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist;
import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingBlock; import de.ellpeck.actuallyadditions.mod.util.IColorProvidingBlock;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem; import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.util.ArrayList;
import java.util.List;
public class ClientProxy implements IProxy{ public class ClientProxy implements IProxy{
private static final List<Item> COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING = new ArrayList<Item>(); private static final List<Item> COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING = new ArrayList<Item>();
@ -117,4 +138,12 @@ public class ClientProxy implements IProxy{
public EntityPlayer getCurrentPlayer(){ public EntityPlayer getCurrentPlayer(){
return Minecraft.getMinecraft().player; return Minecraft.getMinecraft().player;
} }
@Override
public void sendBreakPacket(BlockPos pos) {
NetHandlerPlayClient netHandlerPlayClient = Minecraft.getMinecraft().getConnection();
assert netHandlerPlayClient != null;
netHandlerPlayClient.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, Minecraft
.getMinecraft().objectMouseOver.sideHit));
}
} }

View file

@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -35,4 +36,6 @@ public interface IProxy{
EntityPlayer getCurrentPlayer(); EntityPlayer getCurrentPlayer();
default void sendBreakPacket(BlockPos pos) {};
} }

View file

@ -16,24 +16,22 @@ import java.util.List;
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler; import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper; import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.network.play.server.SPacketBlockChange; import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@ -48,28 +46,28 @@ import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public final class WorldUtil{ public final class WorldUtil {
public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract){ public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract) {
return doItemInteraction(extractWrapper, insertWrapper, maxExtract, null); return doItemInteraction(extractWrapper, insertWrapper, maxExtract, null);
} }
public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract, FilterSettings filter){ public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract, FilterSettings filter) {
return doItemInteraction(extractWrapper, insertWrapper, maxExtract, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, filter); return doItemInteraction(extractWrapper, insertWrapper, maxExtract, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, filter);
} }
public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract, int extractSlotStart, int extractSlotEnd, int insertSlotStart, int insertSlotEnd, FilterSettings filter){ public static boolean doItemInteraction(SlotlessableItemHandlerWrapper extractWrapper, SlotlessableItemHandlerWrapper insertWrapper, int maxExtract, int extractSlotStart, int extractSlotEnd, int insertSlotStart, int insertSlotEnd, FilterSettings filter) {
ItemStack theoreticalExtract = extractItem(extractWrapper, maxExtract, true, extractSlotStart, extractSlotEnd, filter); ItemStack theoreticalExtract = extractItem(extractWrapper, maxExtract, true, extractSlotStart, extractSlotEnd, filter);
if(StackUtil.isValid(theoreticalExtract)){ if (StackUtil.isValid(theoreticalExtract)) {
ItemStack remaining = insertItem(insertWrapper, theoreticalExtract, false, insertSlotStart, insertSlotEnd); ItemStack remaining = insertItem(insertWrapper, theoreticalExtract, false, insertSlotStart, insertSlotEnd);
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){ if (!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)) {
int toExtract = !StackUtil.isValid(remaining) ? StackUtil.getStackSize(theoreticalExtract) : StackUtil.getStackSize(theoreticalExtract)-StackUtil.getStackSize(remaining); int toExtract = !StackUtil.isValid(remaining) ? StackUtil.getStackSize(theoreticalExtract) : StackUtil.getStackSize(theoreticalExtract) - StackUtil.getStackSize(remaining);
extractItem(extractWrapper, toExtract, false, extractSlotStart, extractSlotEnd, filter); extractItem(extractWrapper, toExtract, false, extractSlotStart, extractSlotEnd, filter);
return true; return true;
} }
@ -77,25 +75,23 @@ public final class WorldUtil{
return false; return false;
} }
public static ItemStack extractItem(SlotlessableItemHandlerWrapper extractWrapper, int maxExtract, boolean simulate, int slotStart, int slotEnd, FilterSettings filter){ public static ItemStack extractItem(SlotlessableItemHandlerWrapper extractWrapper, int maxExtract, boolean simulate, int slotStart, int slotEnd, FilterSettings filter) {
ItemStack extracted = StackUtil.getEmpty(); ItemStack extracted = StackUtil.getEmpty();
if(ActuallyAdditions.commonCapsLoaded){ if (ActuallyAdditions.commonCapsLoaded) {
Object handler = extractWrapper.getSlotlessHandler(); Object handler = extractWrapper.getSlotlessHandler();
if(handler instanceof ISlotlessItemHandler){ if (handler instanceof ISlotlessItemHandler) {
ISlotlessItemHandler slotless = (ISlotlessItemHandler)handler; ISlotlessItemHandler slotless = (ISlotlessItemHandler) handler;
if(filter == null || !filter.needsCheck()){ if (filter == null || !filter.needsCheck()) {
extracted = slotless.extractItem(maxExtract, simulate); extracted = slotless.extractItem(maxExtract, simulate);
return extracted; return extracted;
} } else {
else{
ItemStack would = slotless.extractItem(maxExtract, true); ItemStack would = slotless.extractItem(maxExtract, true);
if(filter.check(would)){ if (filter.check(would)) {
if(simulate){ if (simulate) {
extracted = would; extracted = would;
} } else {
else{
extracted = slotless.extractItem(maxExtract, false); extracted = slotless.extractItem(maxExtract, false);
} }
} }
@ -104,14 +100,14 @@ public final class WorldUtil{
} }
} }
if(!StackUtil.isValid(extracted)){ if (!StackUtil.isValid(extracted)) {
IItemHandler handler = extractWrapper.getNormalHandler(); IItemHandler handler = extractWrapper.getNormalHandler();
if(handler != null){ if (handler != null) {
for(int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++){ for (int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++) {
if(filter == null || !filter.needsCheck() || filter.check(handler.getStackInSlot(i))){ if (filter == null || !filter.needsCheck() || filter.check(handler.getStackInSlot(i))) {
extracted = handler.extractItem(i, maxExtract, simulate); extracted = handler.extractItem(i, maxExtract, simulate);
if(StackUtil.isValid(extracted)){ if (StackUtil.isValid(extracted)) {
break; break;
} }
} }
@ -122,23 +118,21 @@ public final class WorldUtil{
return extracted; return extracted;
} }
public static ItemStack insertItem(SlotlessableItemHandlerWrapper insertWrapper, ItemStack stack, boolean simulate, int slotStart, int slotEnd){ public static ItemStack insertItem(SlotlessableItemHandlerWrapper insertWrapper, ItemStack stack, boolean simulate, int slotStart, int slotEnd) {
ItemStack remain = StackUtil.validateCopy(stack); ItemStack remain = StackUtil.validateCopy(stack);
if(ActuallyAdditions.commonCapsLoaded){ if (ActuallyAdditions.commonCapsLoaded) {
Object handler = insertWrapper.getSlotlessHandler(); Object handler = insertWrapper.getSlotlessHandler();
if(handler instanceof ISlotlessItemHandler){ if (handler instanceof ISlotlessItemHandler) {
remain = ((ISlotlessItemHandler)handler).insertItem(remain, simulate); remain = ((ISlotlessItemHandler) handler).insertItem(remain, simulate);
if(!ItemStack.areItemStacksEqual(remain, stack)){ if (!ItemStack.areItemStacksEqual(remain, stack)) { return remain; }
return remain;
}
} }
} }
IItemHandler handler = insertWrapper.getNormalHandler(); IItemHandler handler = insertWrapper.getNormalHandler();
if(handler != null){ if (handler != null) {
for(int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++){ for (int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++) {
remain = handler.insertItem(i, remain, simulate); remain = handler.insertItem(i, remain, simulate);
} }
} }
@ -146,16 +140,16 @@ public final class WorldUtil{
return remain; return remain;
} }
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){ public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer) {
if(maxTransfer > 0){ if (maxTransfer > 0) {
EnumFacing opp = sideTo == null ? null : sideTo.getOpposite(); EnumFacing opp = sideTo == null ? null : sideTo.getOpposite();
if(tileFrom.hasCapability(CapabilityEnergy.ENERGY, sideTo) && tileTo.hasCapability(CapabilityEnergy.ENERGY, opp)){ if (tileFrom.hasCapability(CapabilityEnergy.ENERGY, sideTo) && tileTo.hasCapability(CapabilityEnergy.ENERGY, opp)) {
IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo); IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo);
IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp); IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, opp);
if(handlerFrom != null && handlerTo != null){ if (handlerFrom != null && handlerTo != null) {
int drain = handlerFrom.extractEnergy(maxTransfer, true); int drain = handlerFrom.extractEnergy(maxTransfer, true);
if(drain > 0){ if (drain > 0) {
int filled = handlerTo.receiveEnergy(drain, false); int filled = handlerTo.receiveEnergy(drain, false);
handlerFrom.extractEnergy(filled, false); handlerFrom.extractEnergy(filled, false);
return; return;
@ -165,13 +159,13 @@ public final class WorldUtil{
} }
} }
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){ public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer) {
if(maxTransfer > 0){ if (maxTransfer > 0) {
if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){ if (tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())) {
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo); IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite()); IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
FluidStack drain = handlerFrom.drain(maxTransfer, false); FluidStack drain = handlerFrom.drain(maxTransfer, false);
if(drain != null){ if (drain != null) {
int filled = handlerTo.fill(drain.copy(), true); int filled = handlerTo.fill(drain.copy(), true);
handlerFrom.drain(filled, true); handlerFrom.drain(filled, true);
} }
@ -188,42 +182,38 @@ public final class WorldUtil{
* @param world The World * @param world The World
* @return Is every block present? * @return Is every block present?
*/ */
public static boolean hasBlocksInPlacesGiven(BlockPos[] positions, Block block, int meta, World world){ public static boolean hasBlocksInPlacesGiven(BlockPos[] positions, Block block, int meta, World world) {
for(BlockPos pos : positions){ for (BlockPos pos : positions) {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
if(!(state.getBlock() == block && block.getMetaFromState(state) == meta)){ if (!(state.getBlock() == block && block.getMetaFromState(state) == meta)) { return false; }
return false;
}
} }
return true; return true;
} }
public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){ public static ItemStack useItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack) {
if(world instanceof WorldServer && StackUtil.isValid(stack) && pos != null){ if (world instanceof WorldServer && StackUtil.isValid(stack) && pos != null) {
BlockPos offsetPos = pos.offset(side); BlockPos offsetPos = pos.offset(side);
IBlockState state = world.getBlockState(offsetPos); IBlockState state = world.getBlockState(offsetPos);
Block block = state.getBlock(); Block block = state.getBlock();
boolean replaceable = block.isReplaceable(world, offsetPos); boolean replaceable = block.isReplaceable(world, offsetPos);
//Redstone //Redstone
if(replaceable && stack.getItem() == Items.REDSTONE){ if (replaceable && stack.getItem() == Items.REDSTONE) {
world.setBlockState(offsetPos, Blocks.REDSTONE_WIRE.getDefaultState(), 2); world.setBlockState(offsetPos, Blocks.REDSTONE_WIRE.getDefaultState(), 2);
return StackUtil.addStackSize(stack, -1); return StackUtil.addStackSize(stack, -1);
} }
//Plants //Plants
if(replaceable && stack.getItem() instanceof IPlantable){ if (replaceable && stack.getItem() instanceof IPlantable) {
if(((IPlantable)stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)){ if (((IPlantable) stack.getItem()).getPlant(world, offsetPos).getBlock().canPlaceBlockAt(world, offsetPos)) {
if(world.setBlockState(offsetPos, ((IPlantable)stack.getItem()).getPlant(world, offsetPos), 2)){ if (world.setBlockState(offsetPos, ((IPlantable) stack.getItem()).getPlant(world, offsetPos), 2)) { return StackUtil.addStackSize(stack, -1); }
return StackUtil.addStackSize(stack, -1);
}
} }
} }
//Everything else //Everything else
try{ try {
if(world instanceof WorldServer){ if (world instanceof WorldServer) {
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer)world); FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) world);
ItemStack heldBefore = fake.getHeldItemMainhand(); ItemStack heldBefore = fake.getHeldItemMainhand();
setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, stack.copy()); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, stack.copy());
@ -233,18 +223,17 @@ public final class WorldUtil{
setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, heldBefore); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, heldBefore);
return result; return result;
} }
} } catch (Exception e) {
catch(Exception e){ ModUtil.LOGGER.error("Something that places Blocks at " + offsetPos.getX() + ", " + offsetPos.getY() + ", " + offsetPos.getZ() + " in World " + world.provider.getDimension() + " threw an Exception! Don't let that happen again!", e);
ModUtil.LOGGER.error("Something that places Blocks at "+offsetPos.getX()+", "+offsetPos.getY()+", "+offsetPos.getZ()+" in World "+world.provider.getDimension()+" threw an Exception! Don't let that happen again!", e);
} }
} }
return stack; return stack;
} }
public static boolean dropItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack){ public static boolean dropItemAtSide(EnumFacing side, World world, BlockPos pos, ItemStack stack) {
BlockPos coords = pos.offset(side); BlockPos coords = pos.offset(side);
if(world.isBlockLoaded(coords)){ if (world.isBlockLoaded(coords)) {
EntityItem item = new EntityItem(world, coords.getX()+0.5, coords.getY()+0.5, coords.getZ()+0.5, stack); EntityItem item = new EntityItem(world, coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, stack);
item.motionX = 0; item.motionX = 0;
item.motionY = 0; item.motionY = 0;
item.motionZ = 0; item.motionZ = 0;
@ -254,8 +243,8 @@ public final class WorldUtil{
return false; return false;
} }
public static EnumFacing getDirectionBySidesInOrder(int side){ public static EnumFacing getDirectionBySidesInOrder(int side) {
switch(side){ switch (side) {
case 0: case 0:
return EnumFacing.UP; return EnumFacing.UP;
case 1: case 1:
@ -271,11 +260,11 @@ public final class WorldUtil{
} }
} }
public static EnumFacing getDirectionByPistonRotation(int meta){ public static EnumFacing getDirectionByPistonRotation(int meta) {
return EnumFacing.values()[meta]; return EnumFacing.values()[meta];
} }
public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos){ public static ArrayList<Material> getMaterialsAround(World world, BlockPos pos) {
ArrayList<Material> blocks = new ArrayList<Material>(); ArrayList<Material> blocks = new ArrayList<Material>();
blocks.add(world.getBlockState(pos.offset(EnumFacing.NORTH)).getMaterial()); blocks.add(world.getBlockState(pos.offset(EnumFacing.NORTH)).getMaterial());
blocks.add(world.getBlockState(pos.offset(EnumFacing.EAST)).getMaterial()); blocks.add(world.getBlockState(pos.offset(EnumFacing.EAST)).getMaterial());
@ -284,41 +273,40 @@ public final class WorldUtil{
return blocks; return blocks;
} }
public static boolean addToInventory(ItemStackHandlerCustom inventory, List<ItemStack> stacks, boolean actuallyDo){ public static boolean addToInventory(ItemStackHandlerCustom inventory, List<ItemStack> stacks, boolean actuallyDo) {
return addToInventory(inventory, 0, inventory.getSlots(), stacks, actuallyDo); return addToInventory(inventory, 0, inventory.getSlots(), stacks, actuallyDo);
} }
public static boolean addToInventory(ItemStackHandlerCustom inventory, int start, int end, List<ItemStack> stacks, boolean actuallyDo){ public static boolean addToInventory(ItemStackHandlerCustom inventory, int start, int end, List<ItemStack> stacks, boolean actuallyDo) {
//Copy the slots if just testing to later load them again //Copy the slots if just testing to later load them again
ItemStack[] backupSlots = null; ItemStack[] backupSlots = null;
if(!actuallyDo){ if (!actuallyDo) {
backupSlots = new ItemStack[inventory.getSlots()]; backupSlots = new ItemStack[inventory.getSlots()];
for(int i = 0; i < backupSlots.length; i++){ for (int i = 0; i < backupSlots.length; i++) {
ItemStack stack = inventory.getStackInSlot(i); ItemStack stack = inventory.getStackInSlot(i);
backupSlots[i] = StackUtil.validateCopy(stack); backupSlots[i] = StackUtil.validateCopy(stack);
} }
} }
int working = 0; int working = 0;
for(ItemStack stack : stacks){ for (ItemStack stack : stacks) {
if(StackUtil.isValid(stack)){ if (StackUtil.isValid(stack)) {
for(int i = start; i < end; i++){ for (int i = start; i < end; i++) {
stack = inventory.insertItemInternal(i, stack, false); stack = inventory.insertItemInternal(i, stack, false);
if(!StackUtil.isValid(stack)){ if (!StackUtil.isValid(stack)) {
working++; working++;
break; break;
} }
} }
} } else {
else{
working++; working++;
} }
} }
//Load the slots again //Load the slots again
if(!actuallyDo){ if (!actuallyDo) {
for(int i = 0; i < backupSlots.length; i++){ for (int i = 0; i < backupSlots.length; i++) {
inventory.setStackInSlot(i, StackUtil.validateCheck(backupSlots[i])); inventory.setStackInSlot(i, StackUtil.validateCheck(backupSlots[i]));
} }
} }
@ -326,139 +314,151 @@ public final class WorldUtil{
return working >= stacks.size(); return working >= stacks.size();
} }
public static int findFirstFilledSlot(ItemStackHandlerCustom slots){ public static int findFirstFilledSlot(ItemStackHandlerCustom slots) {
for(int i = 0; i < slots.getSlots(); i++){ for (int i = 0; i < slots.getSlots(); i++) {
if(StackUtil.isValid(slots.getStackInSlot(i))){ if (StackUtil.isValid(slots.getStackInSlot(i))) { return i; }
return i;
}
} }
return 0; return 0;
} }
public static RayTraceResult getNearestPositionWithAir(World world, EntityPlayer player, int reach){ public static RayTraceResult getNearestPositionWithAir(World world, EntityPlayer player, int reach) {
return getMovingObjectPosWithReachDistance(world, player, reach, false, false, true); return getMovingObjectPosWithReachDistance(world, player, reach, false, false, true);
} }
private static RayTraceResult getMovingObjectPosWithReachDistance(World world, EntityPlayer player, double distance, boolean p1, boolean p2, boolean p3){ private static RayTraceResult getMovingObjectPosWithReachDistance(World world, EntityPlayer player, double distance, boolean p1, boolean p2, boolean p3) {
float f = player.rotationPitch; float f = player.rotationPitch;
float f1 = player.rotationYaw; float f1 = player.rotationYaw;
double d0 = player.posX; double d0 = player.posX;
double d1 = player.posY+(double)player.getEyeHeight(); double d1 = player.posY + (double) player.getEyeHeight();
double d2 = player.posZ; double d2 = player.posZ;
Vec3d vec3 = new Vec3d(d0, d1, d2); Vec3d vec3 = new Vec3d(d0, d1, d2);
float f2 = MathHelper.cos(-f1*0.017453292F-(float)Math.PI); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
float f3 = MathHelper.sin(-f1*0.017453292F-(float)Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
float f4 = -MathHelper.cos(-f*0.017453292F); float f4 = -MathHelper.cos(-f * 0.017453292F);
float f5 = MathHelper.sin(-f*0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F);
float f6 = f3*f4; float f6 = f3 * f4;
float f7 = f2*f4; float f7 = f2 * f4;
Vec3d vec31 = vec3.addVector((double)f6*distance, (double)f5*distance, (double)f7*distance); Vec3d vec31 = vec3.addVector((double) f6 * distance, (double) f5 * distance, (double) f7 * distance);
return world.rayTraceBlocks(vec3, vec31, p1, p2, p3); return world.rayTraceBlocks(vec3, vec31, p1, p2, p3);
} }
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player){ public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player) {
return getNearestBlockWithDefaultReachDistance(world, player, false, true, false); return getNearestBlockWithDefaultReachDistance(world, player, false, true, false);
} }
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock){ public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock); return getMovingObjectPosWithReachDistance(world, player, player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(), stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
} }
//Cobbled together from Tinkers' Construct (with permission, thanks!) and PlayerInteractionManager code. public static void setHandItemWithoutAnnoyingSound(EntityPlayer player, EnumHand hand, ItemStack stack) {
//Breaking blocks is a hideous pain so yea. if (hand == EnumHand.MAIN_HAND) {
//This doesn't do any additional harvestability checks that the blocks itself don't do! player.inventory.mainInventory.set(player.inventory.currentItem, stack);
public static boolean playerHarvestBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos){ } else if (hand == EnumHand.OFF_HAND) {
if(world.isAirBlock(pos)){ player.inventory.offHandInventory.set(0, stack);
}
}
public static float fireFakeHarvestEventsForDropChance(NonNullList<ItemStack> drops, World world, BlockPos pos) {
if (world instanceof WorldServer) {
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer) world);
IBlockState state = world.getBlockState(pos);
BreakEvent event = new BreakEvent(world, pos, state, fake);
if (!MinecraftForge.EVENT_BUS.post(event)) { return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); }
}
return 0F;
}
//Stolen from TiC
/**
* Returns true if the tool is effective for harvesting the given block.
*/
public static boolean isToolEffective(ItemStack stack, IBlockState state) {
// check material
for (String type : stack.getItem().getToolClasses(stack)) {
if (state.getBlock().isToolEffective(type, state)) { return true; }
}
return false; return false;
} }
public static boolean canBreakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos) {
// prevent calling that stuff for air blocks, could lead to unexpected behaviour since it fires events
if (world.isAirBlock(pos)) { return false; }
// check if the block can be broken, since extra block breaks shouldn't instantly break stuff like obsidian
// or precious ores you can't harvest while mining stone
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if(!world.isRemote){ // only effective materials
world.playEvent(player, 2001, pos, Block.getStateId(state)); if (!isToolEffective(stack, state)) { return false; }
}
else{
world.playEvent(2001, pos, Block.getStateId(state));
}
if(player.capabilities.isCreativeMode){ // only harvestable blocks that aren't impossibly slow to harvest
if (!ForgeHooks.canHarvestBlock(block, player, world, pos)) { return false; }
block.onBlockHarvested(world, pos, state, player); // From this point on it's clear that the player CAN break the block
if(block.removedByPlayer(state, world, pos, player, false)){
block.onBlockDestroyedByPlayer(world, pos, state);
}
if(!world.isRemote){
if(player instanceof EntityPlayerMP){
((EntityPlayerMP)player).connection.sendPacket(new SPacketBlockChange(world, pos));
}
}
return true; return true;
} }
stack.onBlockDestroyed(world, state, pos, player); public static boolean breakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(!world.isRemote){ if (player.capabilities.isCreativeMode) {
if(player instanceof EntityPlayerMP){ block.onBlockHarvested(world, pos, state, player);
EntityPlayerMP playerMp = (EntityPlayerMP)player; if (block.removedByPlayer(state, world, pos, player, false)) {
block.onBlockDestroyedByPlayer(world, pos, state);
int xp = ForgeHooks.onBlockBreakEvent(world, playerMp.interactionManager.getGameType(), playerMp, pos);
if(xp == -1){
return false;
} }
// send update to client
if (!world.isRemote) {
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
}
return true;
}
// callback to the tool the player uses. Called on both sides. This damages the tool n stuff.
stack.onBlockDestroyed(world, state, pos, player);
// server sided handling
if (!world.isRemote) {
// send the blockbreak event
int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
if (xp == -1) { return false; }
// serverside we reproduce ItemInWorldManager.tryHarvestBlock
TileEntity tileEntity = world.getTileEntity(pos); TileEntity tileEntity = world.getTileEntity(pos);
if(block.removedByPlayer(state, world, pos, player, true)){ // ItemInWorldManager.removeBlock
if (block.removedByPlayer(state, world, pos, player, true)) { // boolean is if block can be harvested, checked above
block.onBlockDestroyedByPlayer(world, pos, state); block.onBlockDestroyedByPlayer(world, pos, state);
block.harvestBlock(world, player, pos, state, tileEntity, stack); block.harvestBlock(world, player, pos, state, tileEntity, stack);
block.dropXpOnBlockBreak(world, pos, xp); block.dropXpOnBlockBreak(world, pos, xp);
} }
playerMp.connection.sendPacket(new SPacketBlockChange(world, pos)); // always send block update to client
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
return true; return true;
} }
} // client sided handling
else{ else {
if(block.removedByPlayer(state, world, pos, player, true)){ // clientside we do a "this block has been clicked on long enough to be broken" call. This should not send any new packets
// the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy.
// following code can be found in PlayerControllerMP.onPlayerDestroyBlock
world.playEvent(2001, pos, Block.getStateId(state));
if (block.removedByPlayer(state, world, pos, player, true)) {
block.onBlockDestroyedByPlayer(world, pos, state); block.onBlockDestroyedByPlayer(world, pos, state);
} }
// callback to the tool
stack.onBlockDestroyed(world, state, pos, player);
if(StackUtil.getStackSize(stack) <= 0 && stack == player.getHeldItemMainhand()){ // send an update to the server, so we get an update back
ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND); ActuallyAdditions.proxy.sendBreakPacket(pos);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
if(ConfigBoolValues.ENABLE_DRILL_DIGGING_PACKET.isEnabled()){
Minecraft mc = Minecraft.getMinecraft();
mc.getConnection().sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit));
}
return true; return true;
} }
return false;
}
public static float fireFakeHarvestEventsForDropChance(List<ItemStack> drops, World world, BlockPos pos){
if(!world.isRemote && world instanceof WorldServer){
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer)world);
IBlockState state = world.getBlockState(pos);
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, fake);
if(!MinecraftForge.EVENT_BUS.post(event)){
return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake);
}
}
return 0F;
}
public static void setHandItemWithoutAnnoyingSound(EntityPlayer player, EnumHand hand, ItemStack stack){
if(hand == EnumHand.MAIN_HAND){
player.inventory.mainInventory.set(player.inventory.currentItem, stack);
}
else if(hand == EnumHand.OFF_HAND){
player.inventory.offHandInventory.set(0, stack);
}
} }
} }