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,7 +46,7 @@ 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;
@ -88,14 +86,12 @@ public final class WorldUtil{
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);
} }
} }
@ -130,9 +126,7 @@ public final class WorldUtil{
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;
}
} }
} }
@ -191,9 +185,7 @@ public final class WorldUtil{
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;
} }
@ -214,9 +206,7 @@ public final class WorldUtil{
//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);
}
} }
} }
@ -233,8 +223,7 @@ 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);
} }
} }
@ -310,8 +299,7 @@ public final class WorldUtil{
break; break;
} }
} }
} } else {
else{
working++; working++;
} }
} }
@ -328,9 +316,7 @@ public final class WorldUtil{
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;
} }
@ -364,101 +350,115 @@ public final class WorldUtil{
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{ // only harvestable blocks that aren't impossibly slow to harvest
world.playEvent(2001, pos, Block.getStateId(state)); if (!ForgeHooks.canHarvestBlock(block, player, world, pos)) { return false; }
// From this point on it's clear that the player CAN break the block
return true;
} }
public static boolean breakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (player.capabilities.isCreativeMode) { if (player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, pos, state, player); block.onBlockHarvested(world, pos, state, player);
if (block.removedByPlayer(state, world, pos, player, false)) { if (block.removedByPlayer(state, world, pos, player, false)) {
block.onBlockDestroyedByPlayer(world, pos, state); block.onBlockDestroyedByPlayer(world, pos, state);
} }
// send update to client
if (!world.isRemote) { if (!world.isRemote) {
if(player instanceof EntityPlayerMP){
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos)); ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
} }
}
return true; 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); stack.onBlockDestroyed(world, state, pos, player);
// server sided handling
if (!world.isRemote) { if (!world.isRemote) {
if(player instanceof EntityPlayerMP){ // send the blockbreak event
EntityPlayerMP playerMp = (EntityPlayerMP)player; int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
if (xp == -1) { return false; }
int xp = ForgeHooks.onBlockBreakEvent(world, playerMp.interactionManager.getGameType(), playerMp, pos); // serverside we reproduce ItemInWorldManager.tryHarvestBlock
if(xp == -1){
return false;
}
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 {
// 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)) { 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);
}
} }
} }