1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-04 07:32:59 +00:00

Fix computers/turtles not being dropped on explosion

Computer drops are currently[^1] implemented via a dynamic drop. To
support this, we need to inject the dynamic drop into the loot
parameters.

We currently do this by implementing our own drop logic in
playerWillDestroy[^2], manually creating the loot params and adding our
additional drop. However, if the item is dropped via some other method
(such as via explosions), we'll go through vanilla's drop logic and so
never add the dynamic drop!

The correct way to do this is to override getDrops to add the dynamic
drop instead. I don't know why we didn't always do this -- the code in
question was first written for MC 1.14[^3], when things were very
different.

[^1]: This is no longer the case on 1.21, where we can just copy
      capabilities.

[^2]: We need to override vanilla's drop behaviour to ensure items are
      dropped in creative mode.

[^3]: See 594bc4203c. Which probably means
      the bug has been around for 5 years :/.
This commit is contained in:
Jonathan Coates
2024-08-14 21:12:30 +01:00
parent 9484315d37
commit bb97c465d9
4 changed files with 168 additions and 23 deletions

View File

@@ -19,9 +19,11 @@ import net.minecraft.gametest.framework.GameTest
import net.minecraft.gametest.framework.GameTestHelper
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.LeverBlock
import net.minecraft.world.level.block.RedstoneLampBlock
import net.minecraft.world.phys.Vec3
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.lwjgl.glfw.GLFW
@@ -115,6 +117,20 @@ class Computer_Test {
thenOnComputer { callPeripheral("right", "size").assertArrayEquals(54) }
}
/**
* Tests a computer item is dropped on explosion.
*/
@GameTest
fun Drops_on_explosion(context: GameTestHelper) = context.sequence {
thenExecute {
val pos = BlockPos(2, 2, 2)
val explosionPos = Vec3.atCenterOf(context.absolutePos(pos))
context.level.explode(null, explosionPos.x, explosionPos.y, explosionPos.z, 2.0f, Level.ExplosionInteraction.TNT)
context.assertItemEntityPresent(ModRegistry.Items.COMPUTER_NORMAL.get(), pos, 1.0)
}
}
/**
* Check the client can open the computer UI and interact with it.
*/