Skip to content

Commit

Permalink
fix: setBlockNoPP
Browse files Browse the repository at this point in the history
[publish beta]

Signed-off-by: Liyan Zhao <[email protected]>
  • Loading branch information
zly2006 committed Mar 21, 2024
1 parent 95f5561 commit bf198b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/github/zly2006/reden/malilib/KeyCallbacks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import net.minecraft.block.Blocks
import net.minecraft.block.entity.StructureBlockBlockEntity
import net.minecraft.block.enums.StructureBlockMode
import net.minecraft.client.MinecraftClient
import net.minecraft.client.sound.AbstractSoundInstance
import net.minecraft.network.packet.c2s.play.UpdateStructureBlockC2SPacket
import net.minecraft.sound.SoundCategory
import net.minecraft.text.Text
Expand All @@ -76,6 +77,11 @@ fun configureKeyCallbacks(mc: MinecraftClient) {
true
}
var undoEasterEggLock = false
val zawaludo = object : AbstractSoundInstance(
Sounds.THE_WORLD.id,
SoundCategory.VOICE,
net.minecraft.util.math.random.Random.create()
) {}
UNDO_KEY.callback {
if (undoEasterEggLock) {
mc.player?.sendMessage(translateMessage("undo", "busy"))
Expand All @@ -90,12 +96,7 @@ fun configureKeyCallbacks(mc: MinecraftClient) {
return@callback false
val playSound = Random.nextInt(100) < EASTER_EGG_RATE.integerValue
if (playSound) {
mc.world!!.playSound(
mc.player,
mc.player!!.blockPos,
Sounds.THE_WORLD,
SoundCategory.BLOCKS
)
mc.soundManager.play(zawaludo)
undoEasterEggLock = true
if (!EASTER_EGG_RATE.isModified) {
val key = "reden:easter_egg/the_world"
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/github/zly2006/reden/report/Report.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.github.zly2006.reden.utils.isClient
import com.github.zly2006.reden.utils.isDevVersion
import com.github.zly2006.reden.utils.redenApiBaseUrl
import com.github.zly2006.reden.utils.server
import com.mojang.authlib.exceptions.InvalidCredentialsException
import com.mojang.authlib.minecraft.UserApiService
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
Expand Down Expand Up @@ -374,6 +375,9 @@ fun updateOnlineInfo(client: MinecraftClient): Boolean {
if (shutdown) return false
}.key) { "Reden ApiKey is null" }
return true
} catch (_: InvalidCredentialsException) {
LOGGER.error("Cannot log you in, are you using an online minecraft account?")
return false
} catch (e: Exception) {
LOGGER.error("Failed to login", e)
return false
Expand Down Expand Up @@ -416,6 +420,9 @@ fun redenSetup(client: MinecraftClient) {
client.session.accessToken,
"3cb49a79c3af1f1dba6c56eddd760ac7d50c518a"
)
} catch (_: InvalidCredentialsException) {
req.online_mode = false
LOGGER.warn("Failed to login to minecraft, using offline mode.")
} catch (e: Exception) {
LOGGER.error("", e)
req.online_mode = false
Expand Down
35 changes: 2 additions & 33 deletions src/main/java/com/github/zly2006/reden/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import net.minecraft.network.PacketByteBuf
import net.minecraft.registry.Registries
import net.minecraft.server.MinecraftServer
import net.minecraft.server.ServerTask
import net.minecraft.server.world.ServerWorld
import net.minecraft.text.MutableText
import net.minecraft.text.Text
import net.minecraft.util.Formatting
Expand All @@ -31,9 +30,7 @@ import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.util.math.Vec3d
import net.minecraft.world.Heightmap
import net.minecraft.world.World
import net.minecraft.world.chunk.light.ChunkLightProvider
import java.io.IOException
import java.io.InputStream
import java.net.URL
Expand All @@ -56,36 +53,8 @@ val ClientPlayerEntity.holdingToolItem: Boolean get() {
return Registries.ITEM.getId(stack.item) == Identifier.tryParse(SELECTION_TOOL.stringValue)
}

fun World.setBlockNoPP(pos: BlockPos, state: BlockState, flags: Int) {
profiler.push("reden_setBlockState_noPP")
val stateBefore = getBlockState(pos)
if (stateBefore.hasBlockEntity()) {
removeBlockEntity(pos)
}
getChunk(pos).run { getSection(getSectionIndex(pos.y)) }
.setBlockState(pos.x and 15, pos.y and 15, pos.z and 15, state, false)
getChunk(pos).run {
this.heightmaps[Heightmap.Type.MOTION_BLOCKING]!!.trackUpdate(pos.x and 15, pos.y, pos.z and 15, state)
this.heightmaps[Heightmap.Type.MOTION_BLOCKING_NO_LEAVES]!!.trackUpdate(pos.x and 15, pos.y, pos.z and 15, state)
this.heightmaps[Heightmap.Type.OCEAN_FLOOR]!!.trackUpdate(pos.x and 15, pos.y, pos.z and 15, state)
this.heightmaps[Heightmap.Type.WORLD_SURFACE]!!.trackUpdate(pos.x and 15, pos.y, pos.z and 15, state)
setNeedsSaving(true)

if (ChunkLightProvider.needsLightUpdate(this, pos, stateBefore, state)) {
profiler.push("updateSkyLightSources")
chunkSkyLight.isSkyLightAccessible(this, pos.x and 15, pos.y and 15, pos.z and 15)
profiler.swap("queueCheckLight")
chunkManager.lightingProvider.checkBlock(pos)
profiler.pop()
}
}
if (this is ServerWorld) {
chunkManager.markForUpdate(pos)
}
if (flags and Block.NOTIFY_LISTENERS != 0) {
updateListeners(pos, stateBefore, state, flags)
}
profiler.pop()
fun World.setBlockNoPP(pos: BlockPos, state: BlockState, flags: Int = Block.NOTIFY_LISTENERS) {
setBlockState(pos, state, flags and Block.NOTIFY_NEIGHBORS.inv() or Block.FORCE_STATE or Block.SKIP_DROPS)
}

val isClient: Boolean get() = FabricLoader.getInstance().environmentType == EnvType.CLIENT
Expand Down

0 comments on commit bf198b6

Please sign in to comment.