Skip to content

Commit

Permalink
fix: Try update custom blocks and custom item event
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchen5209 committed Nov 12, 2024
1 parent b8b65f0 commit 3dd8d99
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/block/CustomBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package one.oktw.galaxy.block

import net.fabricmc.fabric.api.`object`.builder.v1.block.entity.FabricBlockEntityTypeBuilder
import net.minecraft.block.Block
import net.minecraft.block.Blocks.*
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.block.entity.BlockEntityType.Builder
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.util.Identifier
Expand All @@ -37,7 +37,7 @@ open class CustomBlock(final override val identifier: Identifier, val baseBlock:
protected val blockEntityType: BlockEntityType<CustomBlockEntity> = Registry.register(
Registries.BLOCK_ENTITY_TYPE,
identifier,
Builder.create({ pos, _ -> createBlockEntity(pos) }, BARRIER).build(null)
FabricBlockEntityTypeBuilder.create({ pos, _ -> createBlockEntity(pos) }, BARRIER).build(null)
)

companion object {
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/block/event/BlockEvents.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2023
* Copyright (C) 2018-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
Expand All @@ -22,6 +22,7 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.minecraft.advancement.criterion.Criteria
import net.minecraft.item.ItemPlacementContext
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import one.oktw.galaxy.block.CustomBlockHelper
import one.oktw.galaxy.block.entity.ModelCustomBlockEntity
Expand Down Expand Up @@ -62,7 +63,7 @@ class BlockEvents {
val result = blockEntity.onClick(player, packet.hand, hitResult)
if (result.isAccepted) {
Criteria.ITEM_USED_ON_BLOCK.trigger(player, hitResult.blockPos, player.getStackInHand(packet.hand))
event.swing = result.shouldSwingHand()
event.swing = (result as? ActionResult.Success)?.swingSource() == ActionResult.SwingSource.SERVER
usedLock[player] = player.server.ticks
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/block/event/Elevator.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OKTW Galaxy Project
* Copyright (C) 2018-2023
* Copyright (C) 2018-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
Expand Down Expand Up @@ -35,7 +35,7 @@ class Elevator {
}

private fun isSafe(world: ServerWorld, blockPos: BlockPos): Boolean {
return !world.getBlockState(blockPos).isOpaqueFullCube(world, blockPos)
return !world.getBlockState(blockPos).isOpaqueFullCube
}

private fun doTeleport(player: ServerPlayerEntity, pos: BlockPos) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/one/oktw/galaxy/item/event/Wrench.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Wrench {
}

world.setBlockState(blockPos, newState)
world.updateNeighbor(newState, blockPos, newState.block, blockPos, true)
world.updateNeighbor(newState, blockPos, newState.block, null, true)
// Workaround disable state update for bell
Block.postProcessState(newState, world, blockPos).let { if (!it.isAir && it.block != BELL) world.setBlockState(blockPos, it, 2) }

Expand Down

0 comments on commit 3dd8d99

Please sign in to comment.