emit events and particles on chest upgrade
This commit is contained in:
parent
db4f24e85e
commit
1f72cd865c
@ -17,6 +17,7 @@ import net.minecraft.world.level.Level
|
|||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.block.entity.BarrelBlockEntity
|
import net.minecraft.world.level.block.entity.BarrelBlockEntity
|
||||||
import net.minecraft.world.level.block.entity.ChestBlockEntity
|
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.LootParams
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters.MOD_ID
|
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 (container.containerSize >= 54) return super.onItemUseFirst(stack, context)
|
||||||
|
|
||||||
if (context.level is ServerLevel) {
|
val blockState = context.level.getBlockState(pos)
|
||||||
val newState = block.getStateForPlacement(BlockPlaceContext(context)) ?: return InteractionResult.FAIL
|
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)
|
val contents = Int2ObjectArrayMap<ItemStack>(container.containerSize)
|
||||||
for (i in 0 until container.containerSize) {
|
for (i in 0 until container.containerSize) {
|
||||||
contents.put(i, container.getItem(i))
|
contents.put(i, container.getItem(i))
|
||||||
@ -58,7 +64,6 @@ class ChestUpgraderItem : Item(Properties().stacksTo(1)) {
|
|||||||
|
|
||||||
val level = context.level as ServerLevel
|
val level = context.level as ServerLevel
|
||||||
|
|
||||||
val blockState = level.getBlockState(pos)
|
|
||||||
val lootparams = LootParams.Builder(level)
|
val lootparams = LootParams.Builder(level)
|
||||||
.withParameter(LootContextParams.ORIGIN, Vector.atCenterOf(context.clickedPos))
|
.withParameter(LootContextParams.ORIGIN, Vector.atCenterOf(context.clickedPos))
|
||||||
.withParameter(LootContextParams.TOOL, stack)
|
.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
|
return InteractionResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user