Skip to content

Commit

Permalink
Merge branch '1.20' into 1.20.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	gradle.properties
  • Loading branch information
Patbox committed Jan 25, 2024
2 parents 1d70b94 + fe08a33 commit c042045
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static class Placement {
public int shiftDistance = 40;
@SerializedName("generate_on_top_of_fluids")
public boolean generateOnTopOfFluids = false;
@SerializedName("generate_on_ground")
public boolean generateOnGround = false;

@SerializedName("create_gravestone_after_emptying")
public boolean createVisualGrave = false;
@SerializedName("restore_replaced_block_after_player_breaking")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ItemDisplayModelPart extends DisplayModelPart<ItemDisplayElement, I

@Override
protected ItemDisplayElement constructBase() {
var e = new ItemDisplayElement(this.itemStack);
var e = new ItemDisplayElement(this.itemStack.copy());
e.setModelTransformation(this.itemModelTransformation);
return e;
}
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/eu/pb4/graves/other/GraveUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicketType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand All @@ -45,10 +46,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.GameRules;
Expand All @@ -60,6 +58,8 @@
import java.util.stream.Collectors;

public class GraveUtils {
private static final ChunkTicketType<Grave> GRAVE_TICKED = ChunkTicketType.create("universal_graves", Comparator.comparing(Grave::getId), 5);

public static final Identifier REPLACEABLE_ID = new Identifier("universal_graves", "replaceable");
public static final TagKey<Block> REPLACEABLE_TAG = TagKey.of(RegistryKeys.BLOCK, REPLACEABLE_ID);
public static final Inventory EMPTY_INVENTORY = new SimpleInventory(0);
Expand All @@ -82,6 +82,11 @@ public static BlockCheckResult findGravePosition(ServerPlayerEntity player, Serv
var border = world.getWorldBorder();
blockPos = BlockPos.ofFloored(MathHelper.clamp(blockPos.getX(), border.getBoundWest() + 1, border.getBoundEast() - 1), MathHelper.clamp(blockPos.getY(), world.getBottomY(), world.getTopY() - 1), MathHelper.clamp(blockPos.getZ(), border.getBoundNorth() + 1, border.getBoundSouth() - 1));
var config = ConfigManager.getConfig();
if (config.placement.generateOnGround) {
while (world.getBlockState(blockPos).isAir() && world.getBottomY() + 2 < blockPos.getY()) {
blockPos = blockPos.down();
}
}

var result = isValidPos(player, world, border, blockPos, false, config);
if (result.allow) {
Expand Down Expand Up @@ -287,7 +292,7 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) {

WrappedText text = null;
var placeholders = Map.of(
"position", Text.literal("" + player.getBlockPos().toShortString()),
"position", Text.literal(player.getBlockPos().toShortString()),
"world", GraveUtils.toWorldName(player.getWorld().getRegistryKey().getValue())
);

Expand Down Expand Up @@ -320,6 +325,9 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) {
var model = config.getGraveModel(player);

BlockPos gravePos = result.pos();
if (gravePos == null) {
return;
}
List<PositionedItemStack> items = new ArrayList<>();

for (var mask : GravesApi.getAllInventoryMasks()) {
Expand All @@ -331,7 +339,7 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) {
experience = config.storage.xpStorageType.converter.calc(player);
}

if (items.size() == 0 && (!config.storage.canStoreOnlyXp || experience == 0)) {
if (items.isEmpty() && (!config.storage.canStoreOnlyXp || experience == 0)) {
return;
}

Expand Down Expand Up @@ -367,6 +375,8 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) {
var fluidState = world.getFluidState(gravePos);
world.setBlockState(gravePos, TempBlock.INSTANCE.getDefaultState());

world.getChunkManager().addTicket(GRAVE_TICKED, new ChunkPos(gravePos), 1, grave);

GravesMod.DO_ON_NEXT_TICK.add(() -> {
WrappedText text2;
Map<String, Text> placeholders2 = placeholders;
Expand All @@ -381,13 +391,14 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) {
GraveManager.INSTANCE.add(grave);
graveBlockEntity.setGrave(grave, storedBlockState);
graveBlockEntity.setModelId(model);
world.markDirty(gravePos);
text2 = config.texts.messageGraveCreated;
placeholders2 = grave.getPlaceholders(player.getServer());


if (config.placement.maxGraveCount > -1) {
var graves = new ArrayList<>(GraveManager.INSTANCE.getByPlayer(player));
graves.sort(Comparator.comparing(x -> x.getCreationTime()));
graves.sort(Comparator.comparing(Grave::getCreationTime));
while (graves.size() > config.placement.maxGraveCount) {
graves.remove(0).destroyGrave(player.server, null);
}
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,10 @@ protected void writeNbt(NbtCompound nbt) {
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
try {
if (nbt.contains("GraveInfo", NbtElement.COMPOUND_TYPE)) {
// Legacy grave handling
this.data = new Grave();
this.data.readNbt(nbt.getCompound("GraveInfo"));

NbtList nbtList = nbt.getList("Items", NbtElement.COMPOUND_TYPE);

for (NbtElement compound : nbtList) {
this.data.getItems().add(new PositionedItemStack(ItemStack.fromNbt((NbtCompound) compound), -1, VanillaInventoryMask.INSTANCE, null, Set.of()));
}
GraveManager.INSTANCE.add(this.data);
this.visualData = this.data.toVisualGraveData();
} else if (nbt.contains("GraveId", NbtElement.LONG_TYPE)) {
if (nbt.contains("GraveId", NbtElement.LONG_TYPE)) {
this.graveId = nbt.getLong("GraveId");
}

if (this.data == null) {
this.fetchGraveData();
}
this.fetchGraveData();

if (this.visualData == null) {
this.visualData = VisualGraveData.fromNbt(nbt.getCompound("VisualData"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"universal_graves:grave"
]
}

0 comments on commit c042045

Please sign in to comment.