Bunch all mined blocks in one spot

Solves the problem of veinmined stuff being stuck in enclosed pockets, even with a magnet active
This commit is contained in:
abel1502 2025-06-26 22:28:03 +03:00
parent 71c1eaf430
commit 5a0dabc5a9
No known key found for this signature in database
GPG Key ID: 076926596A536338
3 changed files with 40 additions and 8 deletions

View File

@ -175,7 +175,7 @@ public interface IToolHarvestAbility extends IBaseAbility {
if(doesSmelt) {
for(ItemStack stack : drops) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
world.spawnEntityInWorld(new EntityItem(world, ItemToolAbility.dropX + 0.5, ItemToolAbility.dropY + 0.5, ItemToolAbility.dropZ + 0.5, stack.copy()));
}
}
}
@ -211,7 +211,7 @@ public interface IToolHarvestAbility extends IBaseAbility {
harvestBlock(doesShred, world, x, y, z, player);
if(doesShred) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.copy()));
world.spawnEntityInWorld(new EntityItem(world, ItemToolAbility.dropX + 0.5, ItemToolAbility.dropY + 0.5, ItemToolAbility.dropZ + 0.5, result.copy()));
}
}
};
@ -248,7 +248,7 @@ public interface IToolHarvestAbility extends IBaseAbility {
if(doesCentrifuge) {
for(ItemStack st : result) {
if(st != null) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy()));
world.spawnEntityInWorld(new EntityItem(world, ItemToolAbility.dropX + 0.5, ItemToolAbility.dropY + 0.5, ItemToolAbility.dropZ + 0.5, st.copy()));
}
}
}
@ -285,7 +285,7 @@ public interface IToolHarvestAbility extends IBaseAbility {
harvestBlock(doesCrystallize, world, x, y, z, player);
if(doesCrystallize) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
world.spawnEntityInWorld(new EntityItem(world, ItemToolAbility.dropX + 0.5, ItemToolAbility.dropY + 0.5, ItemToolAbility.dropZ + 0.5, result.output.copy()));
}
}
};
@ -324,7 +324,7 @@ public interface IToolHarvestAbility extends IBaseAbility {
harvestBlock(doesConvert, world, x, y, z, player);
if(doesConvert) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
world.spawnEntityInWorld(new EntityItem(world, ItemToolAbility.dropX + 0.5, ItemToolAbility.dropY + 0.5, ItemToolAbility.dropZ + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
}
}
};

View File

@ -1,5 +1,7 @@
package com.hbm.items.tool;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
@ -27,6 +29,8 @@ import com.hbm.packet.toclient.PlayerInformPacket;
import com.hbm.tileentity.IGUIProvider;
import api.hbm.item.IDepthRockTool;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
@ -151,6 +155,10 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
return true;
}
// Should be safe, considering the AoE ability does a similar trick already.
// If not, wrap this in a ThreadLocal or something...
public static int dropX, dropY, dropZ;
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
@ -173,6 +181,10 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
Configuration config = getConfiguration(stack);
ToolPreset preset = config.getActivePreset();
dropX = x;
dropY = y;
dropZ = z;
preset.harvestAbility.preHarvestAll(preset.harvestAbilityLevel, world, player);
boolean skipRef = preset.areaAbility.onDig(preset.areaAbilityLevel, world, x, y, z, player, this);
@ -316,7 +328,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, stack);
EntityItem entityitem = new EntityItem(player.worldObj, (double) dropX + d, (double) dropY + d1, (double) dropZ + d2, stack);
entityitem.delayBeforeCanPickup = 10;
player.worldObj.spawnEntityInWorld(entityitem);
}
@ -326,6 +338,9 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
}
}
// Since it's added by forge, access transformers don't affect it (even wildcards), so we do it the old-fashioned way
private static Method blockCaptureDrops = ReflectionHelper.findMethod(Block.class, null, new String[] { "captureDrops" }, new Class[] { boolean.class });
public static void standardDigPost(World world, int x, int y, int z, EntityPlayerMP player) {
Block block = world.getBlock(x, y, z);
@ -351,7 +366,20 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
}
if(removedByPlayer && canHarvest) {
block.harvestBlock(world, player, x, y, z, l);
try {
blockCaptureDrops.invoke(block, true);
block.harvestBlock(world, player, x, y, z, l);
List<ItemStack> drops = (List)blockCaptureDrops.invoke(block, false);
for (ItemStack stack : drops) {
block.dropBlockAsItem(world, dropX, dropY, dropZ, stack);
}
} catch (IllegalAccessException e) {
// Shouldn't be possible with ReflectionHelper
MainRegistry.logger.error("Failed to capture drops for block " + block, e);
} catch (InvocationTargetException e) {
// Might be possible? Not in practice, though
MainRegistry.logger.error("Failed to capture drops for block " + block, e);
}
}
}

View File

@ -50,4 +50,8 @@ public net.minecraft.client.resources.AbstractResourcePack field_110597_b # re
public net.minecraft.inventory.Container * # fucking everything i hate this class
# GuiIngame
public net.minecraft.client.gui.GuiIngame field_92016_l # highlightingItemStack
public net.minecraft.client.gui.GuiIngame field_92016_l # highlightingItemStack
# Block
public net.minecraft.block.Block func_149642_a(Lnet/minecraft/world/World;IIILnet/minecraft/item/ItemStack;)V # dropBlockAsItem