Update to 1.20.1

This commit is contained in:
zontreck 2023-11-19 02:10:20 -07:00
parent 0066b86d18
commit f3b1ccbd3a
20 changed files with 200 additions and 166 deletions

View file

@ -1,13 +1,21 @@
plugins { plugins {
id 'eclipse' id 'eclipse'
id 'maven-publish' id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1.+' id 'java-library'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+' id 'org.parchmentmc.librarian.forgegradle' version '1.+'
} }
version = "${mc_version}-${myversion}" version = "${mc_version}-${mod_version}"
group = 'dev.zontreck' // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = mod_group_id
archivesBaseName = 'libzontreck'
base {
archivesName = mod_id
}
java {
withSourcesJar()
}
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.toolchain.languageVersion = JavaLanguageVersion.of(17)
@ -35,6 +43,8 @@ minecraft {
mappings channel: 'parchment', version: "${parchment_version}-${mc_version}" mappings channel: 'parchment', version: "${parchment_version}-${mc_version}"
// mappings channel: 'official', version: "${mc_version}" // mappings channel: 'official', version: "${mc_version}"
copyIdeResources = true
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default. // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
@ -152,69 +162,63 @@ dependencies {
implementation "dev.zontreck:LibAC:${libac}" implementation "dev.zontreck:LibAC:${libac}"
minecraftLibrary "dev.zontreck:LibAC:${libac}" minecraftLibrary "dev.zontreck:LibAC:${libac}"
provided "dev.zontreck:EventsBus:${eventsbus}"
implementation "dev.zontreck:EventsBus:${eventsbus}"
minecraftLibrary "dev.zontreck:EventsBus:${eventsbus}"
// For more info... // For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html // http://www.gradle.org/docs/current/userguide/dependency_management.html
} }
// Example for how to get properties into the manifest for reading at runtime. tasks.named('processResources', ProcessResources).configure {
jar { var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
forge_version: forge_version, forge_version_range: forge_version_range,
loader_version_range: loader_version_range,
mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors: mod_authors, mod_description: mod_description,
]
inputs.properties replaceProperties
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}
}
tasks.named('jar', Jar).configure {
from { from {
configurations.provided.asFileTree.collect{zipTree(it)} configurations.provided.asFileTree.collect{zipTree(it)}
} }
manifest { manifest {
attributes([ attributes([
"Specification-Title" : project.name, "Specification-Title" : mod_id,
"Specification-Vendor" : "zontreck", "Specification-Vendor" : mod_authors,
"Specification-Version": "${myversion}", "Specification-Version": "${mod_version}",
"Implementation-Title": project.name, "Implementation-Title": project.name,
"Implementation-Version": "${myversion}", "Implementation-Version": "${mod_version}",
"Implementation-Vendor" : "zontreck", "Implementation-Vendor" : mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
]) ])
} }
finalizedBy 'reobfJar'
} }
compileJava.finalizedBy('devJar') compileJava.finalizedBy('sourcesJar')
// Example configuration to allow publishing using the maven-publish plugin
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing // However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
// publish.dependsOn('reobfJar') // publish.dependsOn('reobfJar')
task devJar(type: Jar) {
from sourceSets.main.output
from sourceSets.main.allJava
classifier = 'dev'
from {
configurations.provided.asFileTree.collect{zipTree(it)}
}
manifest {
attributes([
"Specification-Title": project.name,
"Specification-Vendor": "zontreck",
"Specification-Version": "${myversion}",
"Implementation-Title": project.name,
"Implementation-Version": "${myversion}",
"Implementation-Vendor": "zontreck",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
devJar.finalizedBy('reobfJar')
def MAVEN_PASSWORD_PROPERTY = "AriasCreationsMavenPassword" def MAVEN_PASSWORD_PROPERTY = "AriasCreationsMavenPassword"
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
artifact jar artifact jar
artifact devJar artifact sourcesJar
} }
} }
repositories { repositories {
@ -236,5 +240,5 @@ tasks.withType(JavaCompile).configureEach {
} }
artifacts { artifacts {
archives devJar archives sourcesJar
} }

View file

@ -3,10 +3,44 @@
org.gradle.jvmargs=-Xmx3G org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false org.gradle.daemon=false
mc_version=1.19.3 mc_version=1.20.1
forge_version=44.1.0 forge_version=47.2.0
myversion=1.0.7.0515232132 parchment_version=2023.09.03
parchment_version=2023.03.12
# luckperms_api_version=5.4 # luckperms_api_version=5.4
libac=1.3.61 libac=1.4.1
eventsbus=1.0.16
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[47,)
minecraft_range=[1.20.1,1.21]
# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge.
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.1
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=libzontreck
# The human-readable display name for the mod.
mod_name=Zontreck's Library Mod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=1.0.8.1119230115
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=dev.zontreck
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=Zontreck
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=This is a library mod. It contains code used commonly in all or most Zontreck Projects

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -7,4 +7,7 @@ pluginManagement {
} }
} }
rootProject.name = "libzontreck"
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}

View file

@ -8,7 +8,8 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import dev.zontreck.ariaslib.events.EventBus; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.eventsbus.Bus;
import dev.zontreck.libzontreck.currency.Bank; import dev.zontreck.libzontreck.currency.Bank;
import dev.zontreck.libzontreck.currency.CurrencyHelper; import dev.zontreck.libzontreck.currency.CurrencyHelper;
import dev.zontreck.libzontreck.networking.NetworkEvents; import dev.zontreck.libzontreck.networking.NetworkEvents;
@ -16,7 +17,6 @@ import org.slf4j.Logger;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.libzontreck.commands.Commands; import dev.zontreck.libzontreck.commands.Commands;
import dev.zontreck.libzontreck.events.ForgeEventHandlers; import dev.zontreck.libzontreck.events.ForgeEventHandlers;
import dev.zontreck.libzontreck.memory.VolatilePlayerStorage; import dev.zontreck.libzontreck.memory.VolatilePlayerStorage;
@ -80,8 +80,10 @@ public class LibZontreck {
MinecraftForge.EVENT_BUS.register(new ForgeEventHandlers()); MinecraftForge.EVENT_BUS.register(new ForgeEventHandlers());
MinecraftForge.EVENT_BUS.register(new Commands()); MinecraftForge.EVENT_BUS.register(new Commands());
MinecraftForge.EVENT_BUS.register(new NetworkEvents()); MinecraftForge.EVENT_BUS.register(new NetworkEvents());
EventBus.BUS.register(CurrencyHelper.class);
EventBus.BUS.register(Bank.class);
Bus.Register(CurrencyHelper.class, null);
Bus.Register(Bank.class, null);
} }
private void setup(final FMLCommonSetupEvent event) private void setup(final FMLCommonSetupEvent event)

View file

@ -1,6 +1,7 @@
package dev.zontreck.libzontreck.currency; package dev.zontreck.libzontreck.currency;
import dev.zontreck.ariaslib.events.EventBus;
import dev.zontreck.eventsbus.Bus;
import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.currency.events.TransactionHistoryFlushEvent; import dev.zontreck.libzontreck.currency.events.TransactionHistoryFlushEvent;
import dev.zontreck.libzontreck.profiles.Profile; import dev.zontreck.libzontreck.profiles.Profile;
@ -11,6 +12,7 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -88,12 +90,17 @@ public class Account
* When the TX history grows beyond 20, the history should clear and it should get transferred to the long-term tx history storage. That file is not retained in memory, and only gets loaded when clearing to merge the lists. It is immediately saved and unloaded * When the TX history grows beyond 20, the history should clear and it should get transferred to the long-term tx history storage. That file is not retained in memory, and only gets loaded when clearing to merge the lists. It is immediately saved and unloaded
* @see LongTermTransactionHistoryRecord * @see LongTermTransactionHistoryRecord
*/ */
public void flushTxHistory() public void flushTxHistory() {
{
LongTermTransactionHistoryRecord rec = LongTermTransactionHistoryRecord.of(player_id); LongTermTransactionHistoryRecord rec = LongTermTransactionHistoryRecord.of(player_id);
rec.addHistory(history); rec.addHistory(history);
rec.commit(); rec.commit();
EventBus.BUS.post(new TransactionHistoryFlushEvent(this, rec, history)); try {
Bus.Post(new TransactionHistoryFlushEvent(this, rec, history));
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
rec = null; rec = null;
history = new ArrayList<>(); history = new ArrayList<>();
} }

View file

@ -1,9 +1,8 @@
package dev.zontreck.libzontreck.currency; package dev.zontreck.libzontreck.currency;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.zontreck.ariaslib.events.Event; import dev.zontreck.eventsbus.Bus;
import dev.zontreck.ariaslib.events.EventBus; import dev.zontreck.eventsbus.Subscribe;
import dev.zontreck.ariaslib.events.annotations.Subscribe;
import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColorFactory; import dev.zontreck.libzontreck.chat.ChatColorFactory;
@ -25,6 +24,7 @@ import net.minecraft.nbt.Tag;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -81,11 +81,15 @@ public class Bank
accounts.add(new Account((CompoundTag) t)); accounts.add(new Account((CompoundTag) t));
} }
EventBus.BUS.post(new BankReadyEvent()); Bus.Post(new BankReadyEvent());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} } catch (InvocationTargetException e) {
} throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
/** /**
* Do not use manually, this saves the bank data to disk. This is fired automatically when transactions are posted to accounts. * Do not use manually, this saves the bank data to disk. This is fired automatically when transactions are posted to accounts.
@ -128,8 +132,15 @@ public class Bank
instance.accounts.add(new Account(ID)); instance.accounts.add(new Account(ID));
instance.commit(); instance.commit();
EventBus.BUS.post(new BankAccountCreatedEvent(getAccount(ID))); try {
}else return; Bus.Post(new BankAccountCreatedEvent(getAccount(ID)));
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}else {
}
} }
/** /**
@ -139,10 +150,10 @@ public class Bank
* @param tx The transaction being attempted * @param tx The transaction being attempted
* @return True if the transaction has been accepted. False if the transaction was rejected, or insufficient funds. * @return True if the transaction has been accepted. False if the transaction was rejected, or insufficient funds.
*/ */
protected static boolean postTx(Transaction tx) throws InvalidSideException { protected static boolean postTx(Transaction tx) throws InvalidSideException, InvocationTargetException, IllegalAccessException {
if(ServerUtilities.isClient())return false; if(ServerUtilities.isClient())return false;
TransactionEvent ev = new TransactionEvent(tx); TransactionEvent ev = new TransactionEvent(tx);
if(EventBus.BUS.post(ev)) if(Bus.Post(ev))
{ {
// Send the list of reasons to the user // Send the list of reasons to the user
String reasonStr = String.join("\n", ev.reasons); String reasonStr = String.join("\n", ev.reasons);
@ -207,8 +218,9 @@ public class Bank
Profile.unload(fromProf); Profile.unload(fromProf);
EventBus.BUS.post(new WalletUpdatedEvent(from.player_id, fromOld, from.balance, tx)); Bus.Post(new WalletUpdatedEvent(from.player_id, fromOld, from.balance, tx));
EventBus.BUS.post(new WalletUpdatedEvent(to.player_id, toOld, to.balance, tx));
Bus.Post(new WalletUpdatedEvent(to.player_id, toOld, to.balance, tx));
if(from.isValidPlayer() && !ServerUtilities.playerIsOffline(from.player_id)) if(from.isValidPlayer() && !ServerUtilities.playerIsOffline(from.player_id))
{ {

View file

@ -1,6 +1,5 @@
package dev.zontreck.libzontreck.currency; package dev.zontreck.libzontreck.currency;
import dev.zontreck.ariaslib.events.annotations.Subscribe;
public class CurrencyHelper { public class CurrencyHelper {

View file

@ -4,6 +4,7 @@ import dev.zontreck.libzontreck.exceptions.InvalidSideException;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.Date; import java.util.Date;
public class Transaction public class Transaction
@ -48,7 +49,7 @@ public class Transaction
public boolean submit(){ public boolean submit(){
try { try {
return Bank.postTx(this); return Bank.postTx(this);
} catch (InvalidSideException e) { } catch (InvalidSideException | InvocationTargetException | IllegalAccessException e) {
return false; return false;
} }
} }

View file

@ -1,7 +1,7 @@
package dev.zontreck.libzontreck.currency.events; package dev.zontreck.libzontreck.currency.events;
import dev.zontreck.ariaslib.events.Event; import dev.zontreck.eventsbus.Event;
import dev.zontreck.libzontreck.currency.Account; import dev.zontreck.libzontreck.currency.Account;
public class BankAccountCreatedEvent extends Event public class BankAccountCreatedEvent extends Event
@ -11,9 +11,4 @@ public class BankAccountCreatedEvent extends Event
{ {
account=act; account=act;
} }
@Override
public boolean isCancellable() {
return false;
}
} }

View file

@ -1,6 +1,7 @@
package dev.zontreck.libzontreck.currency.events; package dev.zontreck.libzontreck.currency.events;
import dev.zontreck.ariaslib.events.Event;
import dev.zontreck.eventsbus.Event;
/** /**
* Contains no information by itself, it only signals that the Bank is open for business * Contains no information by itself, it only signals that the Bank is open for business
@ -10,8 +11,4 @@ import dev.zontreck.ariaslib.events.Event;
public class BankReadyEvent extends Event public class BankReadyEvent extends Event
{ {
@Override
public boolean isCancellable() {
return false;
}
} }

View file

@ -1,10 +1,15 @@
package dev.zontreck.libzontreck.currency.events; package dev.zontreck.libzontreck.currency.events;
import dev.zontreck.ariaslib.events.Event;
import dev.zontreck.eventsbus.Cancellable;
import dev.zontreck.eventsbus.Event;
import dev.zontreck.libzontreck.currency.Transaction; import dev.zontreck.libzontreck.currency.Transaction;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List; import java.util.List;
@Cancellable
public class TransactionEvent extends Event public class TransactionEvent extends Event
{ {
public Transaction tx; public Transaction tx;
@ -18,9 +23,4 @@ public class TransactionEvent extends Event
{ {
tx=txNew; tx=txNew;
} }
@Override
public boolean isCancellable() {
return true;
}
} }

View file

@ -1,6 +1,7 @@
package dev.zontreck.libzontreck.currency.events; package dev.zontreck.libzontreck.currency.events;
import dev.zontreck.ariaslib.events.Event;
import dev.zontreck.eventsbus.Event;
import dev.zontreck.libzontreck.currency.Account; import dev.zontreck.libzontreck.currency.Account;
import dev.zontreck.libzontreck.currency.LongTermTransactionHistoryRecord; import dev.zontreck.libzontreck.currency.LongTermTransactionHistoryRecord;
import dev.zontreck.libzontreck.currency.Transaction; import dev.zontreck.libzontreck.currency.Transaction;
@ -19,9 +20,4 @@ public class TransactionHistoryFlushEvent extends Event
this.txHistory=txHistory; this.txHistory=txHistory;
this.flushed=flushed; this.flushed=flushed;
} }
@Override
public boolean isCancellable() {
return false;
}
} }

View file

@ -1,6 +1,6 @@
package dev.zontreck.libzontreck.currency.events; package dev.zontreck.libzontreck.currency.events;
import dev.zontreck.ariaslib.events.Event; import dev.zontreck.eventsbus.Event;
import dev.zontreck.libzontreck.currency.Transaction; import dev.zontreck.libzontreck.currency.Transaction;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -23,8 +23,4 @@ public class WalletUpdatedEvent extends Event
this.newBal = newBal; this.newBal = newBal;
this.tx=tx; this.tx=tx;
} }
@Override
public boolean isCancellable() {
return false;
}
} }

View file

@ -1,6 +1,5 @@
package dev.zontreck.libzontreck.events; package dev.zontreck.libzontreck.events;
import dev.zontreck.ariaslib.events.EventBus;
import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.LibZontreck;
@ -25,11 +24,10 @@ public class ForgeEventHandlers {
@SubscribeEvent @SubscribeEvent
public void onPlayerTick(LivingEvent.LivingTickEvent ev) public void onPlayerTick(LivingEvent.LivingTickEvent ev)
{ {
if(ev.getEntity().level.isClientSide)return; if(ev.getEntity().level().isClientSide) return;
if(ev.getEntity() instanceof ServerPlayer) if(ev.getEntity() instanceof ServerPlayer player)
{ {
ServerPlayer player = (ServerPlayer)ev.getEntity();
PlayerContainer cont = LibZontreck.playerStorage.get(player.getUUID()); PlayerContainer cont = LibZontreck.playerStorage.get(player.getUUID());
if(cont.player.positionChanged()) if(cont.player.positionChanged())
@ -45,11 +43,11 @@ public class ForgeEventHandlers {
@SubscribeEvent @SubscribeEvent
public void onPlayerJoin(final PlayerEvent.PlayerLoggedInEvent ev) public void onPlayerJoin(final PlayerEvent.PlayerLoggedInEvent ev)
{ {
if(ev.getEntity().level.isClientSide)return; if(ev.getEntity().level().isClientSide)return;
ServerPlayer player = (ServerPlayer)ev.getEntity(); ServerPlayer player = (ServerPlayer)ev.getEntity();
Profile prof = Profile.factory(player); Profile prof = Profile.factory(player);
ServerLevel level = player.getLevel(); ServerLevel level = player.serverLevel();
MinecraftForge.EVENT_BUS.post(new ProfileLoadedEvent(prof, player, level)); MinecraftForge.EVENT_BUS.post(new ProfileLoadedEvent(prof, player, level));
@ -65,7 +63,7 @@ public class ForgeEventHandlers {
@SubscribeEvent @SubscribeEvent
public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev) public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev)
{ {
if(ev.getEntity().level.isClientSide)return; if(ev.getEntity().level().isClientSide)return;
// Get player profile, send disconnect alert, then commit profile and remove it from memory // Get player profile, send disconnect alert, then commit profile and remove it from memory
Profile px=null; Profile px=null;
try { try {

View file

@ -9,7 +9,6 @@ import net.minecraftforge.eventbus.api.Event;
/** /**
* Used to register your packets with LibZontreck. Packets must extend IPacket and implement PacketSerializable. This is dispatched on both logical sides, and is considered a final event. It is not cancelable * Used to register your packets with LibZontreck. Packets must extend IPacket and implement PacketSerializable. This is dispatched on both logical sides, and is considered a final event. It is not cancelable
* @see IPacket * @see IPacket
* @see PacketSerializable
*/ */
public class RegisterPacketsEvent extends Event public class RegisterPacketsEvent extends Event
{ {

View file

@ -2,7 +2,6 @@ package dev.zontreck.libzontreck.exceptions;
/** /**
* Thrown when requesting a world position's level on the client when in the wrong dimension. * Thrown when requesting a world position's level on the client when in the wrong dimension.
* @see WorldPosition
*/ */
public class InvalidSideException extends Exception public class InvalidSideException extends Exception
{ {

View file

@ -1,6 +1,6 @@
package dev.zontreck.libzontreck.networking.packets; package dev.zontreck.libzontreck.networking.packets;
import dev.zontreck.ariaslib.events.EventBus; import dev.zontreck.eventsbus.Bus;
import dev.zontreck.libzontreck.currency.Transaction; import dev.zontreck.libzontreck.currency.Transaction;
import dev.zontreck.libzontreck.currency.events.WalletUpdatedEvent; import dev.zontreck.libzontreck.currency.events.WalletUpdatedEvent;
import dev.zontreck.libzontreck.util.ServerUtilities; import dev.zontreck.libzontreck.util.ServerUtilities;
@ -10,6 +10,7 @@ import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.simple.SimpleChannel;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -62,7 +63,13 @@ public class S2CWalletUpdatedPacket implements IPacket
return ServerUtilities.handlePacket(supplier, new Runnable() { return ServerUtilities.handlePacket(supplier, new Runnable() {
@Override @Override
public void run() { public void run() {
EventBus.BUS.post(new WalletUpdatedEvent(ID, oldBal, balance, tx)); try {
Bus.Post(new WalletUpdatedEvent(ID, oldBal, balance, tx));
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} }
}); });

View file

@ -8,20 +8,18 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
public class WorldPosition public class WorldPosition {
{
public Vector3 Position; public Vector3 Position;
public String Dimension; public String Dimension;
public String DimSafe; public String DimSafe;
public WorldPosition(CompoundTag tag, boolean pretty) throws InvalidDeserialization public WorldPosition(CompoundTag tag, boolean pretty) throws InvalidDeserialization {
{ if (pretty) {
if(pretty){
Position = new Vector3(tag.getString("Position")); Position = new Vector3(tag.getString("Position"));
Dimension = tag.getString("Dimension"); Dimension = tag.getString("Dimension");
}else { } else {
Position = new Vector3(tag.getCompound("pos")); Position = new Vector3(tag.getCompound("pos"));
Dimension = tag.getString("Dimension"); Dimension = tag.getString("Dimension");
} }
@ -30,64 +28,57 @@ public class WorldPosition
} }
public WorldPosition(Vector3 pos, String dim) public WorldPosition(Vector3 pos, String dim) {
{ Position = pos;
Position=pos; Dimension = dim;
Dimension=dim;
calcDimSafe(); calcDimSafe();
} }
public WorldPosition(ServerPlayer player) public WorldPosition(ServerPlayer player) {
{ this(new Vector3(player.position()), player.serverLevel());
this(new Vector3(player.position()), player.getLevel());
} }
public WorldPosition(Vector3 pos, ServerLevel lvl) public WorldPosition(Vector3 pos, ServerLevel lvl) {
{ Position = pos;
Position=pos; Dimension = lvl.dimension().location().getNamespace() + ":" + lvl.dimension().location().getPath();
Dimension = lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath();
calcDimSafe(); calcDimSafe();
} }
public void calcDimSafe() public void calcDimSafe() {
{
ServerLevel lvl = getActualDimension(); ServerLevel lvl = getActualDimension();
DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath(); DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath();
} }
public static String getDimSafe(ServerLevel lvl)
{ public static String getDimSafe(ServerLevel lvl) {
return lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath(); return lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath();
} }
/** /**
* Gives you the dimension string modid:dimension * Gives you the dimension string modid:dimension
*
* @param lvl * @param lvl
* @return dimension string * @return dimension string
*/ */
public static String getDim(ServerLevel lvl) public static String getDim(ServerLevel lvl) {
{
return lvl.dimension().location().getNamespace() + ":" + lvl.dimension().location().getPath(); return lvl.dimension().location().getNamespace() + ":" + lvl.dimension().location().getPath();
} }
@Override @Override
public String toString() public String toString() {
{
return NbtUtils.structureToSnbt(serialize()); return NbtUtils.structureToSnbt(serialize());
} }
public CompoundTag serializePretty() public CompoundTag serializePretty() {
{
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.putString("Position", Position.toString()); tag.putString("Position", Position.toString());
tag.putString("Dimension", Dimension); tag.putString("Dimension", Dimension);
return tag; return tag;
} }
public CompoundTag serialize() public CompoundTag serialize() {
{
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.put("pos", Position.serialize()); tag.put("pos", Position.serialize());
tag.putString("Dimension", Dimension); tag.putString("Dimension", Dimension);
@ -95,46 +86,40 @@ public class WorldPosition
return tag; return tag;
} }
public ServerLevel getActualDimension() public ServerLevel getActualDimension() {
{
String dim = Dimension; String dim = Dimension;
String[] dims = dim.split(":"); String[] dims = dim.split(":");
ResourceLocation rl = new ResourceLocation(dims[0], dims[1]); ResourceLocation rl = new ResourceLocation(dims[0], dims[1]);
ServerLevel dimL = null; ServerLevel dimL = null;
for (ServerLevel lServerLevel : LibZontreck.THE_SERVER.getAllLevels()) { for (ServerLevel lServerLevel : LibZontreck.THE_SERVER.getAllLevels()) {
ResourceLocation XL = lServerLevel.dimension().location(); ResourceLocation XL = lServerLevel.dimension().location();
if(XL.getNamespace().equals(rl.getNamespace())){ if (XL.getNamespace().equals(rl.getNamespace())) {
if(XL.getPath().equals(rl.getPath())){ if (XL.getPath().equals(rl.getPath())) {
dimL = lServerLevel; dimL = lServerLevel;
} }
} }
} }
if(dimL == null) if (dimL == null) {
{ LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : " + Dimension);
LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : "+Dimension);
return null; return null;
} }
return dimL; return dimL;
} }
public boolean same(WorldPosition other) public boolean same(WorldPosition other) {
{ return Position.same(other.Position) && Dimension == other.Dimension;
if(Position.same(other.Position) && Dimension == other.Dimension)return true;
else return false;
} }
public ChunkPos getChunkPos() public ChunkPos getChunkPos() {
{
net.minecraft.world.level.ChunkPos mcChunk = getActualDimension().getChunkAt(Position.asBlockPos()).getPos(); net.minecraft.world.level.ChunkPos mcChunk = getActualDimension().getChunkAt(Position.asBlockPos()).getPos();
ChunkPos pos = new ChunkPos(new Vector3(mcChunk.getMinBlockX(),-70,mcChunk.getMinBlockZ()), new Vector3(mcChunk.getMaxBlockX(), 400, mcChunk.getMaxBlockZ()), getActualDimension()); ChunkPos pos = new ChunkPos(new Vector3(mcChunk.getMinBlockX(), -70, mcChunk.getMinBlockZ()), new Vector3(mcChunk.getMaxBlockX(), 400, mcChunk.getMaxBlockZ()), getActualDimension());
pos.centerPoints = new Vector2(mcChunk.getMiddleBlockX(), mcChunk.getMiddleBlockZ()); pos.centerPoints = new Vector2(mcChunk.getMiddleBlockX(), mcChunk.getMiddleBlockZ());
return pos; return pos;

View file

@ -6,22 +6,22 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version # A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[44,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="GPLv3" license="${mod_license}"
# A URL to refer people to when problems occur with this mod # A URL to refer people to when problems occur with this mod
issueTrackerURL="https://github.com/zontreck/LibZontreckMod/issues" #optional issueTrackerURL="https://github.com/zontreck/LibZontreckMod/issues" #optional
# A list of mods - how many allowed here is determined by the individual mod loader # A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory [[mods]] #mandatory
# The modid of the mod # The modid of the mod
modId="libzontreck" #mandatory modId="${mod_id}" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build # see the associated build.gradle script for how to populate this completely automatically during a build
version="${file.jarVersion}" #mandatory version="${file.jarVersion}" #mandatory
# A display name for the mod # A display name for the mod
displayName="LibZontreck" #mandatory displayName="${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional #updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI # A URL for the "homepage" for this mod, displayed in the mod UI
@ -29,9 +29,9 @@ displayName="LibZontreck" #mandatory
# A file name (in the root of the mod JAR) containing a logo for display # A file name (in the root of the mod JAR) containing a logo for display
logoFile="library.png" #optional logoFile="library.png" #optional
# A text field displayed in the mod UI # A text field displayed in the mod UI
credits="Zontreck" #optional #credits="Zontreck" #optional
# A text field displayed in the mod UI # A text field displayed in the mod UI
authors="Zontreck" #optional authors="#{mod_authors}" #optional
# Display Test controls the display for your mod in the server connection screen # Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
@ -52,7 +52,7 @@ This mod provides common code to all of zontreck's mods.
# Does this dependency have to exist - if not, ordering below must be specified # Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory mandatory=true #mandatory
# The version range of the dependency # The version range of the dependency
versionRange="[44,)" #mandatory versionRange="${loader_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE" ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER # Side this dependency is applied on - BOTH, CLIENT or SERVER
@ -62,6 +62,6 @@ This mod provides common code to all of zontreck's mods.
modId="minecraft" modId="minecraft"
mandatory=true mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version # This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.19.3,1.20)" versionRange="${minecraft_range}"
ordering="NONE" ordering="NONE"
side="BOTH" side="BOTH"