Skip to content

Commit

Permalink
Fix to render and grave robbing mechanic
Browse files Browse the repository at this point in the history
  • Loading branch information
B1n-ry committed Mar 17, 2024
1 parent bfc9d61 commit 9ccf397
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,14 +123,11 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {

CompatHelper.setBackStack(player, backpack);

BackData backData = CompatHelper.getBackData(player);
backData.backpackInventory.clear();
DefaultedList<ItemStack> 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);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/b1n_ry/yigd/components/GraveComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/yigd/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9ccf397

Please sign in to comment.