From 9ccf397777e4e2f1bc90946202d9337a72cd4727 Mon Sep 17 00:00:00 2001 From: B1n_ry Date: Sun, 17 Mar 2024 01:06:55 +0100 Subject: [PATCH] Fix to render and grave robbing mechanic --- CHANGELOG.md | 2 ++ .../render/GraveBlockEntityRenderer.java | 18 ++++++++++-------- .../yigd/compat/BeansBackpacksCompat.java | 10 +++------- .../b1n_ry/yigd/components/GraveComponent.java | 9 +++++---- .../yigd/events/YigdServerEventHandler.java | 9 +++++++-- src/main/resources/assets/yigd/lang/en_us.json | 1 + 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf901eb..a0d56ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ before removing a compatible inventory mod * Fixed crash with Beans Backpacks * No longer sending error message to player when claiming the grave by breaking it * Default trinket drop rule will now actually be default +* Fixed adaptive grave renderer, so it renders the grave properly (still not perfect adaptive rendering though) +* Fixed issues where grave robbing didn't work outside very specific conditions ### Changes * Improved compatibility with Beans Backpacks, by dropping the backpack instead of the diff --git a/src/main/java/com/b1n_ry/yigd/client/render/GraveBlockEntityRenderer.java b/src/main/java/com/b1n_ry/yigd/client/render/GraveBlockEntityRenderer.java index 876d821..5b68392 100644 --- a/src/main/java/com/b1n_ry/yigd/client/render/GraveBlockEntityRenderer.java +++ b/src/main/java/com/b1n_ry/yigd/client/render/GraveBlockEntityRenderer.java @@ -15,10 +15,7 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.model.*; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.render.OutlineVertexConsumerProvider; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.*; import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.client.render.block.entity.SkullBlockEntityModel; @@ -32,7 +29,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.RotationAxis; -import net.minecraft.util.math.random.Random; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import org.joml.Quaternionf; @@ -166,13 +162,19 @@ private void renderGraveModel(GraveBlockEntity entity, float ignoredTickDelta, M BlockState blockUnder = entity.getWorld().getBlockState(underPos); if (blockUnder != null && blockUnder.isOpaqueFullCube(world, underPos)) { - ModelPart.Cuboid cuboidPart = part.getRandomCuboid(Random.create()); // Only contains 1 cuboid, so we'll get that one + ModelPart.Cuboid cuboidPart = part.getRandomCuboid(world.random); // Only contains 1 cuboid, so we'll get that one float scaleX = cuboidPart.maxX - cuboidPart.minX; float scaleZ = cuboidPart.maxZ - cuboidPart.minZ; + matrices.push(); + matrices.translate(cuboidPart.minX / 16f + .0005f, cuboidPart.maxY / 16f - 1f, cuboidPart.minZ / 16f + .0005f); - matrices.scale(.999f * (scaleX / 16f), 1, .999f * (scaleZ / 16f)); - this.client.getBlockRenderManager().renderBlock(blockUnder, underPos, world, matrices, vertexConsumers.getBuffer(RenderLayer.getCutout()), true, world.getRandom()); + matrices.scale(.999f * (scaleX / 16f), 1f, .999f * (scaleZ / 16f)); + + this.client.getBlockRenderManager() + .renderBlock(blockUnder, underPos, world, matrices, vertexConsumers.getBuffer( + RenderLayer.getCutout()), true, world.random); + matrices.pop(); continue; } diff --git a/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java b/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java index 62e85be..85c5331 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java @@ -5,7 +5,6 @@ import com.b1n_ry.yigd.data.DeathContext; import com.b1n_ry.yigd.events.DropRuleEvent; import com.b1n_ry.yigd.util.DropRule; -import com.beansgalaxy.backpacks.data.BackData; import com.beansgalaxy.backpacks.platform.services.CompatHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -124,14 +123,11 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { CompatHelper.setBackStack(player, backpack); - BackData backData = CompatHelper.getBackData(player); - backData.backpackInventory.clear(); + DefaultedList backpackInventory = CompatHelper.getBackpackInventory(player); + backpackInventory.clear(); for (ItemStack stack : backpackContents) { if (!stack.isEmpty()) { - ItemStack leftOver = backData.backpackInventory.insertItemSilent(stack, stack.getCount()); - if (!leftOver.isEmpty()) { - extraItems.add(leftOver); - } + backpackInventory.add(stack); } } diff --git a/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java b/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java index c15ca79..d3817e9 100644 --- a/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java +++ b/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java @@ -323,10 +323,10 @@ public void backUp() { DeathInfoManager.INSTANCE.markDirty(); } - public boolean hasExistedMs(long time) { + public boolean hasExistedTicks(long time) { if (this.world == null) return false; - return this.world.getTime() - this.creationTime.getTime() < time; + return this.world.getTime() - this.creationTime.getTime() >= time; } /** @@ -336,10 +336,11 @@ public boolean hasExistedMs(long time) { */ public String getTimeUntilRobbable() { if (this.world == null) return "0"; + final int tps = 20; YigdConfig.GraveConfig.GraveRobbing robConfig = YigdConfig.getConfig().graveConfig.graveRobbing; - long delay = robConfig.timeUnit.toSeconds(robConfig.afterTime); + long delay = robConfig.timeUnit.toSeconds(robConfig.afterTime) * tps; - long timePassed = this.creationTime.getTime() - this.world.getTime() + delay; + long timePassed = (this.creationTime.getTime() - this.world.getTime() + delay) / tps; long seconds = timePassed % 60; long minutes = (timePassed / 60) % 60; long hours = timePassed / 3600; diff --git a/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java b/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java index c958558..bf3516f 100644 --- a/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java +++ b/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java @@ -162,12 +162,17 @@ public static void registerEventCallbacks() { if (!robConfig.enabled) return false; final int tps = 20; // ticks per second - if (!grave.hasExistedMs(robConfig.timeUnit.toSeconds(robConfig.afterTime) * tps)) { + if (!grave.hasExistedTicks(robConfig.timeUnit.toSeconds(robConfig.afterTime) * tps)) { player.sendMessage(Text.translatable("text.yigd.message.rob.too_early", grave.getTimeUntilRobbable()), true); return false; } - return robConfig.onlyMurderer && player.getUuid().equals(grave.getKillerId()); + if (robConfig.onlyMurderer && !player.getUuid().equals(grave.getKillerId())) { + player.sendMessage(Text.translatable("text.yigd.message.rob_not_killer", grave.getOwner().getName()), true); + return false; + } + + return true; }); AllowGraveGenerationEvent.EVENT.register((context, grave) -> { diff --git a/src/main/resources/assets/yigd/lang/en_us.json b/src/main/resources/assets/yigd/lang/en_us.json index bd0b712..6b2f5bb 100644 --- a/src/main/resources/assets/yigd/lang/en_us.json +++ b/src/main/resources/assets/yigd/lang/en_us.json @@ -64,6 +64,7 @@ "text.yigd.command.whitelist.toggle": "Toggled list to %s", "text.yigd.command.whitelist.set_mode": "Set list to %s", "text.yigd.message.rob.too_early": "You can not rob this grave until in %s", + "text.yigd.message.rob_not_killer": "You can't rob this grave as you did not kill %s", "text.yigd.message.missing_key": "You do not have the proper key to unlock this grave", "text.yigd.message.no_shovel": "You need a shovel to loot this grave", "text.yigd.message.sellout_player": "%s logged off, and they have a grave at X: %d / Y: %d / Z: %d / %s",