Fix visual glitch with harvest abilities

This commit is contained in:
abel1502 2025-05-18 16:16:32 +03:00
parent aadb2d5f2a
commit 4728e3c6ba
No known key found for this signature in database
GPG Key ID: 076926596A536338

View File

@ -27,11 +27,14 @@ public interface IToolHarvestAbility extends IBaseAbility {
public default void postHarvestAll(int level, World world, EntityPlayer player) {} public default void postHarvestAll(int level, World world, EntityPlayer player) {}
public boolean skipDefaultDrops(int level); // You must call harvestBlock to actually break the block.
// If you don't, visual glitches ensue
// Call IToolHarvestAbility.super.onHarvestBlock to emulate the actual block breaking
public default void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public default void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
if (skipDefaultDrops(level)) { harvestBlock(false, world, x, y, z, player);
}
public static void harvestBlock(boolean skipDefaultDrops, World world, int x, int y, int z, EntityPlayer player) {
if (skipDefaultDrops) {
// Emulate the block breaking without drops // Emulate the block breaking without drops
world.setBlockToAir(x, y, z); world.setBlockToAir(x, y, z);
player.getHeldItem().damageItem(1, player); player.getHeldItem().damageItem(1, player);
@ -54,11 +57,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
public int sortOrder() { public int sortOrder() {
return SORT_ORDER_BASE + 0; return SORT_ORDER_BASE + 0;
} }
@Override
public boolean skipDefaultDrops(int level) {
return false;
}
}; };
public static final IToolHarvestAbility SILK = new IToolHarvestAbility() { public static final IToolHarvestAbility SILK = new IToolHarvestAbility() {
@ -77,11 +75,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 1; return SORT_ORDER_BASE + 1;
} }
@Override
public boolean skipDefaultDrops(int level) {
return false;
}
@Override @Override
public void preHarvestAll(int level, World world, EntityPlayer player) { public void preHarvestAll(int level, World world, EntityPlayer player) {
ItemStack stack = player.getHeldItem(); ItemStack stack = player.getHeldItem();
@ -126,11 +119,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 2; return SORT_ORDER_BASE + 2;
} }
@Override
public boolean skipDefaultDrops(int level) {
return false;
}
@Override @Override
public void preHarvestAll(int level, World world, EntityPlayer player) { public void preHarvestAll(int level, World world, EntityPlayer player) {
ItemStack stack = player.getHeldItem(); ItemStack stack = player.getHeldItem();
@ -163,11 +151,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 3; return SORT_ORDER_BASE + 3;
} }
@Override
public boolean skipDefaultDrops(int level) {
return true;
}
@Override @Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0); List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
@ -186,11 +169,12 @@ public interface IToolHarvestAbility extends IBaseAbility {
} }
} }
if(doesSmelt) { harvestBlock(doesSmelt, world, x, y, z, player);
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
for(ItemStack stack : drops) 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, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
}
} }
} }
}; };
@ -211,11 +195,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 4; return SORT_ORDER_BASE + 4;
} }
@Override
public boolean skipDefaultDrops(int level) {
return true;
}
@Override @Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound //a band-aid on a gaping wound
@ -225,8 +204,11 @@ public interface IToolHarvestAbility extends IBaseAbility {
ItemStack stack = new ItemStack(block, 1, meta); ItemStack stack = new ItemStack(block, 1, meta);
ItemStack result = ShredderRecipes.getShredderResult(stack); ItemStack result = ShredderRecipes.getShredderResult(stack);
if(result != null && result.getItem() != ModItems.scrap) { boolean doesShred = result != null && result.getItem() != ModItems.scrap;
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
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, x + 0.5, y + 0.5, z + 0.5, result.copy()));
} }
} }
@ -248,11 +230,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 5; return SORT_ORDER_BASE + 5;
} }
@Override
public boolean skipDefaultDrops(int level) {
return true;
}
@Override @Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound //a band-aid on a gaping wound
@ -262,12 +239,15 @@ public interface IToolHarvestAbility extends IBaseAbility {
ItemStack stack = new ItemStack(block, 1, meta); ItemStack stack = new ItemStack(block, 1, meta);
ItemStack[] result = CentrifugeRecipes.getOutput(stack); ItemStack[] result = CentrifugeRecipes.getOutput(stack);
if(result != null) { boolean doesCentrifuge = result != null;
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
harvestBlock(doesCentrifuge, world, x, y, z, player);
if(doesCentrifuge) {
for(ItemStack st : result) { for(ItemStack st : result) {
if(st != null) if(st != null) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy())); world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy()));
}
} }
} }
} }
@ -289,11 +269,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 6; return SORT_ORDER_BASE + 6;
} }
@Override
public boolean skipDefaultDrops(int level) {
return true;
}
@Override @Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound //a band-aid on a gaping wound
@ -303,8 +278,11 @@ public interface IToolHarvestAbility extends IBaseAbility {
ItemStack stack = new ItemStack(block, 1, meta); ItemStack stack = new ItemStack(block, 1, meta);
CrystallizerRecipe result = CrystallizerRecipes.getOutput(stack, Fluids.PEROXIDE); CrystallizerRecipe result = CrystallizerRecipes.getOutput(stack, Fluids.PEROXIDE);
if(result != null) { boolean doesCrystallize = result != null;
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
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, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
} }
} }
@ -326,11 +304,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
return SORT_ORDER_BASE + 7; return SORT_ORDER_BASE + 7;
} }
@Override
public boolean skipDefaultDrops(int level) {
return true;
}
@Override @Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) { public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound //a band-aid on a gaping wound
@ -344,8 +317,11 @@ public interface IToolHarvestAbility extends IBaseAbility {
if(block == Blocks.redstone_block) if(block == Blocks.redstone_block)
mercury = player.getRNG().nextInt(7) + 8; mercury = player.getRNG().nextInt(7) + 8;
if(mercury > 0) { boolean doesConvert = mercury > 0;
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
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, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
} }
} }