emit events and particles on chest upgrade

This commit is contained in:
YuRaNnNzZZ 2023-10-26 08:53:53 +03:00
parent db4f24e85e
commit 1f72cd865c
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D

View File

@ -17,6 +17,7 @@ import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.entity.BarrelBlockEntity
import net.minecraft.world.level.block.entity.ChestBlockEntity
import net.minecraft.world.level.gameevent.GameEvent
import net.minecraft.world.level.storage.loot.LootParams
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
import ru.dbotthepony.mc.otm.OverdriveThatMatters.MOD_ID
@ -47,9 +48,14 @@ class ChestUpgraderItem : Item(Properties().stacksTo(1)) {
if (container.containerSize >= 54) return super.onItemUseFirst(stack, context)
if (context.level is ServerLevel) {
val newState = block.getStateForPlacement(BlockPlaceContext(context)) ?: return InteractionResult.FAIL
val blockState = context.level.getBlockState(pos)
val newState = block.getStateForPlacement(BlockPlaceContext(context)) ?: return InteractionResult.FAIL
if (!newState.canSurvive(context.level, pos)) return InteractionResult.FAIL
context.level.gameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Context.of(player, blockState))
context.level.levelEvent(player, 2001, pos, Block.getId(blockState))
if (context.level is ServerLevel) {
val contents = Int2ObjectArrayMap<ItemStack>(container.containerSize)
for (i in 0 until container.containerSize) {
contents.put(i, container.getItem(i))
@ -58,7 +64,6 @@ class ChestUpgraderItem : Item(Properties().stacksTo(1)) {
val level = context.level as ServerLevel
val blockState = level.getBlockState(pos)
val lootparams = LootParams.Builder(level)
.withParameter(LootContextParams.ORIGIN, Vector.atCenterOf(context.clickedPos))
.withParameter(LootContextParams.TOOL, stack)
@ -86,6 +91,8 @@ class ChestUpgraderItem : Item(Properties().stacksTo(1)) {
}
}
context.level.gameEvent(GameEvent.BLOCK_PLACE, pos, GameEvent.Context.of(player, newState))
return InteractionResult.SUCCESS
}