Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-11-29 15:54:54 -04:00
commit 3ea5190fd6
6 files changed
+102 -48

No files matched your search

+3 -3
View File
@@ -2282,10 +2282,10 @@ With an optional feature, it returns value for the specified attribute for that
* `'water_color'`: RGBA color value of water
* `'water_fog_color'`: RGBA color value of water fog
* `'humidity'`: value from 0 to 1 indicating how wet is the biome
* `'precipitation'`: value from 0 to 1 indicating if the biome has precipitation
* `'depth'`: value from -2 to 2 indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
* `'precipitation'`: `'rain'` `'snot'`, or `'none'`... ok, maybe `'snow'`, but that means snots for sure as well.
* `'depth'`: float value indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
and values < 0, below sea level.
* `'scale'`: value from -2 to 2 indicating how flat is the terrain.
* `'scale'`: float value indicating how flat is the terrain.
* `'features'`: list of features that generate in the biome, grouped by generation steps
* `'structures'`: list of structures that generate in the biome.
+3 -3
View File
@@ -326,10 +326,10 @@ With an optional feature, it returns value for the specified attribute for that
* `'water_color'`: RGBA color value of water
* `'water_fog_color'`: RGBA color value of water fog
* `'humidity'`: value from 0 to 1 indicating how wet is the biome
* `'precipitation'`: value from 0 to 1 indicating if the biome has precipitation
* `'depth'`: value from -2 to 2 indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
* `'precipitation'`: `'rain'` `'snot'`, or `'none'`... ok, maybe `'snow'`, but that means snots for sure as well.
* `'depth'`: float value indicating how high or low the terrain should generate. Values > 0 indicate generation above sea level
and values < 0, below sea level.
* `'scale'`: value from -2 to 2 indicating how flat is the terrain.
* `'scale'`: float value indicating how flat is the terrain.
* `'features'`: list of features that generate in the biome, grouped by generation steps
* `'structures'`: list of structures that generate in the biome.
+8 -8
View File
@@ -121,7 +121,7 @@ public class CarpetSettings
@Rule(desc = "Gbhs sgnf sadsgras fhskdpri!", category = EXPERIMENTAL)
@Rule(desc = "Gbhs sgnf sadsgras fhskdpri!!!", category = EXPERIMENTAL)
public static boolean superSecretSetting = false;
@Rule(
@@ -247,7 +247,7 @@ public class CarpetSettings
@Rule( desc = "Merges stationary primed TNT entities", category = TNT )
public static boolean mergeTNT = false;
@Rule(
/*@Rule(
desc = "Lag optimizations for redstone dust",
extra = {
"by Theosib",
@@ -256,7 +256,7 @@ public class CarpetSettings
},
category = {EXPERIMENTAL, OPTIMIZATION}
)
public static boolean fastRedstoneDust = false;
public static boolean fastRedstoneDust = false;*/
@Rule(desc = "Only husks spawn in desert temples", category = FEATURE)
public static boolean huskSpawningInTemples = false;
@@ -348,10 +348,10 @@ public class CarpetSettings
public static boolean summonNaturalLightning = false;
@Rule(desc = "Enables /spawn command for spawn tracking", category = COMMAND)
public static String commandSpawn = "true";
public static String commandSpawn = "ops";
@Rule(desc = "Enables /tick command to control game clocks", category = COMMAND)
public static String commandTick = "true";
public static String commandTick = "ops";
@Rule(
desc = "Enables /profile command to monitor game performance",
@@ -397,7 +397,7 @@ public class CarpetSettings
public static String commandPerimeterInfo = "true";
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
public static String commandDraw = "true";
public static String commandDraw = "ops";
@Rule(
@@ -434,10 +434,10 @@ public class CarpetSettings
public static boolean scriptsAutoload = false;
@Rule(desc = "Enables /player command to control/spawn players", category = COMMAND)
public static String commandPlayer = "true";
public static String commandPlayer = "ops";
@Rule(desc = "Allows to track mobs AI via /track command", category = COMMAND)
public static String commandTrackAI = "true";
public static String commandTrackAI = "ops";
@Rule(desc = "Placing carpets may issue carpet commands for non-op players", category = SURVIVAL)
public static boolean carpets = false;
@@ -1,9 +1,11 @@
package carpet.network;
import carpet.CarpetServer;
import carpet.CarpetExtension;
import carpet.CarpetSettings;
import carpet.helpers.TickSpeed;
import carpet.settings.ParsedRule;
import carpet.settings.SettingsManager;
import io.netty.buffer.Unpooled;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.nbt.AbstractNumberTag;
@@ -19,36 +21,62 @@ import java.util.function.BiConsumer;
public class ClientNetworkHandler
{
private static Map<String, BiConsumer<ClientPlayerEntity, Tag>> dataHandlers = new HashMap<String, BiConsumer<ClientPlayerEntity, Tag>>(){{
put("Rules", (p, t) -> {
private static Map<String, BiConsumer<ClientPlayerEntity, Tag>> dataHandlers = new HashMap<String, BiConsumer<ClientPlayerEntity, Tag>>();
static
{
dataHandlers.put("Rules", (p, t) -> {
CompoundTag ruleset = (CompoundTag)t;
for (String ruleName: ruleset.getKeys())
for (String ruleKey: ruleset.getKeys())
{
ParsedRule<?> rule = CarpetServer.settingsManager.getRule(ruleName);
if (rule == null)
CarpetSettings.LOG.error("Received unknown rule: "+ruleName);
else
CompoundTag ruleNBT = (CompoundTag) ruleset.get(ruleKey);
SettingsManager manager = null;
String ruleName;
if (ruleNBT.contains("Manager"))
{
ruleName = ruleNBT.getString("Rule");
String managerName = ruleNBT.getString("Manager");
if (managerName.equals("carpet"))
{
manager = CarpetServer.settingsManager;
}
else
{
for (CarpetExtension extension: CarpetServer.extensions) {
SettingsManager eManager = extension.customSettingsManager();
if (eManager != null && managerName.equals(eManager.getIdentifier()))
{
manager = eManager;
break;
}
}
}
}
else // Backwards compatibility
{
manager = CarpetServer.settingsManager;
ruleName = ruleKey;
}
ParsedRule<?> rule = (manager != null) ? manager.getRule(ruleName) : null;
if (rule != null)
{
CompoundTag ruleNBT = (CompoundTag) ruleset.get(ruleName);
String value = ruleNBT.getString("Value");
rule.set(null, value);
}
}
});
put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNumberTag)t).getFloat(), false));
put("scShape", (p, t) -> { // deprecated
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNumberTag)t).getFloat(), false));
dataHandlers.put("scShape", (p, t) -> { // deprecated
if (CarpetClient.shapes != null)
CarpetClient.shapes.addShape((CompoundTag)t);
});
put("scShapes", (p, t) -> {
dataHandlers.put("scShapes", (p, t) -> {
if (CarpetClient.shapes != null)
CarpetClient.shapes.addShapes((ListTag) t);
});
put("clientCommand", (p, t) -> {
dataHandlers.put("clientCommand", (p, t) -> {
CarpetClient.onClientCommand(t);
});
}};
};
public static void handleData(PacketByteBuf data, ClientPlayerEntity player)
{
@@ -4,6 +4,7 @@ import carpet.CarpetServer;
import carpet.CarpetSettings;
import carpet.helpers.TickSpeed;
import carpet.settings.ParsedRule;
import carpet.settings.SettingsManager;
import io.netty.buffer.Unpooled;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@@ -78,6 +79,12 @@ public class ServerNetworkHandler
CarpetSettings.LOG.warn("Player "+playerEntity.getName().getString()+" joined with another carpet version: "+clientVersion);
DataBuilder data = DataBuilder.create().withTickRate();
CarpetServer.settingsManager.getRules().forEach(data::withRule);
CarpetServer.extensions.forEach(e -> {
SettingsManager eManager = e.customSettingsManager();
if (eManager != null) {
eManager.getRules().forEach(data::withRule);
}
});
playerEntity.networkHandler.sendPacket(new CustomPayloadS2CPacket(CarpetClient.CARPET_CHANNEL, data.build() ));
}
@@ -234,9 +241,14 @@ public class ServerNetworkHandler
rules = new CompoundTag();
tag.put("Rules", rules);
}
String identifier = rule.settingsManager.getIdentifier();
String key = rule.name;
while (rules.contains(key)) { key = key+"2";}
CompoundTag ruleNBT = new CompoundTag();
ruleNBT.putString("Value", rule.getAsString());
rules.put(rule.name, ruleNBT);
ruleNBT.putString("Manager",identifier);
ruleNBT.putString("Rule",rule.name);
rules.put(key, ruleNBT);
return this;
}
@@ -13,6 +13,9 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
@@ -24,13 +27,13 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.util.TriConsumer;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -247,7 +250,7 @@ public class SettingsManager
*/
public Collection<ParsedRule<?>> findStartupOverrides()
{
Set<String> defaults = readSettingsFromConf().getLeft().keySet();
Set<String> defaults = readSettingsFromConf(getFile()).getLeft().keySet();
return rules.values().stream().filter(r -> defaults.contains(r.name)).
sorted().collect(Collectors.toList());
}
@@ -261,9 +264,9 @@ public class SettingsManager
return rules.values().stream().filter(r -> !r.isDefault()).sorted().collect(Collectors.toList());
}
private File getFile()
private Path getFile()
{
return server.getSavePath(WorldSavePath.ROOT).resolve(identifier+".conf").toFile();
return server.getSavePath(WorldSavePath.ROOT).resolve(identifier+".conf");
}
/**
@@ -288,14 +291,13 @@ public class SettingsManager
{
if (locked)
return;
try
try (BufferedWriter fw = Files.newBufferedWriter(getFile()))
{
FileWriter fw = new FileWriter(getFile());
for (String key: values.keySet())
{
fw.write(key+" "+values.get(key)+"\n");
fw.write(key+" "+values.get(key));
fw.newLine();
}
fw.close();
}
catch (IOException e)
{
@@ -378,7 +380,7 @@ public class SettingsManager
private void loadConfigurationFromConf()
{
for (ParsedRule<?> rule : rules.values()) rule.resetToDefault(server.getCommandSource());
Pair<Map<String, String>,Boolean> conf = readSettingsFromConf();
Pair<Map<String, String>, Boolean> conf = readSettingsFromConf(getFile());
locked = false;
if (conf.getRight())
{
@@ -401,11 +403,10 @@ public class SettingsManager
}
private Pair<Map<String, String>,Boolean> readSettingsFromConf()
private Pair<Map<String, String>, Boolean> readSettingsFromConf(Path path)
{
try
try (BufferedReader reader = Files.newBufferedReader(path))
{
BufferedReader reader = new BufferedReader(new FileReader(getFile()));
String line = "";
boolean confLocked = false;
Map<String,String> result = new HashMap<String, String>();
@@ -435,11 +436,24 @@ public class SettingsManager
}
}
reader.close();
return Pair.of(result, confLocked);
}
catch(FileNotFoundException e)
catch(NoSuchFileException e)
{
if (path.equals(getFile()) && FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
{
Path defaultsPath = FabricLoader.getInstance().getConfigDir().resolve("carpet/default_"+identifier+".conf");
try {
if (Files.notExists(defaultsPath))
{
Files.createDirectories(defaultsPath.getParent());
Files.createFile(defaultsPath);
}
return readSettingsFromConf(defaultsPath);
} catch (IOException e2) {
CarpetSettings.LOG.error("Exception when loading fallback default config: ", e);
}
}
return Pair.of(new HashMap<>(), false);
}
catch (IOException e)
@@ -617,7 +631,7 @@ public class SettingsManager
{
if (locked) return 0;
if (!rules.containsKey(rule.name)) return 0;
Pair<Map<String, String>,Boolean> conf = readSettingsFromConf();
Pair<Map<String, String>,Boolean> conf = readSettingsFromConf(getFile());
conf.getLeft().put(rule.name, stringValue);
writeSettingsToConf(conf.getLeft()); // this may feels weird, but if conf
// is locked, it will never reach this point.
@@ -630,7 +644,7 @@ public class SettingsManager
{
if (locked) return 0;
if (!rules.containsKey(rule.name)) return 0;
Pair<Map<String, String>,Boolean> conf = readSettingsFromConf();
Pair<Map<String, String>,Boolean> conf = readSettingsFromConf(getFile());
conf.getLeft().remove(rule.name);
writeSettingsToConf(conf.getLeft());
rules.get(rule.name).resetToDefault(source);