Skip to content

Commit

Permalink
fix: Upgrading an obsidian chest could make it lose the obsidian upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekromaster committed Aug 3, 2024
1 parent dcd2932 commit d22873d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/kotlin/net/zekromaster/minecraft/ironchests/upgrades.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import net.modificationstation.stationapi.api.util.Identifier
import net.modificationstation.stationapi.api.util.math.Direction
import net.zekromaster.minecraft.ironchests.IronChestsBlockStates.FACING
import net.zekromaster.minecraft.ironchests.IronChestMaterial.*
import net.zekromaster.minecraft.ironchests.IronChestsBlockStates.HAS_OBSIDIAN_UPGRADE
import net.zekromaster.minecraft.ironchests.mixin.ChestInventoryAccessor

internal object IronChestsUpgradesEntrypoint {
Expand Down Expand Up @@ -110,7 +111,10 @@ private sealed class TierUpgrade(identifier: Identifier, private val destination
world.setBlock(x, y, z, destination.getBlock().id)

if (oldBlock is IronChestBlock) {
world.setBlockState(x, y, z, world.getBlockState(x, y, z).with(FACING, oldBlockState.get(FACING) ?: Direction.NORTH))
world.setBlockState(x, y, z, world.getBlockState(x, y, z)
.with(FACING, oldBlockState.get(FACING) ?: Direction.NORTH)
.with(HAS_OBSIDIAN_UPGRADE, oldBlockState.get(HAS_OBSIDIAN_UPGRADE) ?: false)
)
} else {
world.setBlockState(x, y, z, world.getBlockState(x, y, z).with(FACING, player.placementFacing()))
}
Expand Down Expand Up @@ -146,12 +150,12 @@ private class ObsidianUpgrade(identifier: Identifier): ChestUpgrade(identifier)
blockEntity: ChestBlockEntity
): Boolean {
val blockState = world.getBlockState(x, y, z)
if (blockState.block !is IronChestBlock || blockState.get(IronChestsBlockStates.HAS_OBSIDIAN_UPGRADE)) {
if (blockState.block !is IronChestBlock || blockState.get(HAS_OBSIDIAN_UPGRADE)) {
return false
}

val entity = world.getBlockEntity(x, y, z) as IronChestBlockEntity
world.setBlockStateWithNotify(x, y, z, blockState.with(IronChestsBlockStates.HAS_OBSIDIAN_UPGRADE, true))
world.setBlockStateWithNotify(x, y, z, blockState.with(HAS_OBSIDIAN_UPGRADE, true))
world.setBlockEntity(x, y, z, entity)
entity.isBlastResistant = true
world.setBlockDirty(x, y, z)
Expand Down

0 comments on commit d22873d

Please sign in to comment.