Skip to content

Commit

Permalink
[1.2.0] Update to 1.18
Browse files Browse the repository at this point in the history
- Ported to 1.18
- You can disable creation of graves in void or in case of death from /kill command,
- You can now add your own enchantments that will get skipped from adding to grave,
- You can disable default compatibility with soulbound enchantment,
- You can now allow attackers to take items from graves (disabled by default),
- Added option for replacing any block with grave (instead of only air/fluids)
- Changed some default config values,
- Graves will be waterlogged now if visual block supports it
  • Loading branch information
Patbox committed Nov 28, 2021
1 parent 788a57c commit c68da49
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 173 deletions.
19 changes: 9 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.9-SNAPSHOT'
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -39,7 +39,6 @@ repositories {
name 'Gegy'
url 'https://maven.gegy.dev'
}

}

dependencies {
Expand All @@ -52,11 +51,11 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


modImplementation include("eu.pb4:sgui:1.0.0-rc5+1.17.1")
modImplementation include("eu.pb4:hologram-api:0.2.1+1.17.1")
modImplementation include("eu.pb4:placeholder-api:1.1.2+1.17.1")
modImplementation include("eu.pb4:polymer:0.1.8+1.17.1")
modImplementation include("fr.catcore:server-translations-api:1.4.8+1.17")
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.4+1.18-rc3")
modImplementation include("fr.catcore:server-translations-api:1.4.8+1.18-pre1")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

modCompileOnly "dev.emi:trinkets:3.0.4"
Expand Down Expand Up @@ -87,7 +86,7 @@ tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 16
it.options.release = 17
}

java {
Expand Down
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.59
loader_version=0.11.6
minecraft_version=1.18-rc3
yarn_mappings=1.18-rc3+build.1
loader_version=0.12.5

#Fabric api
fabric_version=0.43.1+1.18

# Mod Properties
mod_version = 1.1.4+1.17.1
mod_version = 1.2.0+1.18
maven_group = eu.pb4
archives_base_name = graves

# Dependencies
fabric_version=0.40.1+1.17
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 7 additions & 6 deletions src/main/java/eu/pb4/graves/GravesMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
import eu.pb4.graves.grave.GraveBlockEntity;
import eu.pb4.graves.grave.GraveManager;
import eu.pb4.graves.other.Commands;
import eu.pb4.polymer.PolymerMod;
import eu.pb4.polymer.block.BlockHelper;
import eu.pb4.polymer.api.block.PolymerBlockUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.WorldEvents;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class GravesMod implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("Universal Graves");
public static String VERSION = FabricLoader.getInstance().getModContainer("universal-graves").get().getMetadata().getVersion().getFriendlyString();

public static final List<Runnable> DO_ON_NEXT_TICK = new ArrayList<>();

private static boolean runRunners(Runnable c) {
c.run();
return true;
}

@Override
public void onInitialize() {
this.crabboardDetection();
Expand All @@ -40,7 +41,7 @@ public void onInitialize() {
Registry.register(Registry.BLOCK, new Identifier("universal_graves", "grave"), GraveBlock.INSTANCE);
GraveBlockEntity.BLOCK_ENTITY_TYPE = Registry.register(Registry.BLOCK_ENTITY_TYPE, "universal_graves:grave", FabricBlockEntityTypeBuilder.create(GraveBlockEntity::new, GraveBlock.INSTANCE).build(null));
Commands.register();
BlockHelper.registerVirtualBlockEntity(GraveBlockEntity.BLOCK_ENTITY_TYPE);
PolymerBlockUtils.registerBlockEntity(GraveBlockEntity.BLOCK_ENTITY_TYPE);

if (loader.isModLoaded("trinkets")) {
TrinketsCompat.register();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/graves/compat/InventorioCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void register() {
var stack = inv.getStack(i);
if (!stack.isEmpty()
&& PlayerGraveItemAddedEvent.EVENT.invoker().canAddItem(player, stack) != ActionResult.FAIL
&& !GraveUtils.hasSoulboundEnchantment(stack)
&& !GraveUtils.hasSkippedEnchantment(stack)
&& !EnchantmentHelper.hasVanishingCurse(stack)
) {
items.add(inv.removeStack(i));
Expand Down
100 changes: 52 additions & 48 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.command.argument.ItemStringReader;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -54,9 +56,11 @@ public final class Config {
@Nullable
public final Text creationFailedGraveMessage;
@Nullable
public final Text creationFailedPvPGraveMessage;
public final Text creationFailedVoidMessage;
@Nullable
public final Text creationFailedClaimGraveMessage;
public final Text creationFailedPvPMessage;
@Nullable
public final Text creationFailedClaimMessage;
public final GravesXPCalculation xpCalc;

public final BlockStyleEntry[] customBlockStateStylesLocked;
Expand All @@ -78,13 +82,14 @@ public Config(ConfigData data) {
this.guiProtectedText = parse(data.guiProtectedText);
this.guiText = parse(data.guiText);

this.noLongerProtectedMessage = !data.messageProtectionEnded.isEmpty() ? TextParser.parse(data.messageProtectionEnded) : null;
this.graveExpiredMessage = !data.messageGraveExpired.isEmpty() ? TextParser.parse(data.messageGraveExpired) : null;
this.graveBrokenMessage = !data.messageGraveBroken.isEmpty() ? TextParser.parse(data.messageGraveBroken) : null;
this.createdGraveMessage = !data.messageGraveCreated.isEmpty() ? TextParser.parse(data.messageGraveCreated) : null;
this.creationFailedGraveMessage = !data.messageCreationFailed.isEmpty() ? TextParser.parse(data.messageCreationFailed) : null;
this.creationFailedPvPGraveMessage = !data.messageCreationFailedPvP.isEmpty() ? TextParser.parse(data.messageCreationFailedPvP) : null;
this.creationFailedClaimGraveMessage = !data.messageCreationFailedClaim.isEmpty() ? TextParser.parse(data.messageCreationFailedClaim) : null;
this.noLongerProtectedMessage = parse(data.messageProtectionEnded);
this.graveExpiredMessage = parse(data.messageGraveExpired);
this.graveBrokenMessage = parse(data.messageGraveBroken);
this.createdGraveMessage = parse(data.messageGraveCreated);
this.creationFailedGraveMessage = parse(data.messageCreationFailed);
this.creationFailedVoidMessage = parse(data.messageCreationFailedVoid);
this.creationFailedPvPMessage = parse(data.messageCreationFailedPvP);
this.creationFailedClaimMessage = parse(data.messageCreationFailedClaim);

this.customBlockStateStylesLocked = parseBlockStyles(this.configData.customBlockStateLockedStyles);
this.customBlockStateStylesUnlocked = parseBlockStyles(this.configData.customBlockStateUnlockedStyles);
Expand All @@ -93,7 +98,12 @@ public Config(ConfigData data) {
this.guiItem = parseItems(this.configData.guiItem);
}

public static ItemStack[] parseItems(List<String> stringList) {
@Nullable
private static Text parse(String string) {
return !string.isEmpty() ? TextParser.parse(string) : null;
}

private static ItemStack[] parseItems(List<String> stringList) {
var items = new ArrayList<ItemStack>();

for (var itemDef : stringList) {
Expand All @@ -116,7 +126,7 @@ public static ItemStack[] parseItems(List<String> stringList) {
return items.toArray(new ItemStack[0]);
}

public static BlockStyleEntry[] parseBlockStyles(List<String> stringList) {
private static BlockStyleEntry[] parseBlockStyles(List<String> stringList) {
var blockStates = new ArrayList<BlockStyleEntry>();

for (String stateName : stringList) {
Expand All @@ -125,11 +135,11 @@ public static BlockStyleEntry[] parseBlockStyles(List<String> stringList) {
if (stateData.getBlockState().getBlock() != GraveBlock.INSTANCE && stateData.getBlockState() != null) {
if (stateData.getBlockState().hasBlockEntity()) {
var blockEntity = ((BlockEntityProvider) stateData.getBlockState().getBlock()).createBlockEntity(BlockPos.ORIGIN, stateData.getBlockState());
int i = -1;
BlockEntityType<?> i = null;

var packet = blockEntity.toUpdatePacket();
if (packet != null) {
i = packet.getBlockEntityType();
if (packet instanceof BlockEntityUpdateS2CPacket bePacket) {
i = bePacket.getBlockEntityType();
}

if (stateData.getNbtData() != null) {
Expand All @@ -138,60 +148,53 @@ public static BlockStyleEntry[] parseBlockStyles(List<String> stringList) {

blockStates.add(new BlockStyleEntry(stateData.getBlockState(), i, blockEntity.toInitialChunkDataNbt()));
} else {
blockStates.add(new BlockStyleEntry(stateData.getBlockState(), -1, null));
blockStates.add(new BlockStyleEntry(stateData.getBlockState(), null, null));
}
} else {
blockStates.add(new BlockStyleEntry(Blocks.POTATOES.getDefaultState().with(CropBlock.AGE, 7), -1, null));
blockStates.add(new BlockStyleEntry(Blocks.POTATOES.getDefaultState().with(CropBlock.AGE, 7), null, null));
}
} catch (Exception e) {
e.printStackTrace();
blockStates.add(new BlockStyleEntry(Blocks.SKELETON_SKULL.getDefaultState(), -1, null));
blockStates.add(new BlockStyleEntry(Blocks.SKELETON_SKULL.getDefaultState(), null, null));
}
}

if (blockStates.size() == 0) {
blockStates.add(new BlockStyleEntry(Blocks.SKELETON_SKULL.getDefaultState(), -1, null));
blockStates.add(new BlockStyleEntry(Blocks.SKELETON_SKULL.getDefaultState(), null, null));
}

return blockStates.toArray(new BlockStyleEntry[0]);
}


public String getFormattedTime(long time) {
if (time != Long.MAX_VALUE) {
long seconds = time % 60;
long minutes = (time / 60) % 60;
long hours = (time / (60 * 60)) % 24;
long days = time / (60 * 60 * 24) % 365;
long years = time / (60 * 60 * 24 * 365);

long seconds = time % 60;
long minutes = (time / 60) % 60;
long hours = (time / (60 * 60)) % 24;
long days = time / (60 * 60 * 24) % 365;
long years = time / (60 * 60 * 24 * 365);
StringBuilder builder = new StringBuilder();

StringBuilder builder = new StringBuilder();

if (years > 0) {
builder.append(years).append(configData.yearsText);
}
if (days > 0) {
builder.append(days).append(configData.daysText);
}
if (hours > 0) {
builder.append(hours).append(configData.hoursText);
}
if (minutes > 0) {
builder.append(minutes).append(configData.minutesText);
}
if (seconds >= 0) {
builder.append(seconds).append(configData.secondsText);
} else {
builder.append(time).append(configData.secondsText);
}
return builder.toString();
} else {
return configData.neverExpires;
if (years > 0) {
builder.append(years).append(configData.yearsText);
}
if (days > 0) {
builder.append(days).append(configData.daysText);
}
if (hours > 0) {
builder.append(hours).append(configData.hoursText);
}
if (minutes > 0) {
builder.append(minutes).append(configData.minutesText);
}
if (seconds > 0 || time <= 0) {
builder.append(seconds).append(configData.secondsText);
}
return builder.toString();
}

public static Text[] parse(List<String> strings) {
private static Text[] parse(List<String> strings) {
List<Text> texts = new ArrayList<>();

for (String line : strings) {
Expand All @@ -204,7 +207,8 @@ public static Text[] parse(List<String> strings) {
return texts.toArray(new Text[0]);
}

public static record BlockStyleEntry(BlockState state, int blockEntityId, NbtCompound blockEntityNbt) {
public static record BlockStyleEntry(BlockState state, BlockEntityType<?> blockEntityType,
NbtCompound blockEntityNbt) {
}

}
23 changes: 17 additions & 6 deletions src/main/java/eu/pb4/graves/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import eu.pb4.graves.grave.GravesLookType;
import eu.pb4.graves.grave.GravesXPCalculation;
import eu.pb4.graves.other.GraveUtils;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.WallBlock;
import net.minecraft.block.enums.WallShape;
import net.minecraft.tag.Tag;

import java.util.*;

Expand All @@ -32,18 +34,24 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public int customStyleUpdateRate = 20;

public boolean isProtected = true;
public int protectionTime = 300;
public int breakingTime = 900;
public int protectionTime = 900;
public int breakingTime = 1800;
public boolean breakEmptyGraves = true;

public String xpStorageType = GravesXPCalculation.VANILLA.name;
public String xpStorageType = GravesXPCalculation.PERCENT_POINTS.name;
public double xpPercentTypeValue = 100;

public boolean replaceAnyBlock = false;
//public boolean useRealTime = true;

public boolean createFromPvP = true;
public boolean createFromVoid = true;
public boolean createFromCommandDeaths = true;
public boolean createInClaims = true;
public boolean dropItemsAfterExpiring = true;

public boolean shiftClickTakesItems = true;
public boolean allowAttackersToTakeItems = false;

public String graveTitle = "<lang:'text.graves.players_grave':'${player}'>";

Expand All @@ -59,24 +67,27 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public List<String> guiProtectedItem = Collections.singletonList("chest");
public List<String> guiItem = Collections.singletonList("trapped_chest");

public String messageGraveCreated = "<white><lang:'text.graves.created_at':'<yellow>${position}':'<gray>${world}'>";
public String messageGraveCreated = "<white><lang:'text.graves.created_at_expire':'<yellow>${position}':'<gray>${world}':'<red>${break_time}'>";
public String messageProtectionEnded = "<red><lang:'text.graves.no_longer_protected':'<gold>${position}':'<white>${world}':'<yellow>${item_count}'>";
public String messageGraveExpired = "<red><lang:'text.graves.expired':'<gold>${position}':'<white>${world}':'<yellow>${item_count}'>";
public String messageGraveBroken = "<gray><lang:'text.graves.somebody_broke':'<white>${position}':'<white>${world}':'<white>${item_count}'>";
public String messageCreationFailed = "<red><lang:'text.graves.creation_failed':'<gold>${position}':'<yellow>${world}'>";
public String messageCreationFailedVoid = "<red><lang:'text.graves.creation_failed_void':'<gold>${position}':'<yellow>${world}'>";
public String messageCreationFailedPvP = "<red><lang:'text.graves.creation_failed_pvp':'<gold>${position}':'<yellow>${world}'>";
public String messageCreationFailedClaim = "<red><lang:'text.graves.creation_failed_claim':'<gold>${position}':'<yellow>${world}'>";

public String neverExpires = "Never";

public String yearsText = "y";
public String daysText = "d";
public String hoursText = "h";
public String minutesText = "m";
public String secondsText = "s";

public String infinityText = "∞";

public Map<String, String> worldNameOverrides = new HashMap<>();

public boolean tryDetectionSoulbound = true;
public List<String> skippedEnchantments = new ArrayList<>();


private static List<String> getDefaultProtectedHologram() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public ConfigData update() {
config.messageCreationFailed = this.displayCreationFailedGraveMessage ? this.creationFailedGraveMessage : "";
config.messageCreationFailedPvP = this.displayCreationFailedPvPGraveMessage ? this.creationFailedPvPGraveMessage : "";
config.messageCreationFailedClaim = this.displayCreationFailedClaimGraveMessage ? this.creationFailedClaimMessage : "";
config.neverExpires = this.neverExpires;
config.yearsText = this.yearsText;
config.daysText = this.daysText;
config.hoursText = this.hoursText;
Expand Down
Loading

0 comments on commit c68da49

Please sign in to comment.