Skip to content

Commit

Permalink
[2.0.0-beta.2] Stability fixes
Browse files Browse the repository at this point in the history
- Added `universal_graves:breaking_time` and `universal_graves:protection_time`
- Visual Graves now use their own hologram/sign text
- Changing protection time to 0 disables it (it was it's own option before)
- Graves now have static id instead of being position based
- Fixed compatibility with Immersive Portals
- Fixed few bugs
  • Loading branch information
Patbox committed Dec 23, 2021
1 parent 5d22121 commit 39927bb
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
modImplementation include("eu.pb4:sgui:1.0.0-rc6+1.18-pre5")
modImplementation include("eu.pb4:hologram-api:0.2.1+1.18-pre5")
modImplementation include("eu.pb4:placeholder-api:1.1.3+1.17.1")
modImplementation include("eu.pb4:polymer:0.2.0-beta.12+1.18.1")
modImplementation include("eu.pb4:polymer:0.2.0-beta.13+1.18.1")
modImplementation include("fr.catcore:server-translations-api:1.4.8+1.18-pre1")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.44.0+1.18

# Mod Properties
mod_version = 2.0.0-beta.1+1.18
mod_version = 2.0.0-beta.2+1.18
maven_group = eu.pb4
archives_base_name = graves

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/eu/pb4/graves/GraveNetworking.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ public static NetworkingGrave readGrave(int version, PacketByteBuf buf) {
}

public static void initialize() {

// A bug in polymer networking api... I will fix that later but for now it will do
ServerPackets.register("custom/" + CLIENT_HELLO.getNamespace() + "/" + CLIENT_HELLO.getPath(), 0);
ServerPackets.register("custom/" + CLIENT_GRAVE.getNamespace() + "/" + CLIENT_GRAVE.getPath(), 0);
PolymerPacketUtils.registerServerPacket(CLIENT_HELLO, 0);
PolymerPacketUtils.registerServerPacket(CLIENT_GRAVE, 0);

PolymerSyncUtils.ON_SYNC_CUSTOM.register(((handler, full) -> {
sendConfig(handler);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/eu/pb4/graves/GravesMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void onInitialize() {
PolymerBlockUtils.registerBlockEntity(VisualGraveBlockEntity.BLOCK_ENTITY_TYPE);

GraveNetworking.initialize();
new GraveGameRules();

GravesApi.registerInventoryMask(new Identifier("vanilla"), VanillaInventoryMask.INSTANCE);

Expand All @@ -69,7 +70,7 @@ public void onInitialize() {
ServerWorldEvents.LOAD.register(((server, world) -> {
if (world == server.getOverworld()) {
GraveManager.INSTANCE = (GraveManager) world.getPersistentStateManager()
.getOrCreate(GraveManager::fromNbt, GraveManager::new, "universal-graves");
.getOrCreate((nbt) -> GraveManager.fromNbt(nbt, server), GraveManager::new, "universal-graves");
}
}));

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/eu/pb4/graves/client/GravesModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
import eu.pb4.graves.registry.GraveBlockEntity;
import eu.pb4.graves.other.GravesLookType;
import eu.pb4.polymer.api.client.PolymerClientUtils;
import fr.catcore.server.translations.api.ServerTranslations;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.model.*;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;

import java.util.function.Consumer;
Expand All @@ -34,8 +39,8 @@ public void onInitializeClient() {
(ctx) -> (BlockEntityRenderer<GraveBlockEntity>) (Object) new GraveRenderer(ctx));


PolymerClientUtils.registerPacket(GraveNetworking.CLIENT_HELLO, this::handleHelloPacket, 0);
PolymerClientUtils.registerPacket(GraveNetworking.CLIENT_GRAVE, this::handleGravePacket, 0);
PolymerClientUtils.registerPacketHandler(GraveNetworking.CLIENT_HELLO, this::handleHelloPacket, 0);
PolymerClientUtils.registerPacketHandler(GraveNetworking.CLIENT_GRAVE, this::handleGravePacket, 0);

ClientPlayConnectionEvents.JOIN.register(this::onConnect);

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public final class Config {

public final Text[] hologramProtectedText;
public final Text[] hologramText;
public final Text[] hologramVisualText;

public final Text[] signProtectedText;
public final Text[] signText;
public final Text[] signVisualText;

public final Text graveTitle;

Expand Down Expand Up @@ -78,8 +80,10 @@ public Config(ConfigData data) {
this.xpCalc = GravesXPCalculation.byName(configData.xpStorageType);
this.hologramProtectedText = parse(data.hologramProtectedText);
this.hologramText = parse(data.hologramText);
this.hologramVisualText = parse(data.hologramVisualText);
this.signProtectedText = parse(data.customStyleSignProtectedText);
this.signText = parse(data.customStyleSignText);
this.signVisualText = parse(data.customStyleSignVisualText);

this.graveTitle = TextParser.parse(data.graveTitle);
this.canClientSide = data.allowClientSideStyle && this.style.allowClient;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/eu/pb4/graves/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class ConfigData extends VersionedConfigData implements Cloneable {

public List<String> customStyleSignProtectedText = getDefaultProtectedSign();

public List<String> customStyleSignVisualText = getDefaultVisualSign();

public int customStyleUpdateRate = 20;

public boolean isProtected = true;
public int protectionTime = 900;
public int breakingTime = 1800;
public boolean keepBlockAfterBreaking = true;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public double hologramOffset = 1.2;
public List<String> hologramProtectedText = getDefaultProtectedHologram();
public List<String> hologramText = getDefaultHologram();
public List<String> hologramVisualText = getDefaultVisualHologram();

public String guiTitle = "<lang:'text.graves.gui_title':'${player}'>";
public List<String> guiProtectedText = getDefaultProtectedGui();
Expand Down Expand Up @@ -108,6 +110,15 @@ private static List<String> getDefaultProtectedHologram() {
return list;
}

private static List<String> getDefaultVisualHologram() {
List<String> list = new ArrayList<>();

list.add("<gold><lang:'text.graves.grave_of':'<white>${player}'>");
list.add("<yellow>${death_cause}");

return list;
}

private static List<String> getDefaultHologram() {
List<String> list = new ArrayList<>();

Expand Down Expand Up @@ -156,6 +167,14 @@ private static List<String> getDefaultProtectedSign() {
return list;
}

private List<String> getDefaultVisualSign() {
List<String> list = new ArrayList<>();

list.add("<white>${player}");

return list;
}

private static List<String> getDefaultSign() {
List<String> list = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public ConfigData update() {
config.graveStyle = this.graveType;
config.presetHeadUnlockedTexture = this.unlockedTexture;
config.presetHeadLockedTexture = this.lockedTexture;
config.isProtected = this.isProtected;
config.protectionTime = this.shouldProtectionExpire ? this.protectionTime : -1;
config.breakingTime = this.shouldBreak ? this.breakAfter : -1;
config.xpStorageType = this.storeExperience ? this.xpStorageType : GravesXPCalculation.DROP.name;
Expand Down
80 changes: 53 additions & 27 deletions src/main/java/eu/pb4/graves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class Grave {
protected Location location;
protected GraveType type;
protected boolean isRemoved;
protected long id = -1;

protected boolean utilProtectionChangeMessage;
protected boolean isProtectionEnabled;
Expand All @@ -67,7 +68,7 @@ public Grave() {
this.visualData = VisualGraveData.DEFAULT;
}

public Grave(GameProfile profile, BlockPos position, Identifier world, GraveType type, long creationTime, long gameCreationTime, int xp, Text deathCause, Collection<UUID> allowedUUIDs, Collection<PositionedItemStack> itemStacks, boolean isProtectionEnabled) {
public Grave(long id, GameProfile profile, BlockPos position, Identifier world, GraveType type, long creationTime, long gameCreationTime, int xp, Text deathCause, Collection<UUID> allowedUUIDs, Collection<PositionedItemStack> itemStacks, boolean isProtectionEnabled) {
this.gameProfile = profile;
this.creationTime = creationTime;
this.gameCreationTime = gameCreationTime;
Expand All @@ -79,17 +80,19 @@ public Grave(GameProfile profile, BlockPos position, Identifier world, GraveType
this.items = DefaultedList.copyOf(PositionedItemStack.EMPTY, itemStacks.toArray(new PositionedItemStack[0]));
this.utilProtectionChangeMessage = !this.isProtected();
this.isProtectionEnabled = isProtectionEnabled;
this.id = id;
this.updateDisplay();
}

public static final Grave createBlock(GameProfile profile, Identifier world, BlockPos position, int xp, Text deathCause, Collection<UUID> allowedUUIDs, Collection<PositionedItemStack> itemStacks) {
return new Grave(profile, position, world, GraveType.BLOCK, System.currentTimeMillis() / 1000, GraveManager.INSTANCE.getCurrentGameTime(), xp, deathCause, allowedUUIDs, itemStacks, true);
return new Grave(GraveManager.INSTANCE.requestId(),profile, position, world, GraveType.BLOCK, System.currentTimeMillis() / 1000, GraveManager.INSTANCE.getCurrentGameTime(), xp, deathCause, allowedUUIDs, itemStacks, true);
}

public NbtCompound writeNbt(NbtCompound nbt) {
if (this.gameProfile != null) {
nbt.put("GameProfile", NbtHelper.writeGameProfile(new NbtCompound(), this.gameProfile));
}
nbt.putLong("Id", this.id);
nbt.putInt("XP", this.xp);
nbt.putLong("CreationTime", this.creationTime);
nbt.putInt("ItemCount", this.itemCount);
Expand All @@ -116,6 +119,12 @@ public NbtCompound writeNbt(NbtCompound nbt) {

public void readNbt(NbtCompound nbt) {
try {
if (nbt.contains("Id", NbtElement.LONG_TYPE)) {
this.id = nbt.getLong("Id");
} else {
this.id = GraveManager.INSTANCE.requestId();
}

this.gameProfile = NbtHelper.toGameProfile(nbt.getCompound("GameProfile"));
this.xp = nbt.getInt("XP");
this.creationTime = nbt.getLong("CreationTime");
Expand Down Expand Up @@ -161,13 +170,13 @@ public VisualGraveData toVisualGraveData() {
public Map<String, Text> getPlaceholders(MinecraftServer server) {
Config config = ConfigManager.getConfig();

long protectionTime = config.configData.protectionTime > -1 ? getTimeLeft(config.configData.protectionTime, config.configData.useRealTime) : Long.MAX_VALUE;
long breakTime = config.configData.breakingTime > -1 ? getTimeLeft(config.configData.breakingTime, config.configData.useRealTime) : Long.MAX_VALUE;
long protectionTime = GraveManager.INSTANCE.getProtectionTime() > -1 ? getTimeLeft(GraveManager.INSTANCE.getProtectionTime(), config.configData.useRealTime) : Long.MAX_VALUE;
long breakTime = GraveManager.INSTANCE.getBreakingTime() > -1 ? getTimeLeft(GraveManager.INSTANCE.getBreakingTime(), config.configData.useRealTime) : Long.MAX_VALUE;

Map<String, Text> values = new HashMap<>();
values.put("player", new LiteralText(this.gameProfile != null ? this.gameProfile.getName() : "<No player!>"));
values.put("protection_time", new LiteralText("" + (config.configData.protectionTime > -1 ? config.getFormattedTime(protectionTime) : config.configData.infinityText)));
values.put("break_time", new LiteralText("" + (config.configData.breakingTime > -1 ? config.getFormattedTime(breakTime) : config.configData.infinityText)));
values.put("protection_time", new LiteralText("" + (GraveManager.INSTANCE.getProtectionTime() > -1 ? config.getFormattedTime(protectionTime) : config.configData.infinityText)));
values.put("break_time", new LiteralText("" + (GraveManager.INSTANCE.getBreakingTime() > -1 ? config.getFormattedTime(breakTime) : config.configData.infinityText)));
values.put("xp", new LiteralText("" + this.xp));
values.put("item_count", new LiteralText("" + this.itemCount));
values.put("position", new LiteralText("" + this.location.blockPos().toShortString()));
Expand All @@ -177,10 +186,10 @@ public Map<String, Text> getPlaceholders(MinecraftServer server) {
}

public boolean shouldNaturallyBreak() {
Config config = ConfigManager.getConfig();
var time = GraveManager.INSTANCE.getBreakingTime();

if (config.configData.breakingTime > -1) {
long breakTime = getTimeLeft(config.configData.breakingTime, config.configData.useRealTime);
if (time > -1) {
long breakTime = getTimeLeft(time, ConfigManager.getConfig().configData.useRealTime);

return breakTime <= 0;
} else {
Expand All @@ -193,14 +202,14 @@ public boolean isProtected() {
}

public boolean isTimeProtected() {
Config config = ConfigManager.getConfig();
var time = GraveManager.INSTANCE.getProtectionTime();

if (config.configData.protectionTime > -1 && config.configData.isProtected) {
long protectionTime = getTimeLeft(config.configData.protectionTime, config.configData.useRealTime);
if (time > -1 && GraveManager.INSTANCE.isProtectionEnabled()) {
long protectionTime = getTimeLeft(time, ConfigManager.getConfig().configData.useRealTime);

return protectionTime > 0;
} else {
return config.configData.isProtected;
return GraveManager.INSTANCE.isProtectionEnabled();
}
}

Expand Down Expand Up @@ -242,6 +251,14 @@ public Location getLocation() {
return this.location;
}

public void setLocation(Identifier identifier, BlockPos pos) {
setLocation(new Location(identifier, pos));
}

public void setLocation(Location location) {
this.location = location;
}

public List<PositionedItemStack> getItems() {
return this.items;
}
Expand Down Expand Up @@ -374,22 +391,27 @@ public boolean isEmpty() {
}

public void quickEquip(ServerPlayerEntity player) {
if (this.canTakeFrom(player)) {
for (var item : this.items) {
if (!item.isEmpty() && item.inventoryMask() != null) {
item.inventoryMask().moveToPlayerExactly(player, item.stack(), item.slot(), item.optionalData());
try {

if (this.canTakeFrom(player)) {
for (var item : this.items) {
if (!item.isEmpty() && item.inventoryMask() != null) {
item.inventoryMask().moveToPlayerExactly(player, item.stack(), item.slot(), item.optionalData());
}
}
}
for (var item : this.items) {
if (!item.isEmpty()) {
if (item.inventoryMask() != null) {
item.inventoryMask().moveToPlayerClosest(player, item.stack(), item.slot(), item.optionalData());
} else {
VanillaInventoryMask.INSTANCE.moveToPlayerClosest(player, item.stack(), -1, null);
for (var item : this.items) {
if (!item.isEmpty()) {
if (item.inventoryMask() != null) {
item.inventoryMask().moveToPlayerClosest(player, item.stack(), item.slot(), item.optionalData());
} else {
VanillaInventoryMask.INSTANCE.moveToPlayerClosest(player, item.stack(), -1, null);
}
}
}
this.updateSelf(player.getServer());
}
this.updateSelf(player.getServer());
} catch (Exception e) {
e.printStackTrace();
}
}

Expand All @@ -406,11 +428,15 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Grave graveInfo = (Grave) o;
return Objects.equals(this.location, graveInfo.location);
return Objects.equals(this.id, graveInfo.id);
}

@Override
public int hashCode() {
return this.location.hashCode();
return Objects.hashCode(this.id);
}

public long getId() {
return this.id;
}
}
Loading

0 comments on commit 39927bb

Please sign in to comment.