Update chest upgrader item

This commit is contained in:
DBotThePony 2024-08-24 12:07:23 +07:00
parent e3bbc9a51e
commit 0631287d4f
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -1,18 +1,15 @@
package ru.dbotthepony.mc.otm.item
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap
import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component
import net.minecraft.core.component.DataComponents
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.Container
import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult
import net.minecraft.world.entity.vehicle.AbstractMinecart
import net.minecraft.world.entity.vehicle.MinecartChest
import net.minecraft.world.item.*
import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.item.context.UseOnContext
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.LevelEvent
import net.minecraft.world.level.block.entity.BarrelBlockEntity
@ -20,14 +17,11 @@ 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 net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters.MOD_ID
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
import ru.dbotthepony.mc.otm.container.get
import ru.dbotthepony.mc.otm.container.set
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.entity.MinecartCargoCrate
import ru.dbotthepony.mc.otm.registry.MEntityTypes
@ -143,15 +137,16 @@ class ChestUpgraderItem : MatteryItem(Properties().stacksTo(1)) {
newCart.xRot = cart.xRot
newCart.yRot = cart.yRot
newCart.deltaMovement = delta
newCart.customName = if (stack.hasCustomHoverName()) stack.hoverName else cart.customName
newCart.customName = stack[DataComponents.CUSTOM_NAME] ?: cart.customName
val contents = Int2ObjectArrayMap<ItemStack>(cart.containerSize)
for (i in 0 until cart.containerSize) {
for (i in 0 until cart.containerSize)
contents.put(i, cart.getItem(i))
}
cart.clearContent()
(cart as AbstractMinecart).destroy(cart.damageSources().genericKill())
cart.destroy(cart.damageSources().genericKill())
level.addFreshEntity(newCart)
level.gameEvent(GameEvent.ENTITY_PLACE, event.pos, GameEvent.Context.of(event.entity, level.getBlockState(event.pos.below())))