rain accumulation check command

This commit is contained in:
2024-09-12 23:27:11 +03:00
parent aa4dd64700
commit 03c8a8f7fe
3 changed files with 49 additions and 16 deletions

View File

@@ -7,6 +7,10 @@ buildscript {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
} }
} }
plugins {
id "com.diffplug.spotless" version "6.11.0"
}
apply plugin: 'net.minecraftforge.gradle' apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse' apply plugin: 'eclipse'
@@ -156,9 +160,20 @@ jar {
} }
} }
spotless {
ratchetFrom 'origin/master'
java {
importOrder()
removeUnusedImports()
palantirJavaFormat()
}
}
// Example configuration to allow publishing using the maven-publish task // Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file // This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar') jar.finalizedBy('reobfJar')
assemble.finalizedBy('spotlessJavaApply')
// 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')

View File

@@ -1,5 +1,7 @@
package stargazer.timelord.commands; package stargazer.timelord.commands;
import static stargazer.timelord.Timelord.getDimensionsConfigMap;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
@@ -10,30 +12,45 @@ import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.PacketDistributor;
import stargazer.timelord.Timelord; import stargazer.timelord.Timelord;
import stargazer.timelord.config.Configuration; import stargazer.timelord.config.Configuration;
import stargazer.timelord.logic.TimelordWorldData;
import stargazer.timelord.net.TimePacket; import stargazer.timelord.net.TimePacket;
import static stargazer.timelord.Timelord.getDimensionsConfigMap;
public class TimelordCommands { public class TimelordCommands {
public TimelordCommands(CommandDispatcher<CommandSource> dispatcher) { public TimelordCommands(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(Commands.literal("timelord").then(Commands.literal("reload").requires(s -> s.hasPermissionLevel(4)).executes((command) -> { dispatcher.register(Commands.literal("timelord")
return reload(command.getSource()); .then(Commands.literal("reload")
}))); .requires(s -> s.hasPermissionLevel(4))
.executes((command) -> reload(command.getSource())))
.then(Commands.literal("rain")
.requires(s -> s.hasPermissionLevel(4))
.executes((command) -> getRainAcc(command.getSource()))));
} }
private int reload(CommandSource source) throws CommandSyntaxException { private int reload(CommandSource source) throws CommandSyntaxException {
ServerWorld sw = source.getWorld(); ServerWorld sw = source.getWorld();
for (ServerWorld world : sw.getServer().getWorlds()) { for (ServerWorld world : sw.getServer().getWorlds()) {
ResourceLocation rl = world.getDimensionKey().getLocation(); ResourceLocation rl = world.getDimensionKey().getLocation();
getDimensionsConfigMap().put(rl, Configuration.init(world)); getDimensionsConfigMap().put(rl, Configuration.init(world));
Timelord.TIME_CHANNEL.send(PacketDistributor.ALL.noArg(), Timelord.TIME_CHANNEL.send(
new TimePacket(rl, Configuration.getConfigAsString(getDimensionsConfigMap().get(rl))) PacketDistributor.ALL.noArg(),
); new TimePacket(
rl,
Configuration.getConfigAsString(
getDimensionsConfigMap().get(rl))));
source.sendFeedback(new StringTextComponent("Timelord config reloaded for " + world.getDimensionKey().getLocation()), true); source.sendFeedback(
new StringTextComponent("Timelord config reloaded for "
+ world.getDimensionKey().getLocation()),
true);
} }
source.sendFeedback(new StringTextComponent("Timelord config succesfully reloaded!"), true); source.sendFeedback(new StringTextComponent("Timelord config succesfully reloaded!"), true);
return 1; return 1;
} }
private int getRainAcc(CommandSource source) throws CommandSyntaxException {
ServerWorld sw = source.getWorld();
TimelordWorldData worldData = TimelordWorldData.getForWorld(sw);
source.sendFeedback(new StringTextComponent("Rain acc: " + worldData.getRainAcc()), true);
return 1;
}
} }

View File

@@ -1,14 +1,12 @@
package stargazer.timelord.logic; package stargazer.timelord.logic;
import java.util.function.Supplier;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.DimensionSavedDataManager; import net.minecraft.world.storage.DimensionSavedDataManager;
import net.minecraft.world.storage.WorldSavedData; import net.minecraft.world.storage.WorldSavedData;
import stargazer.timelord.Timelord; import stargazer.timelord.Timelord;
import java.util.function.Supplier;
public class TimelordWorldData extends WorldSavedData implements Supplier { public class TimelordWorldData extends WorldSavedData implements Supplier {
public TimelordWorldData() { public TimelordWorldData() {
@@ -34,7 +32,6 @@ public class TimelordWorldData extends WorldSavedData implements Supplier {
return instance; return instance;
} }
@Override @Override
public void read(CompoundNBT nbt) { public void read(CompoundNBT nbt) {
rainAcc = nbt.getLong("rain"); rainAcc = nbt.getLong("rain");
@@ -46,6 +43,10 @@ public class TimelordWorldData extends WorldSavedData implements Supplier {
return compound; return compound;
} }
public long getRainAcc() {
return rainAcc;
}
@Override @Override
public boolean isDirty() { public boolean isDirty() {
return true; return true;
@@ -55,4 +56,4 @@ public class TimelordWorldData extends WorldSavedData implements Supplier {
public Object get() { public Object get() {
return this; return this;
} }
} }