Merge branch '1.17'
This commit is contained in:
commit
af368a159d
173 files changed
+2214
-1462
No files matched your search
@@ -835,7 +835,9 @@ public class CarpetEventServer
|
||||
private final Set<Identifier> skippedStats = new HashSet<Identifier>(){{
|
||||
add(Stats.TIME_SINCE_DEATH);
|
||||
add(Stats.TIME_SINCE_REST);
|
||||
add(Stats.PLAY_ONE_MINUTE);
|
||||
//add(Stats.PLAY_ONE_MINUTE);
|
||||
add(Stats.PLAY_TIME);
|
||||
add(Stats.TOTAL_WORLD_TIME);
|
||||
}};
|
||||
@Override
|
||||
public void onPlayerStatistic(ServerPlayerEntity player, Stat<?> stat, int amount)
|
||||
@@ -943,7 +945,8 @@ public class CarpetEventServer
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<EntityType<? extends Entity>, Event>() {{
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<>()
|
||||
{{
|
||||
EntityType.get("zombie");
|
||||
Registry.ENTITY_TYPE.forEach(et -> {
|
||||
put(et, new Event(getEntityLoadEventName(et), 1, true, false)
|
||||
@@ -965,7 +968,8 @@ public class CarpetEventServer
|
||||
return "entity_handler_" + ValueConversions.of(Registry.ENTITY_TYPE.getId(et)).getString();
|
||||
}
|
||||
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_HANDLER= new HashMap<EntityType<? extends Entity>, Event>() {{
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_HANDLER= new HashMap<>()
|
||||
{{
|
||||
EntityType.get("zombie");
|
||||
Registry.ENTITY_TYPE.forEach(et -> {
|
||||
put(et, new Event(getEntityHandlerEventName(et), 2, true, false)
|
||||
|
||||
@@ -38,7 +38,7 @@ import net.fabricmc.loader.api.Version;
|
||||
import net.fabricmc.loader.api.VersionParsingException;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -72,7 +72,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
private final CarpetScriptServer scriptServer;
|
||||
public ServerCommandSource responsibleSource;
|
||||
|
||||
private Tag globalState;
|
||||
private NbtElement globalState;
|
||||
private int saveTimeout;
|
||||
public boolean persistenceRequired;
|
||||
|
||||
@@ -651,7 +651,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
{
|
||||
if (optionalTarget == null)
|
||||
{
|
||||
for (ServerPlayerEntity player : source.getMinecraftServer().getPlayerManager().getPlayerList())
|
||||
for (ServerPlayerEntity player : source.getServer().getPlayerManager().getPlayerList())
|
||||
{
|
||||
CarpetScriptHost host = (CarpetScriptHost) retrieveForExecution(player.getEntityName());
|
||||
targets.add(host);
|
||||
@@ -660,7 +660,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerPlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(optionalTarget);
|
||||
ServerPlayerEntity player = source.getServer().getPlayerManager().getPlayer(optionalTarget);
|
||||
if (player != null)
|
||||
{
|
||||
CarpetScriptHost host = (CarpetScriptHost) retrieveForExecution(player.getEntityName());
|
||||
@@ -937,7 +937,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
{
|
||||
for (Entity e : world.getEntitiesByType(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
{
|
||||
e.remove();
|
||||
e.discard();
|
||||
}
|
||||
}
|
||||
if (this.saveTimeout > 0)
|
||||
@@ -950,12 +950,12 @@ public class CarpetScriptHost extends ScriptHost
|
||||
Module.saveData(main, globalState);
|
||||
}
|
||||
|
||||
private Tag loadState()
|
||||
private NbtElement loadState()
|
||||
{
|
||||
return Module.getData(main);
|
||||
}
|
||||
|
||||
public Tag readFileTag(FileArgument fdesc)
|
||||
public NbtElement readFileTag(FileArgument fdesc)
|
||||
{
|
||||
if (getName() == null && !fdesc.isShared) return null;
|
||||
if (fdesc.resource != null)
|
||||
@@ -965,7 +965,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
return ((CarpetScriptHost)parent).globalState;
|
||||
}
|
||||
|
||||
public boolean writeTagFile(Tag tag, FileArgument fdesc)
|
||||
public boolean writeTagFile(NbtElement tag, FileArgument fdesc)
|
||||
{
|
||||
if (getName() == null && !fdesc.isShared) return false; // if belongs to an app, cannot be default host.
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@ public class CarpetScriptServer
|
||||
ServerPlayerEntity target = null;
|
||||
if (optionalTarget != null)
|
||||
{
|
||||
target = sender.getMinecraftServer().getPlayerManager().getPlayer(optionalTarget);
|
||||
target = sender.getServer().getPlayerManager().getPlayer(optionalTarget);
|
||||
if (target == null) return false;
|
||||
}
|
||||
int successes = signal(sender, target, hostname, udf, argv, true );
|
||||
@@ -436,8 +436,8 @@ public class CarpetScriptServer
|
||||
{
|
||||
// getPlayer will always return nonnull cause retrieve for execution only returns hosts for existing players.
|
||||
ServerCommandSource executingSource = host.perUser
|
||||
? source.getMinecraftServer().getPlayerManager().getPlayer(host.user).getCommandSource()
|
||||
: source.getMinecraftServer().getCommandSource();
|
||||
? source.getServer().getPlayerManager().getPlayer(host.user).getCommandSource()
|
||||
: source.getServer().getCommandSource();
|
||||
try
|
||||
{
|
||||
host.callUDF(BlockPos.ORIGIN, source.withLevel(CarpetSettings.runPermissionLevel), udf, argv);
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/* There is no worse example to use for 1.17 compatibility
|
||||
import static net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||
|
||||
public class FunctionsTestClass {
|
||||
@@ -58,3 +58,4 @@ public class FunctionsTestClass {
|
||||
return targets.size();
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
|
||||
import carpet.script.LazyValue;
|
||||
@@ -17,7 +18,6 @@ import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.dynamic.GlobalPos;
|
||||
@@ -48,7 +48,7 @@ public final class OutputConverter<T>
|
||||
registerToValue(String.class, StringValue::new);
|
||||
registerToValue(Entity.class, EntityValue::new);
|
||||
registerToValue(Text.class, FormattedTextValue::new);
|
||||
registerToValue(Tag.class, NBTSerializableValue::new);
|
||||
registerToValue(NbtElement.class, NBTSerializableValue::new);
|
||||
registerToValue(BlockPos.class, ValueConversions::of);
|
||||
registerToValue(Vec3d.class, ValueConversions::of);
|
||||
registerToValue(ItemStack.class, ValueConversions::of);
|
||||
|
||||
@@ -50,14 +50,21 @@ import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.ClearTitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerListHeaderS2CPacket;
|
||||
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||
import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.resource.DataPackSettings;
|
||||
import net.minecraft.resource.ReloadableResourceManagerImpl;
|
||||
@@ -120,6 +127,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -190,7 +198,7 @@ public class Auxiliary {
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (lv.size() == 0) return ListValue.wrap(Registry.PARTICLE_TYPE.getIds().stream().map(ValueConversions::of));
|
||||
MinecraftServer ms = cc.s.getMinecraftServer();
|
||||
MinecraftServer ms = cc.s.getServer();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
String particleName = lv.get(0).getString();
|
||||
@@ -262,7 +270,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,7 +310,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,14 +437,14 @@ public class Auxiliary {
|
||||
for (Entity e : cc.s.getWorld().getEntitiesByType(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
{
|
||||
total ++;
|
||||
e.remove();
|
||||
e.discard(); // discard // remove();
|
||||
}
|
||||
return new NumericValue(total);
|
||||
});
|
||||
|
||||
expression.addUnaryFunction("nbt", NBTSerializableValue::fromValue);
|
||||
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(StringTag.escape(v.getString())));
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(NbtString.escape(v.getString())));
|
||||
|
||||
expression.addUnaryFunction("parse_nbt", v -> {
|
||||
if (v instanceof NBTSerializableValue) return ((NBTSerializableValue) v).toValue();
|
||||
@@ -450,8 +458,8 @@ public class Auxiliary {
|
||||
if (numParam != 2 && numParam != 3) throw new InternalExpressionException("'tag_matches' requires 2 or 3 arguments");
|
||||
if (lv.get(1).isNull()) return Value.TRUE;
|
||||
if (lv.get(0).isNull()) return Value.FALSE;
|
||||
Tag source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
Tag match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
NbtElement source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
NbtElement match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
return BooleanValue.of(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
||||
});
|
||||
|
||||
@@ -460,7 +468,7 @@ public class Auxiliary {
|
||||
if (argSize==0 || argSize > 2) throw new InternalExpressionException("'encode_nbt' requires 1 or 2 parameters");
|
||||
Value v = lv.get(0);
|
||||
boolean force = (argSize > 1) && lv.get(1).getBoolean();
|
||||
Tag tag;
|
||||
NbtElement tag;
|
||||
try
|
||||
{
|
||||
tag = v.toTag(force);
|
||||
@@ -477,7 +485,7 @@ public class Auxiliary {
|
||||
{
|
||||
if (lv.size() == 0 || lv.size() > 2) throw new InternalExpressionException("'print' takes one or two arguments");
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
MinecraftServer server = s.getMinecraftServer();
|
||||
MinecraftServer server = s.getServer();
|
||||
Value res = lv.get(0);
|
||||
List<ServerPlayerEntity> targets = null;
|
||||
if (lv.size() == 2)
|
||||
@@ -508,38 +516,51 @@ public class Auxiliary {
|
||||
if (lv.size() < 2) throw new InternalExpressionException("'display_title' needs at least a target, type and message, and optionally times");
|
||||
Value pVal = lv.get(0);
|
||||
if (!(pVal instanceof ListValue)) pVal = ListValue.of(pVal);
|
||||
MinecraftServer server = ((CarpetContext)c).s.getMinecraftServer();
|
||||
MinecraftServer server = ((CarpetContext)c).s.getServer();
|
||||
Stream<ServerPlayerEntity> targets = ((ListValue) pVal).getItems().stream().map(v ->
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, v);
|
||||
if (player == null) throw new InternalExpressionException("'display_title' requires a valid online player or a list of players as first argument. "+v.getString()+" is not a player.");
|
||||
return player;
|
||||
});
|
||||
TitleS2CPacket.Action action;
|
||||
Function<Text, Packet<?>> packetGetter = null;
|
||||
//TitleS2CPacket.Action action;
|
||||
String actionString = lv.get(1).getString().toLowerCase(Locale.ROOT);
|
||||
switch (actionString)
|
||||
{
|
||||
case "title":
|
||||
action = Action.TITLE;
|
||||
packetGetter = TitleS2CPacket::new;
|
||||
//action = Action.TITLE;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
break;
|
||||
case "subtitle":
|
||||
action = Action.SUBTITLE;
|
||||
packetGetter = SubtitleS2CPacket::new;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
//action = Action.SUBTITLE;
|
||||
break;
|
||||
case "actionbar":
|
||||
action = Action.ACTIONBAR;
|
||||
packetGetter = OverlayMessageS2CPacket::new;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
//action = Action.ACTIONBAR;
|
||||
break;
|
||||
case "clear":
|
||||
action = Action.CLEAR;
|
||||
packetGetter = (x) -> new ClearTitleS2CPacket(true); // resetting default fade
|
||||
//action = Action.CLEAR;
|
||||
break;
|
||||
case "player_list_header":
|
||||
case "player_list_footer":
|
||||
action = null;
|
||||
break;
|
||||
default:
|
||||
throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'player_list_header', 'player_list_footer' or 'clear' as second argument");
|
||||
}
|
||||
if (action != Action.CLEAR && lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
//if (action != Action.CLEAR && lv.size() < 3)
|
||||
// throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
Text title;
|
||||
boolean soundsTrue = false;
|
||||
if (lv.size() > 2)
|
||||
@@ -549,14 +570,14 @@ public class Auxiliary {
|
||||
soundsTrue = pVal.getBoolean();
|
||||
}
|
||||
else title = null; // Will never happen, just to make lambda happy
|
||||
if (action == null)
|
||||
if (packetGetter == null)
|
||||
{
|
||||
Map<String, BaseText> map;
|
||||
if (actionString.equals("player_list_header"))
|
||||
map = HUDController.scarpet_headers;
|
||||
else
|
||||
map = HUDController.scarpet_footers;
|
||||
|
||||
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
List<ServerPlayerEntity> targetList = targets.collect(Collectors.toList());
|
||||
if (!soundsTrue) // null or empty string
|
||||
@@ -569,21 +590,23 @@ public class Auxiliary {
|
||||
map.put(target.getEntityName(), (BaseText) title);
|
||||
total.getAndIncrement();
|
||||
});
|
||||
HUDController.update_hud(((CarpetContext)c).s.getMinecraftServer(), targetList);
|
||||
HUDController.update_hud(((CarpetContext)c).s.getServer(), targetList);
|
||||
return NumericValue.of(total.get());
|
||||
}
|
||||
TitleS2CPacket timesPacket;
|
||||
TitleFadeS2CPacket timesPacket; // TimesPacket
|
||||
if (lv.size() > 3)
|
||||
{
|
||||
if (lv.size() != 6) throw new InternalExpressionException("'display_title' needs all fade-in, stay and fade-out times");
|
||||
int in = NumericValue.asNumber(lv.get(3),"fade in for display_title" ).getInt();
|
||||
int stay = NumericValue.asNumber(lv.get(4),"stay for display_title" ).getInt();
|
||||
int out = NumericValue.asNumber(lv.get(5),"fade out for display_title" ).getInt();
|
||||
timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
|
||||
timesPacket = new TitleFadeS2CPacket(in, stay, out);
|
||||
//timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
|
||||
}
|
||||
else timesPacket = null;
|
||||
|
||||
TitleS2CPacket packet = new TitleS2CPacket(action, title);
|
||||
Packet<?> packet = packetGetter.apply(title);
|
||||
//TitleS2CPacket packet = new TitleS2CPacket(action, title);
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
targets.forEach(p -> {
|
||||
if (timesPacket != null) p.networkHandler.sendPacket(timesPacket);
|
||||
@@ -607,7 +630,7 @@ public class Auxiliary {
|
||||
{
|
||||
Text[] error = {null};
|
||||
List<Text> output = new ArrayList<>();
|
||||
Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute(
|
||||
Value retval = new NumericValue(s.getServer().getCommandManager().execute(
|
||||
new SnoopyCommandSource(s, error, output),
|
||||
lv.get(0).getString())
|
||||
);
|
||||
@@ -626,15 +649,15 @@ public class Auxiliary {
|
||||
expression.addContextFunction("save", 0, (c, t, lv) ->
|
||||
{
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
s.getMinecraftServer().getPlayerManager().saveAllPlayerData();
|
||||
s.getMinecraftServer().save(true,true,true);
|
||||
s.getServer().getPlayerManager().saveAllPlayerData();
|
||||
s.getServer().save(true,true,true);
|
||||
s.getWorld().getChunkManager().tick(() -> true);
|
||||
CarpetScriptServer.LOG.warn("Saved chunks");
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getMinecraftServer().getTicks()));
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTicks()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getWorld().getTime()));
|
||||
@@ -655,9 +678,9 @@ public class Auxiliary {
|
||||
{
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
int currentReportedTick = ((CarpetContext) c).s.getMinecraftServer().getTicks()-1;
|
||||
int currentReportedTick = ((CarpetContext) c).s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = ((CarpetContext) c).s.getMinecraftServer().lastTickLengths;
|
||||
final long[] tickArray = ((CarpetContext) c).s.getServer().lastTickLengths;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
@@ -669,12 +692,12 @@ public class Auxiliary {
|
||||
expression.addContextFunction("game_tick", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerCommandSource s = cc.s;
|
||||
if (!s.getMinecraftServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (!s.getServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (CarpetServer.scriptServer.tickDepth > 16) throw new InternalExpressionException("'game_tick' function caused other 'game_tick' functions to run. You should not allow that.");
|
||||
try
|
||||
{
|
||||
CarpetServer.scriptServer.tickDepth ++;
|
||||
((MinecraftServerInterface) s.getMinecraftServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
((MinecraftServerInterface) s.getServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
if (lv.size() > 0)
|
||||
{
|
||||
long ms_total = NumericValue.asNumber(lv.get(0)).getLong();
|
||||
@@ -724,13 +747,13 @@ public class Auxiliary {
|
||||
ValueConversions.of( ((CarpetContext)c).s.getWorld()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext)c).s.getMinecraftServer().getPlayerManager().getViewDistance()));
|
||||
new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance()));
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
ServerCommandSource outerSource = ((CarpetContext)c).s;
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
World world = ValueConversions.dimFromValue(dimensionValue, outerSource.getMinecraftServer());
|
||||
World world = ValueConversions.dimFromValue(dimensionValue, outerSource.getServer());
|
||||
if (world == outerSource.getWorld()) return lv.get(1);
|
||||
ServerCommandSource innerSource = outerSource.withWorld((ServerWorld)world);
|
||||
Context newCtx = c.recreate();
|
||||
@@ -753,13 +776,13 @@ public class Auxiliary {
|
||||
ListValue.wrap(Registry.FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_features"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("structures"),
|
||||
ListValue.wrap(Registry.STRUCTURE_FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_structures"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
return MapValue.wrap(plopData);
|
||||
}
|
||||
@@ -768,7 +791,7 @@ public class Auxiliary {
|
||||
throw new InternalExpressionException("'plop' needs extra argument indicating what to plop");
|
||||
String what = lv.get(locator.offset).getString();
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).s.getWorld(), locator.block.getPos());
|
||||
|
||||
@@ -837,7 +860,7 @@ public class Auxiliary {
|
||||
Value retVal;
|
||||
if (fdesc.type == FileArgument.Type.NBT)
|
||||
{
|
||||
Tag state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
NbtElement state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
if (state == null) return Value.NULL;
|
||||
retVal = new NBTSerializableValue(state);
|
||||
}
|
||||
@@ -874,7 +897,7 @@ public class Auxiliary {
|
||||
NBTSerializableValue tagValue = (val instanceof NBTSerializableValue)
|
||||
? (NBTSerializableValue) val
|
||||
: new NBTSerializableValue(val.getString());
|
||||
Tag tag = tagValue.getTag();
|
||||
NbtElement tag = tagValue.getTag();
|
||||
success = ((CarpetScriptHost) c.host).writeTagFile(tag, fdesc);
|
||||
}
|
||||
else if (fdesc.type == FileArgument.Type.JSON)
|
||||
@@ -946,7 +969,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("statistic", 3, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getMinecraftServer(), lv.get(0));
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getServer(), lv.get(0));
|
||||
if (player == null) return Value.NULL;
|
||||
Identifier category;
|
||||
Identifier statName;
|
||||
@@ -1000,11 +1023,11 @@ public class Auxiliary {
|
||||
expression.addContextFunction("nbt_storage", -1, (c, t, lv) -> {
|
||||
if (lv.size() > 2) throw new InternalExpressionException("'nbt_storage' requires 0, 1 or 2 arguments.");
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
DataCommandStorage storage = cc.s.getMinecraftServer().getDataCommandStorage();
|
||||
DataCommandStorage storage = cc.s.getServer().getDataCommandStorage();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(storage.getIds().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
||||
String key = lv.get(0).getString();
|
||||
CompoundTag old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
NbtCompound old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
if (lv.size() == 2) {
|
||||
Value nbt = lv.get(1);
|
||||
NBTSerializableValue new_nbt = (nbt instanceof NBTSerializableValue) ? (NBTSerializableValue) nbt
|
||||
@@ -1019,7 +1042,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
String origName = lv.get(0).getString();
|
||||
String name = InputValidator.validateSimpleString(origName, true);
|
||||
MinecraftServer server = cc.s.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
for (String dpName : server.getDataPackManager().getNames())
|
||||
{
|
||||
if (dpName.equalsIgnoreCase("file/"+name+".zip") ||
|
||||
@@ -1084,7 +1107,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("enable_hidden_dimensions", 0, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
// from minecraft.server.Main.main
|
||||
MinecraftServer server = cc.s.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
LevelStorage.Session session = ((MinecraftServerInterface)server).getCMSession();
|
||||
DataPackSettings dataPackSettings = session.getDataPackSettings();
|
||||
ResourcePackManager resourcePackManager = server.getDataPackManager();
|
||||
@@ -1099,7 +1122,7 @@ public class Auxiliary {
|
||||
//not sure its needed, but doesn't seem to have a negative effect and might be used in some custom shtuff
|
||||
serverRM.loadRegistryTags();
|
||||
|
||||
RegistryOps<Tag> registryOps = RegistryOps.of(NbtOps.INSTANCE, serverRM.getResourceManager(), (DynamicRegistryManager.Impl) server.getRegistryManager());
|
||||
RegistryOps<NbtElement> registryOps = RegistryOps.of(NbtOps.INSTANCE, serverRM.getResourceManager(), (DynamicRegistryManager.Impl) server.getRegistryManager());
|
||||
SaveProperties saveProperties = session.readLevelProperties(registryOps, dataPackSettings2);
|
||||
if (saveProperties == null) return Value.NULL;
|
||||
//session.backupLevelDataFile(server.getRegistryManager(), saveProperties); // no need
|
||||
@@ -1117,7 +1140,7 @@ public class Auxiliary {
|
||||
if (!existing_worlds.containsKey(registryKey))
|
||||
{
|
||||
addeds.add(ValueConversions.of(registryKey.getValue()));
|
||||
RegistryKey<World> registryKey2 = RegistryKey.of(Registry.DIMENSION, registryKey.getValue());
|
||||
RegistryKey<World> registryKey2 = RegistryKey.of(Registry.WORLD_KEY, registryKey.getValue());
|
||||
DimensionType dimensionType3 = entry.getValue().getDimensionType();
|
||||
ChunkGenerator chunkGenerator3 = entry.getValue().getChunkGenerator();
|
||||
UnmodifiableLevelProperties unmodifiableLevelProperties = new UnmodifiableLevelProperties(saveProperties, ((ServerWorldInterface) server.getOverworld()).getWorldPropertiesCM());
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -48,7 +48,7 @@ public class Entities {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (cc.host.user != null)
|
||||
{
|
||||
ServerPlayerEntity player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(cc.host.user);
|
||||
ServerPlayerEntity player = cc.s.getServer().getPlayerManager().getPlayer(cc.host.user);
|
||||
return EntityValue.of(player);
|
||||
}
|
||||
Entity callingEntity = cc.s.getEntity();
|
||||
@@ -62,7 +62,7 @@ public class Entities {
|
||||
if ("all".equalsIgnoreCase(playerName))
|
||||
{
|
||||
retval = ListValue.wrap(
|
||||
((CarpetContext)c).s.getMinecraftServer().getPlayerManager().getPlayerList().
|
||||
((CarpetContext)c).s.getServer().getPlayerManager().getPlayerList().
|
||||
stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
}
|
||||
else if ("*".equalsIgnoreCase(playerName))
|
||||
@@ -97,7 +97,7 @@ public class Entities {
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerPlayerEntity player = ((CarpetContext) c).s.getMinecraftServer().getPlayerManager().getPlayer(playerName);
|
||||
ServerPlayerEntity player = ((CarpetContext) c).s.getServer().getPlayerManager().getPlayer(playerName);
|
||||
if (player != null)
|
||||
retval = new EntityValue(player);
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class Entities {
|
||||
Vector3Argument position = Vector3Argument.findIn(lv, 1);
|
||||
if (position.fromBlock)
|
||||
position.vec = position.vec.subtract(0, 0.5, 0);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
boolean hasTag = false;
|
||||
if (lv.size() > position.offset)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ public class Entities {
|
||||
|
||||
ServerWorld serverWorld = cc.s.getWorld();
|
||||
Entity entity_1 = EntityType.loadEntityWithPassengers(tag, serverWorld, (entity_1x) -> {
|
||||
entity_1x.refreshPositionAndAngles(vec3d.x, vec3d.y, vec3d.z, entity_1x.yaw, entity_1x.pitch);
|
||||
entity_1x.refreshPositionAndAngles(vec3d.x, vec3d.y, vec3d.z, entity_1x.getYaw(), entity_1x.getPitch());
|
||||
return !serverWorld.tryLoadEntity(entity_1x) ? null : entity_1x;
|
||||
});
|
||||
if (entity_1 == null) {
|
||||
@@ -167,8 +167,8 @@ public class Entities {
|
||||
{
|
||||
String who = lv.get(0).getString();
|
||||
ServerCommandSource source = ((CarpetContext)c).s;
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getMinecraftServer());
|
||||
List<Entity> entityList = source.getWorld().getEntitiesByType(eDesc.directType, eDesc.filteringPredicate);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
|
||||
List<? extends Entity> entityList = source.getWorld().getEntitiesByType(eDesc.directType, eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
@@ -195,7 +195,7 @@ public class Entities {
|
||||
throw new InternalExpressionException("Range of 'entity_area' cannot come from a block argument");
|
||||
Vec3d range = rangeLocator.vec;
|
||||
Box area = centerBox.expand(range.x, range.y, range.z);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.s.getMinecraftServer());
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.s.getServer());
|
||||
List<? extends Entity> entityList = cc.s.getWorld().getEntitiesByType(eDesc.directType, area,eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -257,7 +257,7 @@ public class Entities {
|
||||
{
|
||||
if (lv.size() > 1) throw new InternalExpressionException("'entity_types' requires one or no arguments");
|
||||
String desc = (lv.size() == 1)?lv.get(0).getString():"*";
|
||||
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getMinecraftServer()).listValue;
|
||||
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getServer()).listValue;
|
||||
});
|
||||
|
||||
expression.addContextFunction("entity_load_handler", -1, (c, t, lv) ->
|
||||
@@ -269,7 +269,7 @@ public class Entities {
|
||||
? ((ListValue) entityValue).getItems().stream().map(Value::getString).collect(Collectors.toList())
|
||||
: Collections.singletonList(entityValue.getString());
|
||||
Set<EntityType<? extends Entity>> types = new HashSet<>();
|
||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getMinecraftServer()).typeList));
|
||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getServer()).typeList));
|
||||
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
|
||||
CarpetEventServer events = ((CarpetScriptHost)c.host).getScriptServer().events;
|
||||
if (funArg.function == null)
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
|
||||
import net.minecraft.recipe.AbstractCookingRecipe;
|
||||
import net.minecraft.recipe.CuttingRecipe;
|
||||
@@ -36,6 +36,7 @@ import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.TagManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.InvalidIdentifierException;
|
||||
@@ -65,9 +66,9 @@ public class Inventories {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.ITEM.getIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getItems().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return ListValue.wrap(itemTag.values().stream().map(b -> ValueConversions.of(Registry.ITEM.getId(b))).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -75,16 +76,16 @@ public class Inventories {
|
||||
expression.addContextFunction("item_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getItems().getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
|
||||
if (lv.size() == 1)
|
||||
return ListValue.wrap(tagManager.getItems().getTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
String tag = lv.get(1).getString();
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getItems().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return BooleanValue.of(item.isIn(itemTag));
|
||||
return BooleanValue.of(itemTag.contains(item));
|
||||
});
|
||||
|
||||
expression.addContextFunction("recipe_data", -1, (c, t, lv) ->
|
||||
@@ -99,7 +100,7 @@ public class Inventories {
|
||||
type = Registry.RECIPE_TYPE.get(InputValidator.identifierOf(recipeType));
|
||||
}
|
||||
List<Recipe<?>> recipes;
|
||||
recipes = ((RecipeManagerInterface) cc.s.getMinecraftServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
recipes = ((RecipeManagerInterface) cc.s.getServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
if (recipes.isEmpty())
|
||||
return Value.NULL;
|
||||
List<Value> recipesOutput = new ArrayList<>();
|
||||
@@ -107,7 +108,7 @@ public class Inventories {
|
||||
{
|
||||
ItemStack result = recipe.getOutput();
|
||||
List<Value> ingredientValue = new ArrayList<>();
|
||||
recipe.getPreviewInputs().forEach(
|
||||
recipe.getIngredients().forEach(
|
||||
ingredient ->
|
||||
{
|
||||
// I am flattening ingredient lists per slot.
|
||||
@@ -239,7 +240,7 @@ public class Inventories {
|
||||
syncPlayerInventory(inventoryLocator, slot);
|
||||
return ValueConversions.of(previousStack);
|
||||
}
|
||||
CompoundTag nbt = null; // skipping one argument
|
||||
NbtCompound nbt = null; // skipping one argument
|
||||
if (lv.size() > inventoryLocator.offset+3)
|
||||
{
|
||||
Value nbtValue = lv.get(inventoryLocator.offset+3);
|
||||
@@ -389,7 +390,7 @@ public class Inventories {
|
||||
{
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) inventory.owner;
|
||||
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(
|
||||
-2,
|
||||
-2, 0, // resolve mystery argument
|
||||
int_1,
|
||||
inventory.inventory.getStack(int_1)
|
||||
));
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
if (lv.size()==0)
|
||||
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new).collect(Collectors.toList()));
|
||||
String objectiveName = lv.get(0).getString();
|
||||
@@ -103,7 +103,7 @@ public class Scoreboards {
|
||||
{
|
||||
if (lv.size()==0) throw new InternalExpressionException("'scoreboard_remove' requires at least one parameter");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String objectiveName = lv.get(0).getString();
|
||||
ScoreboardObjective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective == null) return Value.FALSE;
|
||||
@@ -126,7 +126,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_add", -1, (c, t, lv)->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
if (lv.size() == 0 || lv.size()>2) throw new InternalExpressionException("'scoreboard_add' should have one or two parameters");
|
||||
String objectiveName = lv.get(0).getString();
|
||||
ScoreboardCriterion criterion;
|
||||
@@ -137,7 +137,7 @@ public class Scoreboards {
|
||||
else
|
||||
{
|
||||
String critetionName = lv.get(1).getString();
|
||||
criterion = ScoreboardCriterion.createStatCriterion(critetionName).orElse(null);
|
||||
criterion = ScoreboardCriterion.getOrCreateStatCriterion(critetionName).orElse(null);
|
||||
if (criterion==null)
|
||||
{
|
||||
throw new ThrowStatement(critetionName, Throwables.UNKNOWN_CRITERION);
|
||||
@@ -156,7 +156,7 @@ public class Scoreboards {
|
||||
return Value.FALSE;
|
||||
}
|
||||
|
||||
scoreboard.addObjective(objectiveName, criterion, new LiteralText(objectiveName), criterion.getCriterionType());
|
||||
scoreboard.addObjective(objectiveName, criterion, new LiteralText(objectiveName), criterion.getDefaultRenderType());
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Scoreboards {
|
||||
{
|
||||
if(lv.size() < 2) throw new InternalExpressionException("'scoreboard_property' requires at least two parameters");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ScoreboardObjective objective = scoreboard.getObjective(lv.get(0).getString());
|
||||
if(objective == null) return Value.NULL;
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Scoreboards {
|
||||
switch (property) {
|
||||
case "criterion":
|
||||
if(modify) {
|
||||
ScoreboardCriterion criterion = ScoreboardCriterion.createStatCriterion(setValue.getString()).orElse(null);
|
||||
ScoreboardCriterion criterion = ScoreboardCriterion.getOrCreateStatCriterion(setValue.getString()).orElse(null);
|
||||
if (criterion==null) throw new InternalExpressionException("Unknown scoreboard criterion: "+ setValue.getString());
|
||||
if(objective.getCriterion().equals(criterion) || lv.size() == 1) return Value.FALSE;
|
||||
((Scoreboard_scarpetMixin)scoreboard).getObjectivesByCriterion().get(objective.getCriterion()).remove(objective);
|
||||
@@ -229,7 +229,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_display", 2, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String location = lv.get(0).getString();
|
||||
int slot = Scoreboard.getDisplaySlotId(location);
|
||||
if (slot < 0) throw new InternalExpressionException("Invalid objective slot: "+location);
|
||||
@@ -250,7 +250,7 @@ public class Scoreboards {
|
||||
{
|
||||
if(lv.size() > 1) throw new InternalExpressionException("'team_list' requires zero or one parameters");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
if(lv.size() == 0)
|
||||
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of).collect(Collectors.toList()));
|
||||
if (lv.size() != 1) return Value.NULL;
|
||||
@@ -265,7 +265,7 @@ public class Scoreboards {
|
||||
if(!(lv.size() < 3 && lv.size() > 0)) throw new InternalExpressionException("'team_add' requires one or two parameters");
|
||||
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String teamName = lv.get(0).getString();
|
||||
|
||||
if(lv.size() == 1)
|
||||
@@ -288,7 +288,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_remove", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Value teamVal = lv.get(0);
|
||||
String team = teamVal.getString();
|
||||
if(scoreboard.getTeam(team) == null) return Value.NULL;
|
||||
@@ -300,7 +300,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_leave", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Value playerVal = lv.get(0);
|
||||
String player = EntityValue.getPlayerNameByValue(playerVal);
|
||||
if(player == null) return Value.NULL;
|
||||
@@ -310,7 +310,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_property", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
|
||||
if(lv.size() < 2 || lv.size() > 3) throw new InternalExpressionException("'team_property' requires two or three arguments");
|
||||
|
||||
@@ -401,7 +401,7 @@ public class Scoreboards {
|
||||
|
||||
expression.addContextFunction("bossbar", -1, (c, t, lv) ->
|
||||
{
|
||||
BossBarManager bossBarManager = ((CarpetContext)c).s.getMinecraftServer().getBossBarManager();
|
||||
BossBarManager bossBarManager = ((CarpetContext)c).s.getServer().getBossBarManager();
|
||||
if(lv.size() > 3) throw new InternalExpressionException("'bossbar' accepts max three arguments");
|
||||
|
||||
if(lv.size() == 0) return ListValue.wrap(bossBarManager.getAll().stream().map(CommandBossBar::getId).map(Identifier::toString).map(StringValue::of).collect(Collectors.toList()));
|
||||
@@ -451,13 +451,13 @@ public class Scoreboards {
|
||||
|
||||
if(propertyValue instanceof ListValue) {
|
||||
((ListValue) propertyValue).getItems().forEach((v)->{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext)c).s.getMinecraftServer(),propertyValue);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext)c).s.getServer(),propertyValue);
|
||||
if(player != null) bossBar.addPlayer(player);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), propertyValue);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
if(player != null) {
|
||||
bossBar.addPlayer(player);
|
||||
return Value.TRUE;
|
||||
@@ -469,14 +469,14 @@ public class Scoreboards {
|
||||
{
|
||||
bossBar.clearPlayers();
|
||||
((ListValue) propertyValue).getItems().forEach((v) -> {
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), v);
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), v);
|
||||
if (p != null) bossBar.addPlayer(p);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), propertyValue);
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
bossBar.clearPlayers();
|
||||
if (p != null) {
|
||||
bossBar.addPlayer(p);
|
||||
@@ -484,10 +484,10 @@ public class Scoreboards {
|
||||
}
|
||||
return Value.FALSE;
|
||||
case "style":
|
||||
if(propertyValue == null) return StringValue.of(bossBar.getOverlay().getName());
|
||||
if(propertyValue == null) return StringValue.of(bossBar.getStyle().getName());
|
||||
BossBar.Style style = BossBar.Style.byName(propertyValue.getString());
|
||||
if(style == null) throw new InternalExpressionException("'" + propertyValue.getString() + "' is not a valid value for property " + property);
|
||||
bossBar.setOverlay(style);
|
||||
bossBar.setStyle(style);
|
||||
return Value.TRUE;
|
||||
case "value":
|
||||
if(propertyValue == null) return NumericValue.of(bossBar.getValue());
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Threading
|
||||
{
|
||||
//"overidden" native call to cancel if on main thread
|
||||
expression.addContextFunction("task_join", 1, (c, t, lv) -> {
|
||||
if (((CarpetContext)c).s.getMinecraftServer().isOnThread())
|
||||
if (((CarpetContext)c).s.getServer().isOnThread())
|
||||
throw new InternalExpressionException("'task_join' cannot be called from main thread to avoid deadlocks");
|
||||
Value v = lv.get(0);
|
||||
if (!(v instanceof ThreadValue))
|
||||
@@ -27,13 +27,13 @@ public class Threading
|
||||
// has to be lazy due to deferred execution of the expression
|
||||
expression.addLazyFunctionWithDelegation("task_dock", 1, false,true, (c, t, expr, tok, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
MinecraftServer server = cc.s.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
if (server.isOnThread()) return lv.get(0); // pass through for on thread tasks
|
||||
Value[] result = new Value[]{Value.NULL};
|
||||
RuntimeException[] internal = new RuntimeException[]{null};
|
||||
try
|
||||
{
|
||||
((CarpetContext) c).s.getMinecraftServer().submitAndJoin(() ->
|
||||
((CarpetContext) c).s.getServer().submitAndJoin(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -62,8 +62,8 @@ import net.minecraft.item.MiningToolItem;
|
||||
import net.minecraft.item.ShearsItem;
|
||||
import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.item.TridentItem;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
@@ -74,6 +74,7 @@ import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.TagManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Clearable;
|
||||
@@ -245,7 +246,7 @@ public class WorldAccess {
|
||||
return true;
|
||||
} else {
|
||||
ItemStack itemStack_1 = player.getMainHandStack();
|
||||
boolean boolean_2 = player.isUsingEffectiveTool(blockState_1);
|
||||
boolean boolean_2 = player.canHarvest(blockState_1);
|
||||
itemStack_1.postMine(player.world, blockState_1, blockPos_1, player);
|
||||
if (boolean_1 && boolean_2) {
|
||||
ItemStack itemStack_2 = itemStack_1.isEmpty() ? ItemStack.EMPTY : itemStack_1.copy();
|
||||
@@ -286,7 +287,7 @@ public class WorldAccess {
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
throw new InternalExpressionException("Block requires at least one parameter");
|
||||
CompoundTag tag = BlockArgument.findIn( (CarpetContext) c, lv, 0, true).block.getData();
|
||||
NbtCompound tag = BlockArgument.findIn( (CarpetContext) c, lv, 0, true).block.getData();
|
||||
return NBTSerializableValue.of(tag);
|
||||
});
|
||||
|
||||
@@ -582,7 +583,7 @@ public class WorldAccess {
|
||||
{
|
||||
c.host.issueDeprecation("loaded_ep(...)");
|
||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||
return BooleanValue.of(((CarpetContext)c).s.getWorld().getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
return BooleanValue.of(((CarpetContext)c).s.getWorld().method_37118(pos));// 1.17pre1 getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
});
|
||||
|
||||
expression.addContextFunction("loaded_status", -1, (c, t, lv) ->
|
||||
@@ -698,7 +699,7 @@ public class WorldAccess {
|
||||
boolean previous = CarpetSettings.impendingFillSkipUpdates.get();
|
||||
if (previous) return lv.get(0);
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -721,7 +722,7 @@ public class WorldAccess {
|
||||
BlockArgument sourceLocator = BlockArgument.findIn(cc, lv, targetLocator.offset, true);
|
||||
BlockState sourceBlockState = sourceLocator.block.getBlockState();
|
||||
BlockState targetBlockState = world.getBlockState(targetLocator.block.getPos());
|
||||
CompoundTag data = null;
|
||||
NbtCompound data = null;
|
||||
if (lv.size() > sourceLocator.offset)
|
||||
{
|
||||
List<Value> args = new ArrayList<>();
|
||||
@@ -780,14 +781,14 @@ public class WorldAccess {
|
||||
}
|
||||
|
||||
if (data == null) data = sourceLocator.block.getData();
|
||||
CompoundTag finalData = data;
|
||||
NbtCompound finalData = data;
|
||||
|
||||
if (sourceBlockState == targetBlockState && data == null)
|
||||
return Value.FALSE;
|
||||
BlockState finalSourceBlockState = sourceBlockState;
|
||||
BlockPos targetPos = targetLocator.block.getPos();
|
||||
Boolean[] result = new Boolean[]{true};
|
||||
cc.s.getMinecraftServer().submitAndJoin( () ->
|
||||
cc.s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Clearable.clear(world.getBlockEntity(targetPos));
|
||||
boolean success = world.setBlockState(targetPos, finalSourceBlockState, 2);
|
||||
@@ -796,11 +797,11 @@ public class WorldAccess {
|
||||
BlockEntity be = world.getBlockEntity(targetPos);
|
||||
if (be != null)
|
||||
{
|
||||
CompoundTag destTag = finalData.copy();
|
||||
NbtCompound destTag = finalData.copy();
|
||||
destTag.putInt("x", targetPos.getX());
|
||||
destTag.putInt("y", targetPos.getY());
|
||||
destTag.putInt("z", targetPos.getZ());
|
||||
be.fromTag(finalSourceBlockState, destTag);
|
||||
be.readNbt(destTag);
|
||||
be.markDirty();
|
||||
success = true;
|
||||
}
|
||||
@@ -838,7 +839,7 @@ public class WorldAccess {
|
||||
.orElseThrow(() -> new ThrowStatement(itemString, Throwables.UNKNOWN_ITEM));
|
||||
}
|
||||
}
|
||||
CompoundTag tag = null;
|
||||
NbtCompound tag = null;
|
||||
if (lv.size() > locator.offset+1)
|
||||
{
|
||||
if (!playerBreak) throw new InternalExpressionException("tag is not necessary with 'destroy' with no item");
|
||||
@@ -866,7 +867,7 @@ public class WorldAccess {
|
||||
boolean dropLoot = true;
|
||||
if (playerBreak)
|
||||
{
|
||||
boolean isUsingEffectiveTool = !state.isToolRequired() || tool.isEffectiveOn(state);
|
||||
boolean isUsingEffectiveTool = !state.isToolRequired() || tool.isSuitableFor(state);
|
||||
//postMine() durability from item classes
|
||||
float hardness = state.getHardness(world, where);
|
||||
int damageAmount = 0;
|
||||
@@ -901,7 +902,7 @@ public class WorldAccess {
|
||||
return Value.TRUE;
|
||||
if (toolBroke)
|
||||
return Value.NULL;
|
||||
Tag outtag = tool.getTag();
|
||||
NbtElement outtag = tool.getTag();
|
||||
if (outtag == null)
|
||||
return Value.TRUE;
|
||||
return new NBTSerializableValue(() -> outtag);
|
||||
@@ -1083,7 +1084,7 @@ public class WorldAccess {
|
||||
|
||||
expression.addContextFunction("map_colour", -1, (c, t, lv) ->
|
||||
stateStringQuery(c, "map_colour", lv, (s, p) ->
|
||||
BlockInfo.mapColourName.get(s.getTopMaterialColor(((CarpetContext)c).s.getWorld(), p))));
|
||||
BlockInfo.mapColourName.get(s.getMapColor(((CarpetContext)c).s.getWorld(), p))));
|
||||
|
||||
|
||||
// Deprecated for block_state()
|
||||
@@ -1141,9 +1142,9 @@ public class WorldAccess {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.BLOCK.getIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return ListValue.wrap(blockTag.values().stream().map(b -> ValueConversions.of(Registry.BLOCK.getId(b))).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -1151,17 +1152,17 @@ public class WorldAccess {
|
||||
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getBlocks().getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||
if (blockLocator.offset == lv.size())
|
||||
{
|
||||
Block target = blockLocator.block.getBlockState().getBlock();
|
||||
return ListValue.wrap(tagManager.getBlocks().getTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
}
|
||||
String tag = lv.get(blockLocator.offset).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(InputValidator.identifierOf(tag));
|
||||
Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return BooleanValue.of(blockLocator.block.getBlockState().isIn(blockTag));
|
||||
});
|
||||
@@ -1188,7 +1189,7 @@ public class WorldAccess {
|
||||
// in locatebiome
|
||||
if (locator.offset == lv.size())
|
||||
{
|
||||
Identifier biomeId = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
Identifier biomeId = cc.s.getServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
}
|
||||
String biomeFeature = lv.get(locator.offset).getString();
|
||||
@@ -1205,7 +1206,7 @@ public class WorldAccess {
|
||||
throw new InternalExpressionException("'set_biome' needs a biome name as an argument");
|
||||
String biomeName = lv.get(locator.offset+0).getString();
|
||||
// from locatebiome command code
|
||||
Biome biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(InputValidator.identifierOf(biomeName))
|
||||
Biome biome = cc.s.getServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(InputValidator.identifierOf(biomeName))
|
||||
.orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
|
||||
boolean doImmediateUpdate = true;
|
||||
if (lv.size() > locator.offset+1)
|
||||
@@ -1224,7 +1225,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockPos pos = BlockArgument.findIn(cc, lv, 0).block.getPos();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
cc.s.getMinecraftServer().submitAndJoin( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
cc.s.getServer().submitAndJoin( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
@@ -1323,10 +1324,10 @@ public class WorldAccess {
|
||||
StructureStart<?> start = entry.getValue();
|
||||
if (start == StructureStart.DEFAULT)
|
||||
continue;
|
||||
BlockBox box = start.getBoundingBox();
|
||||
BlockBox box = start.setBoundingBoxFromChildren();
|
||||
structureList.put(
|
||||
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getId(entry.getKey()))),
|
||||
ListValue.of(ListValue.fromTriple(box.minX, box.minY, box.minZ), ListValue.fromTriple(box.maxX, box.maxY, box.maxZ))
|
||||
ListValue.of(ListValue.fromTriple(box.getMinX(), box.getMinY(), box.getMinZ()), ListValue.fromTriple(box.getMaxX(), box.getMaxY(), box.getMaxZ()))
|
||||
);
|
||||
}
|
||||
return MapValue.wrap(structureList);
|
||||
@@ -1351,7 +1352,7 @@ public class WorldAccess {
|
||||
// good 'ol pointer
|
||||
Value[] result = new Value[]{Value.NULL};
|
||||
// technically a world modification. Even if we could let it slide, we will still park it
|
||||
((CarpetContext) c).s.getMinecraftServer().submitAndJoin(() ->
|
||||
((CarpetContext) c).s.getServer().submitAndJoin(() ->
|
||||
{
|
||||
Map<StructureFeature<?>, StructureStart<?>> structures = world.getChunk(pos).getStructureStarts();
|
||||
if (lv.size() == locator.offset + 1)
|
||||
@@ -1371,11 +1372,11 @@ public class WorldAccess {
|
||||
return;
|
||||
}
|
||||
StructureStart<?> start = structures.get(structure);
|
||||
ChunkPos structureChunkPos = new ChunkPos(start.getChunkX(), start.getChunkZ());
|
||||
BlockBox box = start.getBoundingBox();
|
||||
for (int chx = box.minX / 16; chx <= box.maxX / 16; chx++)
|
||||
ChunkPos structureChunkPos = start.getPos(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
|
||||
BlockBox box = start.setBoundingBoxFromChildren();
|
||||
for (int chx = box.getMinX() / 16; chx <= box.getMaxX() / 16; chx++) // minx maxx
|
||||
{
|
||||
for (int chz = box.minZ / 16; chz <= box.maxZ / 16; chz++)
|
||||
for (int chz = box.getMinZ() / 16; chz <= box.getMaxZ() / 16; chz++) //minZ maxZ
|
||||
{
|
||||
ChunkPos chpos = new ChunkPos(chx, chz);
|
||||
// getting a chunk will convert it to full, allowing to modify references
|
||||
@@ -1413,7 +1414,7 @@ public class WorldAccess {
|
||||
}
|
||||
}
|
||||
|
||||
boolean success = WorldTools.createWorld(cc.s.getMinecraftServer(), worldKey, seed);
|
||||
boolean success = WorldTools.createWorld(cc.s.getServer(), worldKey, seed);
|
||||
if (!success) return Value.FALSE;
|
||||
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
||||
return Value.TRUE;
|
||||
@@ -1472,16 +1473,16 @@ public class WorldAccess {
|
||||
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Map<String, Integer> report = ((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(requestedChunks);
|
||||
for (ChunkPos chpos: requestedChunks)
|
||||
/*for (ChunkPos chpos: requestedChunks) // needed in 1.16 only
|
||||
{
|
||||
if (world.getChunk(chpos.x, chpos.z, ChunkStatus.FULL, false) != null)
|
||||
{
|
||||
WorldTools.forceChunkUpdate(chpos.getStartPos(), world);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
result[0] = MapValue.wrap(report.entrySet().stream().collect(Collectors.toMap(
|
||||
e -> new StringValue((String)((Map.Entry) e).getKey()),
|
||||
e -> new NumericValue((Integer)((Map.Entry) e).getValue())
|
||||
|
||||
@@ -14,11 +14,11 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.PositionTracker;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagReaders;
|
||||
import net.minecraft.nbt.NbtTagSizeTracker;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtTypes;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
@@ -331,7 +331,7 @@ public class FileArgument
|
||||
return true;
|
||||
}
|
||||
|
||||
public Tag getNbtData(Module module) // aka getData
|
||||
public NbtElement getNbtData(Module module) // aka getData
|
||||
{
|
||||
try { synchronized (writeIOSync) {
|
||||
Path dataFile = toPath(module);
|
||||
@@ -345,7 +345,7 @@ public class FileArgument
|
||||
|
||||
//copied private method from net.minecraft.nbt.NbtIo.read()
|
||||
// to read non-compound tags - these won't be compressed
|
||||
public static Tag readTag(Path path)
|
||||
public static NbtElement readTag(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -375,7 +375,7 @@ public class FileArgument
|
||||
else
|
||||
{
|
||||
dataInput_1.readUTF();
|
||||
return TagReaders.of(byte_1).read(dataInput_1, 0, PositionTracker.DEFAULT);
|
||||
return NbtTypes.byId(byte_1).read(dataInput_1, 0, NbtTagSizeTracker.EMPTY);
|
||||
}
|
||||
}
|
||||
catch (IOException secondIO)
|
||||
@@ -393,7 +393,7 @@ public class FileArgument
|
||||
}
|
||||
}
|
||||
|
||||
public boolean saveNbtData(Module module, Tag tag) // aka saveData
|
||||
public boolean saveNbtData(Module module, NbtElement tag) // aka saveData
|
||||
{
|
||||
try { synchronized (writeIOSync) {
|
||||
Path dataFile = toPath(module);
|
||||
@@ -408,7 +408,7 @@ public class FileArgument
|
||||
}
|
||||
|
||||
//copied private method from net.minecraft.nbt.NbtIo.write() and client method safe_write
|
||||
public static boolean writeTagDisk(Tag tag_1, Path path, boolean zipped)
|
||||
public static boolean writeTagDisk(NbtElement tag_1, Path path, boolean zipped)
|
||||
{
|
||||
Path original = path;
|
||||
try
|
||||
@@ -419,9 +419,9 @@ public class FileArgument
|
||||
Files.deleteIfExists(path);
|
||||
}
|
||||
|
||||
if (tag_1 instanceof CompoundTag)
|
||||
if (tag_1 instanceof NbtCompound)
|
||||
{
|
||||
NbtIo.writeCompressed((CompoundTag) tag_1, Files.newOutputStream(path));
|
||||
NbtIo.writeCompressed((NbtCompound) tag_1, Files.newOutputStream(path));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ package carpet.script.bundled;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.script.argument.FileArgument;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
|
||||
import java.nio.file.Files;
|
||||
@@ -14,7 +14,7 @@ public abstract class Module
|
||||
public abstract String getCode();
|
||||
public abstract boolean isLibrary();
|
||||
|
||||
public static Tag getData(Module module)
|
||||
public static NbtElement getData(Module module)
|
||||
{
|
||||
Path dataFile = resolveResource(module);
|
||||
if (dataFile == null) return null;
|
||||
@@ -22,7 +22,7 @@ public abstract class Module
|
||||
synchronized (FileArgument.writeIOSync) { return FileArgument.readTag(dataFile); }
|
||||
}
|
||||
|
||||
public static void saveData(Module module, Tag globalState)
|
||||
public static void saveData(Module module, NbtElement globalState)
|
||||
{
|
||||
Path dataFile = resolveResource(module);
|
||||
if (dataFile == null) return;
|
||||
|
||||
@@ -50,18 +50,18 @@ import net.minecraft.command.argument.EntityArgumentType;
|
||||
import net.minecraft.command.argument.EntitySummonArgumentType;
|
||||
import net.minecraft.command.argument.GameProfileArgumentType;
|
||||
import net.minecraft.command.argument.IdentifierArgumentType;
|
||||
import net.minecraft.command.argument.ItemEnchantmentArgumentType;
|
||||
import net.minecraft.command.argument.EnchantmentArgumentType;
|
||||
import net.minecraft.command.argument.ItemSlotArgumentType;
|
||||
import net.minecraft.command.argument.ItemStackArgumentType;
|
||||
import net.minecraft.command.argument.MessageArgumentType;
|
||||
import net.minecraft.command.argument.MobEffectArgumentType;
|
||||
import net.minecraft.command.argument.NbtCompoundTagArgumentType;
|
||||
import net.minecraft.command.argument.StatusEffectArgumentType;
|
||||
import net.minecraft.command.argument.NbtCompoundArgumentType;
|
||||
import net.minecraft.command.argument.NbtPathArgumentType;
|
||||
import net.minecraft.command.argument.NbtTagArgumentType;
|
||||
import net.minecraft.command.argument.NbtElementArgumentType;
|
||||
import net.minecraft.command.argument.NumberRangeArgumentType;
|
||||
import net.minecraft.command.argument.ObjectiveArgumentType;
|
||||
import net.minecraft.command.argument.ObjectiveCriteriaArgumentType;
|
||||
import net.minecraft.command.argument.ParticleArgumentType;
|
||||
import net.minecraft.command.argument.ScoreboardObjectiveArgumentType;
|
||||
import net.minecraft.command.argument.ScoreboardCriterionArgumentType;
|
||||
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
||||
import net.minecraft.command.argument.RotationArgumentType;
|
||||
import net.minecraft.command.argument.ScoreHolderArgumentType;
|
||||
import net.minecraft.command.argument.ScoreboardSlotArgumentType;
|
||||
@@ -132,7 +132,7 @@ public abstract class CommandArgument
|
||||
false
|
||||
),
|
||||
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgumentType::blockPredicate,
|
||||
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getMinecraftServer().getTagManager(), BlockPredicateArgumentType.getBlockPredicate(c, p)), false
|
||||
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().getTagManager(), BlockPredicateArgumentType.getBlockPredicate(c, p)), false
|
||||
),
|
||||
new VanillaUnconfigurableArgument("teamcolor", ColorArgumentType::color,
|
||||
(c, p) -> {
|
||||
@@ -155,17 +155,17 @@ public abstract class CommandArgument
|
||||
new VanillaUnconfigurableArgument("entitytype", EntitySummonArgumentType::entitySummon,
|
||||
(c, p) -> ValueConversions.of(EntitySummonArgumentType.getEntitySummon(c, p)), SuggestionProviders.SUMMONABLE_ENTITIES
|
||||
),
|
||||
new VanillaUnconfigurableArgument("floatrange", NumberRangeArgumentType::method_30918,
|
||||
new VanillaUnconfigurableArgument("floatrange", NumberRangeArgumentType::floatRange,
|
||||
(c, p) -> ValueConversions.of(c.getArgument(p, NumberRange.FloatRange.class)), true
|
||||
),
|
||||
// function??
|
||||
|
||||
new PlayerProfileArgument(),
|
||||
new VanillaUnconfigurableArgument("intrange", NumberRangeArgumentType::numberRange,
|
||||
new VanillaUnconfigurableArgument("intrange", NumberRangeArgumentType::intRange,
|
||||
(c, p) -> ValueConversions.of(NumberRangeArgumentType.IntRangeArgumentType.getRangeArgument(c, p)), true
|
||||
),
|
||||
new VanillaUnconfigurableArgument("enchantment", ItemEnchantmentArgumentType::itemEnchantment,
|
||||
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getId(ItemEnchantmentArgumentType.getEnchantment(c, p))), false
|
||||
new VanillaUnconfigurableArgument("enchantment", EnchantmentArgumentType::enchantment,
|
||||
(c, p) -> ValueConversions.of(Registry.ENCHANTMENT.getId(EnchantmentArgumentType.getEnchantment(c, p))), false
|
||||
),
|
||||
// item_predicate ?? //same as item but accepts tags, not sure right now
|
||||
new SlotArgument(),
|
||||
@@ -175,22 +175,22 @@ public abstract class CommandArgument
|
||||
new VanillaUnconfigurableArgument("message", MessageArgumentType::message,
|
||||
(c, p) -> new FormattedTextValue(MessageArgumentType.getMessage(c, p)), true
|
||||
),
|
||||
new VanillaUnconfigurableArgument("effect", MobEffectArgumentType::mobEffect,
|
||||
(c, p) -> ValueConversions.of(Registry.STATUS_EFFECT.getId(MobEffectArgumentType.getMobEffect(c, p))),false
|
||||
new VanillaUnconfigurableArgument("effect", StatusEffectArgumentType::statusEffect,
|
||||
(c, p) -> ValueConversions.of(Registry.STATUS_EFFECT.getId(StatusEffectArgumentType.getStatusEffect(c, p))),false
|
||||
),
|
||||
new TagArgument(), // for nbt_compound_tag and nbt_tag
|
||||
new VanillaUnconfigurableArgument("path", NbtPathArgumentType::nbtPath,
|
||||
(c, p) -> StringValue.of(NbtPathArgumentType.getNbtPath(c, p).toString()), true
|
||||
),
|
||||
new VanillaUnconfigurableArgument("objective", ObjectiveArgumentType::objective,
|
||||
(c, p) -> ValueConversions.of(ObjectiveArgumentType.getObjective(c, p)), false
|
||||
new VanillaUnconfigurableArgument("objective", ScoreboardObjectiveArgumentType::scoreboardObjective,
|
||||
(c, p) -> ValueConversions.of(ScoreboardObjectiveArgumentType.getObjective(c, p)), false
|
||||
),
|
||||
new VanillaUnconfigurableArgument("criterion", ObjectiveCriteriaArgumentType::objectiveCriteria,
|
||||
(c, p) -> StringValue.of(ObjectiveCriteriaArgumentType.getCriteria(c, p).getName()), false
|
||||
new VanillaUnconfigurableArgument("criterion", ScoreboardCriterionArgumentType::scoreboardCriterion,
|
||||
(c, p) -> StringValue.of(ScoreboardCriterionArgumentType.getCriterion(c, p).getName()), false
|
||||
),
|
||||
// operation // not sure if we need it, you have scarpet for that
|
||||
new VanillaUnconfigurableArgument("particle", ParticleArgumentType::particle,
|
||||
(c, p) -> ValueConversions.of(ParticleArgumentType.getParticle(c, p)), false
|
||||
new VanillaUnconfigurableArgument("particle", ParticleEffectArgumentType::particleEffect,
|
||||
(c, p) -> ValueConversions.of(ParticleEffectArgumentType.getParticle(c, p)), false
|
||||
),
|
||||
|
||||
// resource / identifier section
|
||||
@@ -199,16 +199,16 @@ public abstract class CommandArgument
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getRecipeArgument(c, p).getId()), SuggestionProviders.ALL_RECIPES
|
||||
),
|
||||
new VanillaUnconfigurableArgument("advancement", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getAdvancementArgument(c, p).getId()), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getMinecraftServer().getAdvancementLoader().getAdvancements().stream().map(Advancement::getId), builder)
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getAdvancementArgument(c, p).getId()), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getServer().getAdvancementLoader().getAdvancements().stream().map(Advancement::getId), builder)
|
||||
),
|
||||
new VanillaUnconfigurableArgument("lootcondition", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( Registry.LOOT_CONDITION_TYPE.getId(IdentifierArgumentType.method_23727(c, p).getType())), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getMinecraftServer().getPredicateManager().getIds(), builder)
|
||||
(c, p) -> ValueConversions.of( Registry.LOOT_CONDITION_TYPE.getId(IdentifierArgumentType.getPredicateArgument(c, p).getType())), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getServer().getPredicateManager().getIds(), builder)
|
||||
),
|
||||
new VanillaUnconfigurableArgument("loottable", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getMinecraftServer().getLootManager().getTableIds(), builder)
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getServer().getLootManager().getTableIds(), builder)
|
||||
),
|
||||
new VanillaUnconfigurableArgument("attribute", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( Registry.ATTRIBUTE.getId(IdentifierArgumentType.method_27575(c, p))), (ctx, builder) -> CommandSource.suggestIdentifiers(Registry.ATTRIBUTE.getIds(), builder)
|
||||
(c, p) -> ValueConversions.of( Registry.ATTRIBUTE.getId(IdentifierArgumentType.getAttributeArgument(c, p))), (ctx, builder) -> CommandSource.suggestIdentifiers(Registry.ATTRIBUTE.getIds(), builder)
|
||||
),
|
||||
new VanillaUnconfigurableArgument("boss", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), BossBarCommand.SUGGESTION_PROVIDER
|
||||
@@ -220,7 +220,7 @@ public abstract class CommandArgument
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), SuggestionProviders.AVAILABLE_SOUNDS
|
||||
),
|
||||
new VanillaUnconfigurableArgument("storekey", IdentifierArgumentType::identifier,
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getMinecraftServer().getDataCommandStorage().getIds(), builder)
|
||||
(c, p) -> ValueConversions.of( IdentifierArgumentType.getIdentifier(c, p)), (ctx, builder) -> CommandSource.suggestIdentifiers(ctx.getSource().getServer().getDataCommandStorage().getIds(), builder)
|
||||
),
|
||||
|
||||
// default
|
||||
@@ -698,22 +698,22 @@ public abstract class CommandArgument
|
||||
boolean mapRequired;
|
||||
private TagArgument()
|
||||
{
|
||||
super("tag", NbtCompoundTagArgumentType.nbtCompound().getExamples(), false);
|
||||
super("tag", NbtCompoundArgumentType.nbtCompound().getExamples(), false);
|
||||
mapRequired = true;
|
||||
}
|
||||
@Override
|
||||
protected ArgumentType<?> getArgumentType()
|
||||
{
|
||||
return mapRequired?NbtCompoundTagArgumentType.nbtCompound(): NbtTagArgumentType.nbtTag();
|
||||
return mapRequired?NbtCompoundArgumentType.nbtCompound(): NbtElementArgumentType.nbtElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Value getValueFromContext(CommandContext<ServerCommandSource> context, String param) throws CommandSyntaxException
|
||||
{
|
||||
if (mapRequired)
|
||||
return new NBTSerializableValue(NbtCompoundTagArgumentType.getCompoundTag(context, param));
|
||||
return new NBTSerializableValue(NbtCompoundArgumentType.getNbtCompound(context, param));
|
||||
else
|
||||
return new NBTSerializableValue(NbtTagArgumentType.getTag(context, param));
|
||||
return new NBTSerializableValue(NbtElementArgumentType.getNbtElement(context, param));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -305,13 +305,13 @@ public class AppStoreManager
|
||||
public static boolean saveScriptToFile(ServerCommandSource source, String path, String appFileName, String code, boolean globalSavePath, boolean useTrash)
|
||||
{
|
||||
Path scriptLocation;
|
||||
if (globalSavePath && !source.getMinecraftServer().isDedicated()) // never happens, this is always called with globalSavePath being false
|
||||
if (globalSavePath && !source.getServer().isDedicated()) // never happens, this is always called with globalSavePath being false
|
||||
{ //cos config folder only is in clients
|
||||
scriptLocation = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts/appstore").toAbsolutePath().resolve(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptLocation = source.getMinecraftServer().getSavePath(WorldSavePath.ROOT).resolve("scripts").toAbsolutePath().resolve(appFileName);
|
||||
scriptLocation = source.getServer().getSavePath(WorldSavePath.ROOT).resolve("scripts").toAbsolutePath().resolve(appFileName);
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -384,7 +384,7 @@ public class AppStoreManager
|
||||
Files.copy(in, destination, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String getFullContentUrl(String original, StoreNode storeSource)
|
||||
{
|
||||
if (original.matches("^https?://.*$")) // We've got a full url here: Just use it
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BiomeInfo
|
||||
put("scale", (w, b) -> NumericValue.of(b.getScale()));
|
||||
put("features", (w, b) -> {
|
||||
|
||||
Registry<ConfiguredFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_FEATURE_WORLDGEN);
|
||||
Registry<ConfiguredFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_FEATURE_KEY);
|
||||
return ListValue.wrap(
|
||||
b.getGenerationSettings().getFeatures().stream().map(step ->
|
||||
ListValue.wrap(step.stream().map(cfp ->
|
||||
@@ -47,7 +47,7 @@ public class BiomeInfo
|
||||
);
|
||||
});
|
||||
put("structures", (w, b) -> {
|
||||
Registry<ConfiguredStructureFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN);
|
||||
Registry<ConfiguredStructureFeature<?,?>> registry = w.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY);
|
||||
return ListValue.wrap(b.getGenerationSettings().getStructureFeatures().stream().map(str -> ValueConversions.of(registry.getId(str.get()))));
|
||||
});
|
||||
}};
|
||||
|
||||
@@ -21,16 +21,16 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.argument.ParticleArgumentType;
|
||||
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.FloatTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtByte;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtDouble;
|
||||
import net.minecraft.nbt.NbtFloat;
|
||||
import net.minecraft.nbt.NbtInt;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -135,7 +135,7 @@ public class ShapeDispatcher
|
||||
if (!clientPlayers.isEmpty())
|
||||
{
|
||||
|
||||
ListTag tag = new ListTag();
|
||||
NbtList tag = new NbtList();
|
||||
int tagcount = 0;
|
||||
for (Pair<ExpiringShape, Map<String, Value>> s : shapes)
|
||||
{
|
||||
@@ -143,12 +143,12 @@ public class ShapeDispatcher
|
||||
if (tagcount++>1000)
|
||||
{
|
||||
tagcount = 0;
|
||||
Tag finalTag = tag;
|
||||
NbtElement finalTag = tag;
|
||||
clientPlayers.forEach( p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
|
||||
tag = new ListTag();
|
||||
tag = new NbtList();
|
||||
}
|
||||
}
|
||||
Tag finalTag = tag;
|
||||
NbtElement finalTag = tag;
|
||||
if (tag.size() > 0) clientPlayers.forEach( p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
|
||||
}
|
||||
if (!alternativePlayers.isEmpty())
|
||||
@@ -166,7 +166,7 @@ public class ShapeDispatcher
|
||||
return particle;
|
||||
try
|
||||
{
|
||||
particle = ParticleArgumentType.readParameters(new StringReader(name));
|
||||
particle = ParticleEffectArgumentType.readParameters(new StringReader(name));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
|
||||
// client
|
||||
public static ExpiringShape fromTag(CompoundTag tag)
|
||||
public static ExpiringShape fromTag(NbtCompound tag)
|
||||
{
|
||||
Map<String, Value> options = new HashMap<>();
|
||||
for (String key : tag.getKeys())
|
||||
@@ -277,11 +277,11 @@ public class ShapeDispatcher
|
||||
|
||||
protected ExpiringShape() { }
|
||||
|
||||
public static CompoundTag toTag(Map<String, Value> params)
|
||||
public static NbtCompound toTag(Map<String, Value> params)
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
params.forEach((k, v) -> {
|
||||
Tag valTag = Param.of.get(k).toTag(v);
|
||||
NbtElement valTag = Param.of.get(k).toTag(v);
|
||||
if (valTag != null) tag.put(k, valTag);
|
||||
});
|
||||
return tag;
|
||||
@@ -326,7 +326,7 @@ public class ShapeDispatcher
|
||||
|
||||
key = 0;
|
||||
followEntity = -1;
|
||||
shapeDimension = RegistryKey.of(Registry.DIMENSION, new Identifier(options.get("dim").getString()));
|
||||
shapeDimension = RegistryKey.of(Registry.WORLD_KEY, new Identifier(options.get("dim").getString()));
|
||||
if (options.containsKey("follow"))
|
||||
{
|
||||
followEntity = NumericValue.asNumber(options.getOrDefault("follow", optional.get("follow"))).getInt();
|
||||
@@ -902,9 +902,9 @@ public class ShapeDispatcher
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public abstract Tag toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
|
||||
public abstract NbtElement toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
|
||||
public abstract Value validate(Map<String, Value> options, MinecraftServer server, Value value); // makes sure the value is proper
|
||||
public abstract Value decode(Tag tag);
|
||||
public abstract Value decode(NbtElement tag);
|
||||
}
|
||||
|
||||
public abstract static class StringParam extends Param
|
||||
@@ -912,8 +912,8 @@ public class ShapeDispatcher
|
||||
protected StringParam(String id) { super(id); }
|
||||
|
||||
@Override
|
||||
public Tag toTag(Value value) { return StringTag.of(value.getString()); }
|
||||
public Value decode(Tag tag) { return new StringValue(tag.asString()); }
|
||||
public NbtElement toTag(Value value) { return NbtString.of(value.getString()); }
|
||||
public Value decode(NbtElement tag) { return new StringValue(tag.asString()); }
|
||||
}
|
||||
public static class TextParam extends StringParam
|
||||
{
|
||||
@@ -943,15 +943,15 @@ public class ShapeDispatcher
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(Value value)
|
||||
public NbtElement toTag(Value value)
|
||||
{
|
||||
if (!(value instanceof FormattedTextValue))
|
||||
value = new FormattedTextValue(new LiteralText(value.getString()));
|
||||
return StringTag.of(((FormattedTextValue)value).serialize());
|
||||
return NbtString.of(((FormattedTextValue)value).serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value decode(Tag tag)
|
||||
public Value decode(NbtElement tag)
|
||||
{
|
||||
return FormattedTextValue.deserialize(tag.asString());
|
||||
}
|
||||
@@ -1016,24 +1016,24 @@ public class ShapeDispatcher
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(Value value)
|
||||
public NbtElement toTag(Value value)
|
||||
{
|
||||
return ByteTag.of(value.getBoolean());
|
||||
return NbtByte.of(value.getBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value decode(Tag tag)
|
||||
public Value decode(NbtElement tag)
|
||||
{
|
||||
return BooleanValue.of(((ByteTag) tag).getByte() > 0);
|
||||
return BooleanValue.of(((NbtByte) tag).byteValue() > 0);
|
||||
}
|
||||
}
|
||||
public static class FloatParam extends NumericParam
|
||||
{
|
||||
protected FloatParam(String id) { super(id); }
|
||||
@Override
|
||||
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
}
|
||||
|
||||
public static abstract class PositiveParam extends NumericParam
|
||||
@@ -1050,27 +1050,27 @@ public class ShapeDispatcher
|
||||
{
|
||||
protected PositiveFloatParam(String id) { super(id); }
|
||||
@Override
|
||||
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
|
||||
}
|
||||
public static class PositiveIntParam extends PositiveParam
|
||||
{
|
||||
protected PositiveIntParam(String id) { super(id); }
|
||||
@Override
|
||||
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
|
||||
}
|
||||
public static class NonNegativeIntParam extends NumericParam
|
||||
{
|
||||
protected NonNegativeIntParam(String id) { super(id); }
|
||||
@Override
|
||||
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
@Override public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
|
||||
{
|
||||
Value ret = super.validate(options, server, value);
|
||||
@@ -1082,9 +1082,9 @@ public class ShapeDispatcher
|
||||
{
|
||||
protected NonNegativeFloatParam(String id) { super(id); }
|
||||
@Override
|
||||
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
|
||||
@Override public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
|
||||
{
|
||||
Value ret = super.validate(options, server, value);
|
||||
@@ -1149,9 +1149,9 @@ public class ShapeDispatcher
|
||||
throw new InternalExpressionException("'"+p.id+"' requires a triple, block or entity to indicate position");
|
||||
}
|
||||
|
||||
public Value decode(Tag tag)
|
||||
public Value decode(NbtElement tag)
|
||||
{
|
||||
ListTag ctag = (ListTag)tag;
|
||||
NbtList ctag = (NbtList)tag;
|
||||
return ListValue.of(
|
||||
new NumericValue(ctag.getDouble(0)),
|
||||
new NumericValue(ctag.getDouble(1)),
|
||||
@@ -1159,13 +1159,13 @@ public class ShapeDispatcher
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public Tag toTag(Value value)
|
||||
public NbtElement toTag(Value value)
|
||||
{
|
||||
List<Value> lv = ((ListValue)value).getItems();
|
||||
ListTag tag = new ListTag();
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
|
||||
NbtList tag = new NbtList();
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1187,13 +1187,13 @@ public class ShapeDispatcher
|
||||
return ListValue.wrap(points);
|
||||
}
|
||||
|
||||
public Value decode(Tag tag)
|
||||
public Value decode(NbtElement tag)
|
||||
{
|
||||
ListTag ltag = (ListTag)tag;
|
||||
NbtList ltag = (NbtList)tag;
|
||||
List<Value> points = new ArrayList<>();
|
||||
for (int i=0, ll = ltag.size(); i<ll; i++)
|
||||
{
|
||||
ListTag ptag = ltag.getList(i);
|
||||
NbtList ptag = ltag.getList(i);
|
||||
points.add(ListValue.of(
|
||||
new NumericValue(ptag.getDouble(0)),
|
||||
new NumericValue(ptag.getDouble(1)),
|
||||
@@ -1203,17 +1203,17 @@ public class ShapeDispatcher
|
||||
return ListValue.wrap(points);
|
||||
}
|
||||
@Override
|
||||
public Tag toTag(Value pointsValue)
|
||||
public NbtElement toTag(Value pointsValue)
|
||||
{
|
||||
List<Value> lv = ((ListValue)pointsValue).getItems();
|
||||
ListTag ltag = new ListTag();
|
||||
NbtList ltag = new NbtList();
|
||||
for (Value value : lv)
|
||||
{
|
||||
List<Value> coords = ((ListValue)value).getItems();
|
||||
ListTag tag = new ListTag();
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
|
||||
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
|
||||
NbtList tag = new NbtList();
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
|
||||
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
|
||||
ltag.add(tag);
|
||||
}
|
||||
return ltag;
|
||||
@@ -1228,9 +1228,9 @@ public class ShapeDispatcher
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
|
||||
}
|
||||
|
||||
public static class EntityParam extends Param
|
||||
@@ -1239,22 +1239,22 @@ public class ShapeDispatcher
|
||||
protected EntityParam(String id) { super(id); }
|
||||
|
||||
@Override
|
||||
public Tag toTag(Value value)
|
||||
public NbtElement toTag(Value value)
|
||||
{
|
||||
return IntTag.of(NumericValue.asNumber(value, id).getInt());
|
||||
return NbtInt.of(NumericValue.asNumber(value, id).getInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
|
||||
{
|
||||
if (value instanceof EntityValue) return new NumericValue(((EntityValue) value).getEntity().getEntityId());
|
||||
if (value instanceof EntityValue) return new NumericValue(((EntityValue) value).getEntity().getId());
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, value);
|
||||
if (player == null)
|
||||
throw new InternalExpressionException(id+" parameter needs to represent an entity or player");
|
||||
return new NumericValue(player.getEntityId());
|
||||
return new NumericValue(player.getId());
|
||||
}
|
||||
|
||||
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
|
||||
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
|
||||
}
|
||||
|
||||
private static boolean isStraight(Vec3d from, Vec3d to, double density)
|
||||
@@ -1328,7 +1328,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
|
||||
if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density);
|
||||
Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(distance));
|
||||
Vec3d incvec = to.subtract(from).multiply(2*density/Math.sqrt(distance));
|
||||
|
||||
for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
|
||||
delta.lengthSquared()<distance;
|
||||
|
||||
@@ -8,20 +8,21 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -30,6 +31,7 @@ import java.util.function.BiFunction;
|
||||
public class ShapesRenderer
|
||||
{
|
||||
private final Map<RegistryKey<World>, Long2ObjectOpenHashMap<RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> shapes;
|
||||
private final Map<RegistryKey<World>, Long2ObjectOpenHashMap<RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> labels;
|
||||
private MinecraftClient client;
|
||||
|
||||
private Map<String, BiFunction<MinecraftClient, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >>> renderedShapes
|
||||
@@ -46,34 +48,33 @@ public class ShapesRenderer
|
||||
{
|
||||
this.client = minecraftClient;
|
||||
shapes = new HashMap<>();
|
||||
labels = new HashMap<>();
|
||||
}
|
||||
|
||||
public void render(Camera camera, float partialTick)
|
||||
public void render(MatrixStack matrices, Camera camera, float partialTick)
|
||||
{
|
||||
CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
//Camera camera = this.client.gameRenderer.getCamera();
|
||||
ClientWorld iWorld = this.client.world;
|
||||
RegistryKey<World> dimensionType = iWorld.getRegistryKey();
|
||||
if (shapes.get(dimensionType) == null || shapes.get(dimensionType).isEmpty()) return;
|
||||
if ((shapes.get(dimensionType) == null || shapes.get(dimensionType).isEmpty()) &&
|
||||
(labels.get(dimensionType) == null || labels.get(dimensionType).isEmpty())) return;
|
||||
long currentTime = client.world.getTime();
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.depthFunc(515);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
// too bright
|
||||
//RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
|
||||
//RenderSystem.shadeModel(7425);
|
||||
RenderSystem.shadeModel(GL11.GL_FLAT);
|
||||
RenderSystem.enableAlphaTest();
|
||||
RenderSystem.alphaFunc(GL11.GL_GREATER, 0.003f);
|
||||
// meh
|
||||
//RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.disableLighting();
|
||||
RenderSystem.depthMask(false);
|
||||
// causes water to vanish
|
||||
//RenderSystem.depthMask(true);
|
||||
//RenderSystem.polygonOffset(-3f, -3f);
|
||||
//RenderSystem.enablePolygonOffset();
|
||||
//Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferBuilder = tessellator.getBuffer();
|
||||
@@ -83,49 +84,48 @@ public class ShapesRenderer
|
||||
double cameraY = camera.getPos().y;
|
||||
double cameraZ = camera.getPos().z;
|
||||
|
||||
synchronized (shapes)
|
||||
{
|
||||
if (shapes.size() != 0) { synchronized (shapes) {
|
||||
shapes.get(dimensionType).long2ObjectEntrySet().removeIf(
|
||||
entry -> entry.getValue().isExpired(currentTime)
|
||||
);
|
||||
MatrixStack matrixStack = RenderSystem.getModelViewStack();
|
||||
matrixStack.push();
|
||||
matrixStack.method_34425(matrices.peek().getModel());
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
shapes.get(dimensionType).values().forEach(
|
||||
s ->
|
||||
{
|
||||
if ( !s.lastCall() && s.shouldRender(dimensionType))
|
||||
s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
}
|
||||
);
|
||||
//lines
|
||||
shapes.get(dimensionType).values().forEach(
|
||||
// lines
|
||||
RenderSystem.lineWidth(0.5F);
|
||||
shapes.get(dimensionType).values().forEach( s -> {
|
||||
if (s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
});
|
||||
// faces
|
||||
RenderSystem.lineWidth(0.1F);
|
||||
shapes.get(dimensionType).values().forEach(s -> {
|
||||
if (s.shouldRender(dimensionType)) s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
});
|
||||
RenderSystem.lineWidth(1.0F);
|
||||
matrixStack.pop();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
s -> {
|
||||
if ( !s.lastCall() && s.shouldRender(dimensionType))
|
||||
s.renderLines(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
}
|
||||
}}
|
||||
if (labels.size() != 0) { synchronized (labels)
|
||||
{
|
||||
labels.get(dimensionType).long2ObjectEntrySet().removeIf(
|
||||
entry -> entry.getValue().isExpired(currentTime)
|
||||
);
|
||||
//texts
|
||||
// maybe we can move it laster to lines and makes sure we don't overpass and don't have blinky transparency problems
|
||||
shapes.get(dimensionType).values().forEach(
|
||||
s ->
|
||||
{
|
||||
if ( s.lastCall() && s.shouldRender(dimensionType))
|
||||
s.renderLines(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
labels.get(dimensionType).values().forEach(s -> {
|
||||
if (s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
|
||||
});
|
||||
}}
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.lineWidth(1.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.shadeModel(7424);
|
||||
CarpetProfiler.end_current_section(token);
|
||||
}
|
||||
|
||||
public void addShapes(ListTag tag)
|
||||
public void addShapes(NbtList tag)
|
||||
{
|
||||
CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
for (int i=0, count = tag.size(); i < count; i++)
|
||||
@@ -135,7 +135,7 @@ public class ShapesRenderer
|
||||
CarpetProfiler.end_current_section(token);
|
||||
}
|
||||
|
||||
public void addShape(CompoundTag tag)
|
||||
public void addShape(NbtCompound tag)
|
||||
{
|
||||
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
|
||||
if (shape == null) return;
|
||||
@@ -150,16 +150,18 @@ public class ShapesRenderer
|
||||
RenderedShape<?> rshape = shapeFactory.apply(client, shape);
|
||||
RegistryKey<World> dim = shape.shapeDimension;
|
||||
long key = rshape.key();
|
||||
synchronized (shapes)
|
||||
Map<RegistryKey<World>, Long2ObjectOpenHashMap<RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> container =
|
||||
rshape.stageDeux()?labels:shapes;
|
||||
synchronized (container)
|
||||
{
|
||||
RenderedShape<?> existing = shapes.computeIfAbsent(dim, d -> new Long2ObjectOpenHashMap<>()).get(key);
|
||||
RenderedShape<?> existing = container.computeIfAbsent(dim, d -> new Long2ObjectOpenHashMap<>()).get(key);
|
||||
if (existing != null)
|
||||
{ // promoting previous shape
|
||||
existing.promoteWith(rshape);
|
||||
}
|
||||
else
|
||||
{
|
||||
shapes.get(dim).put(key, rshape);
|
||||
container.get(dim).put(key, rshape);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,6 +172,10 @@ public class ShapesRenderer
|
||||
{
|
||||
shapes.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
}
|
||||
synchronized (labels)
|
||||
{
|
||||
labels.values().forEach(Long2ObjectOpenHashMap::clear);
|
||||
}
|
||||
}
|
||||
|
||||
public void renewShapes()
|
||||
@@ -177,9 +183,11 @@ public class ShapesRenderer
|
||||
CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, "Scarpet client", CarpetProfiler.TYPE.GENERAL);
|
||||
synchronized (shapes)
|
||||
{
|
||||
shapes.values().forEach(el -> el.values().forEach(shape -> {
|
||||
shape.expiryTick++;
|
||||
}));
|
||||
shapes.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
}
|
||||
synchronized (labels)
|
||||
{
|
||||
labels.values().forEach(el -> el.values().forEach(shape -> shape.expiryTick++));
|
||||
}
|
||||
CarpetProfiler.end_current_section(token);
|
||||
}
|
||||
@@ -190,7 +198,7 @@ public class ShapesRenderer
|
||||
protected MinecraftClient client;
|
||||
long expiryTick;
|
||||
double renderEpsilon = 0;
|
||||
public abstract void renderLines(Tessellator tessellator, BufferBuilder builder, double cx, double cy, double cz, float partialTick );
|
||||
public abstract void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder builder, double cx, double cy, double cz, float partialTick );
|
||||
public void renderFaces(Tessellator tessellator, BufferBuilder builder, double cx, double cy, double cz, float partialTick ) {}
|
||||
protected RenderedShape(MinecraftClient client, T shape)
|
||||
{
|
||||
@@ -213,10 +221,9 @@ public class ShapesRenderer
|
||||
if (shape.followEntity <=0 ) return true;
|
||||
if (client.world == null) return false;
|
||||
if (client.world.getRegistryKey() != dim) return false;
|
||||
if (client.world.getEntityById(shape.followEntity) == null) return false;
|
||||
return true;
|
||||
return client.world.getEntityById(shape.followEntity) != null;
|
||||
}
|
||||
public boolean lastCall()
|
||||
public boolean stageDeux()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -236,26 +243,22 @@ public class ShapesRenderer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderLines(Tessellator tessellator, BufferBuilder builder, double cx, double cy, double cz, float partialTick)
|
||||
public void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder builder, double cx, double cy, double cz, float partialTick)
|
||||
{
|
||||
if (shape.a == 0.0) return;
|
||||
Vec3d v1 = shape.relativiseRender(client.world, shape.pos, partialTick);
|
||||
Camera camera1 = client.gameRenderer.getCamera();
|
||||
TextRenderer textRenderer = client.textRenderer;
|
||||
double d = camera1.getPos().x;
|
||||
double e = camera1.getPos().y;
|
||||
double f = camera1.getPos().z;
|
||||
if (shape.doublesided)
|
||||
RenderSystem.disableCull();
|
||||
else
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translatef((float)(v1.x - d), (float)(v1.y - e), (float)(v1.z - f));
|
||||
RenderSystem.normal3f(0.0F, 1.0F, 0.0F);
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(v1.x - cx,v1.y - cy,v1.z - cz);
|
||||
if (shape.facing == null)
|
||||
{
|
||||
RenderSystem.multMatrix(new Matrix4f(camera1.getRotation()));
|
||||
//matrices.method_34425(new Matrix4f(camera1.getRotation()));
|
||||
matrices.multiply(camera1.getRotation());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -264,38 +267,31 @@ public class ShapesRenderer
|
||||
case NORTH:
|
||||
break;
|
||||
case SOUTH:
|
||||
RenderSystem.rotatef(180.0f, 0.0f, 1.0f, 0.0f);
|
||||
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180));
|
||||
break;
|
||||
case EAST:
|
||||
RenderSystem.rotatef(270.0f, 0.0f, 1.0f, 0.0f);
|
||||
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(270));
|
||||
break;
|
||||
case WEST:
|
||||
RenderSystem.rotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
||||
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(90));
|
||||
break;
|
||||
case UP:
|
||||
RenderSystem.rotatef(90.0f, 1.0f, 0.0f, 0.0f);
|
||||
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90));
|
||||
break;
|
||||
case DOWN:
|
||||
RenderSystem.rotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90));
|
||||
break;
|
||||
}
|
||||
}
|
||||
RenderSystem.scalef(shape.size* 0.0025f, -shape.size*0.0025f, shape.size*0.0025f);
|
||||
if (shape.tilt!=0.0f)
|
||||
{
|
||||
RenderSystem.rotatef(shape.tilt, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
if (shape.lean!=0.0f)
|
||||
{
|
||||
RenderSystem.rotatef(shape.lean, 1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
if (shape.turn!=0.0f)
|
||||
{
|
||||
RenderSystem.rotatef(shape.turn, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
RenderSystem.translatef(-10*shape.indent, -10*shape.height-9, (float) (-10*renderEpsilon)-10*shape.raise);
|
||||
matrices.scale(shape.size* 0.0025f, -shape.size*0.0025f, shape.size*0.0025f);
|
||||
//RenderSystem.scalef(shape.size* 0.0025f, -shape.size*0.0025f, shape.size*0.0025f);
|
||||
if (shape.tilt!=0.0f) matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(shape.tilt));
|
||||
if (shape.lean!=0.0f) matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(shape.lean));
|
||||
if (shape.turn!=0.0f) matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(shape.turn));
|
||||
matrices.translate(-10*shape.indent, -10*shape.height-9, (-10*renderEpsilon)-10*shape.raise);
|
||||
//if (visibleThroughWalls) RenderSystem.disableDepthTest();
|
||||
RenderSystem.scalef(-1.0F, 1.0F, 1.0F);
|
||||
matrices.scale(-1, 1, 1);
|
||||
//RenderSystem.applyModelViewMatrix(); // passed matrix directly to textRenderer.draw, not AffineTransformation.identity().getMatrix(),
|
||||
|
||||
float text_x = 0;
|
||||
if (shape.align == 0)
|
||||
@@ -306,19 +302,15 @@ public class ShapesRenderer
|
||||
{
|
||||
text_x = (float)(-textRenderer.getWidth(shape.value.getString()));
|
||||
}
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
|
||||
textRenderer.draw(shape.value, text_x, 0.0F, shape.textcolor, false, AffineTransformation.identity().getMatrix(), immediate, false, shape.textbck, 15728880);
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(builder);
|
||||
textRenderer.draw(shape.value, text_x, 0.0F, shape.textcolor, false, matrices.peek().getModel(), immediate, false, shape.textbck, 15728880);
|
||||
immediate.draw();
|
||||
RenderSystem.popMatrix();
|
||||
matrices.pop();
|
||||
RenderSystem.enableCull();
|
||||
//RenderSystem.enableDepthTest();
|
||||
//RenderSystem.depthFunc(515);
|
||||
//RenderSystem.enableAlphaTest();
|
||||
//RenderSystem.alphaFunc(GL11.GL_GREATER, 0.003f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lastCall()
|
||||
public boolean stageDeux()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -347,12 +339,11 @@ public class ShapesRenderer
|
||||
|
||||
}
|
||||
@Override
|
||||
public void renderLines(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
public void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
{
|
||||
if (shape.a == 0.0) return;
|
||||
Vec3d v1 = shape.relativiseRender(client.world, shape.from, partialTick);
|
||||
Vec3d v2 = shape.relativiseRender(client.world, shape.to, partialTick);
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
drawBoxWireGLLines(tessellator, bufferBuilder,
|
||||
(float)(v1.x-cx-renderEpsilon), (float)(v1.y-cy-renderEpsilon), (float)(v1.z-cz-renderEpsilon),
|
||||
(float)(v2.x-cx+renderEpsilon), (float)(v2.y-cy+renderEpsilon), (float)(v2.z-cz+renderEpsilon),
|
||||
@@ -366,7 +357,8 @@ public class ShapesRenderer
|
||||
if (shape.fa == 0.0) return;
|
||||
Vec3d v1 = shape.relativiseRender(client.world, shape.from, partialTick);
|
||||
Vec3d v2 = shape.relativiseRender(client.world, shape.to, partialTick);
|
||||
RenderSystem.lineWidth(1.0F);
|
||||
// consider using built-ins
|
||||
//DebugRenderer.drawBox(new Box(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z), 0.5f, 0.5f, 0.5f, 0.5f);//shape.r, shape.g, shape.b, shape.a);
|
||||
drawBoxFaces(tessellator, bufferBuilder,
|
||||
(float)(v1.x-cx-renderEpsilon), (float)(v1.y-cy-renderEpsilon), (float)(v1.z-cz-renderEpsilon),
|
||||
(float)(v2.x-cx+renderEpsilon), (float)(v2.y-cy+renderEpsilon), (float)(v2.z-cz+renderEpsilon),
|
||||
@@ -384,11 +376,10 @@ public class ShapesRenderer
|
||||
super(client, (ShapeDispatcher.Line)shape);
|
||||
}
|
||||
@Override
|
||||
public void renderLines(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
public void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
{
|
||||
Vec3d v1 = shape.relativiseRender(client.world, shape.from, partialTick);
|
||||
Vec3d v2 = shape.relativiseRender(client.world, shape.to, partialTick);
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
drawLine(tessellator, bufferBuilder,
|
||||
(float)(v1.x-cx-renderEpsilon), (float)(v1.y-cy-renderEpsilon), (float)(v1.z-cz-renderEpsilon),
|
||||
(float)(v2.x-cx+renderEpsilon), (float)(v2.y-cy+renderEpsilon), (float)(v2.z-cz+renderEpsilon),
|
||||
@@ -404,11 +395,10 @@ public class ShapesRenderer
|
||||
super(client, (ShapeDispatcher.Sphere)shape);
|
||||
}
|
||||
@Override
|
||||
public void renderLines(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
public void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
{
|
||||
if (shape.a == 0.0) return;
|
||||
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
drawSphereWireframe(tessellator, bufferBuilder,
|
||||
(float)(vc.x-cx), (float)(vc.y-cy), (float)(vc.z-cz),
|
||||
(float)(shape.radius+renderEpsilon), shape.subdivisions,
|
||||
@@ -419,7 +409,6 @@ public class ShapesRenderer
|
||||
{
|
||||
if (shape.fa == 0.0) return;
|
||||
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
|
||||
RenderSystem.lineWidth(1.0f);
|
||||
drawSphereFaces(tessellator, bufferBuilder,
|
||||
(float)(vc.x-cx), (float)(vc.y-cy), (float)(vc.z-cz),
|
||||
(float)(shape.radius+renderEpsilon), shape.subdivisions,
|
||||
@@ -434,11 +423,10 @@ public class ShapesRenderer
|
||||
super(client, (ShapeDispatcher.Cylinder)shape);
|
||||
}
|
||||
@Override
|
||||
public void renderLines(Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
public void renderLines(MatrixStack matrices, Tessellator tessellator, BufferBuilder bufferBuilder, double cx, double cy, double cz, float partialTick)
|
||||
{
|
||||
if (shape.a == 0.0) return;
|
||||
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
double dir = MathHelper.sign(shape.height);
|
||||
drawCylinderWireframe(tessellator, bufferBuilder,
|
||||
(float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon),
|
||||
@@ -452,7 +440,6 @@ public class ShapesRenderer
|
||||
{
|
||||
if (shape.fa == 0.0) return;
|
||||
Vec3d vc = shape.relativiseRender(client.world, shape.center, partialTick);
|
||||
RenderSystem.lineWidth(1.0f);
|
||||
double dir = MathHelper.sign(shape.height);
|
||||
drawCylinderFaces(tessellator, bufferBuilder,
|
||||
(float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon),
|
||||
@@ -465,7 +452,7 @@ public class ShapesRenderer
|
||||
// some raw shit
|
||||
|
||||
public static void drawLine(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) {
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
|
||||
tessellator.draw();
|
||||
@@ -478,7 +465,7 @@ public class ShapesRenderer
|
||||
boolean xthick, boolean ythick, boolean zthick,
|
||||
float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2)
|
||||
{
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
|
||||
if (xthick)
|
||||
{
|
||||
builder.vertex(x1, y1, z1).color(red1, grn2, blu2, alpha).next();
|
||||
@@ -531,7 +518,7 @@ public class ShapesRenderer
|
||||
boolean xthick, boolean ythick, boolean zthick,
|
||||
float red1, float grn1, float blu1, float alpha)
|
||||
{
|
||||
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
|
||||
if (xthick && ythick)
|
||||
{
|
||||
@@ -606,8 +593,8 @@ public class ShapesRenderer
|
||||
for (int dh = 0; dh < hsteps; dh++)
|
||||
{
|
||||
float hh = dh*hstep;
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
for (int i = 0; i <= num_steps360+1; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
float x = r * MathHelper.cos(theta);
|
||||
@@ -622,7 +609,7 @@ public class ShapesRenderer
|
||||
{
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
float theta = step * i;
|
||||
float x = r * MathHelper.cos(theta);
|
||||
|
||||
@@ -632,12 +619,13 @@ public class ShapesRenderer
|
||||
builder.vertex(cx + x, cy + 0, cz - z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + x, cy + h, cz - z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx - x, cy + h, cz + z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx - x, cy + 0, cz + z).color(red, grn, blu, alpha).next();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
@@ -655,7 +643,7 @@ public class ShapesRenderer
|
||||
for (int dh = 0; dh < hsteps; dh++)
|
||||
{
|
||||
float hh = dh * hstep;
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
@@ -671,7 +659,7 @@ public class ShapesRenderer
|
||||
{
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
float theta = step * i;
|
||||
float y = r * MathHelper.cos(theta);
|
||||
|
||||
@@ -686,7 +674,7 @@ public class ShapesRenderer
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
@@ -703,7 +691,7 @@ public class ShapesRenderer
|
||||
for (int dh = 0; dh < hsteps; dh++)
|
||||
{
|
||||
float hh = dh * hstep;
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
@@ -718,7 +706,7 @@ public class ShapesRenderer
|
||||
{
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
float theta = step * i;
|
||||
float x = r * MathHelper.cos(theta);
|
||||
|
||||
@@ -733,7 +721,7 @@ public class ShapesRenderer
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps180; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
@@ -760,7 +748,7 @@ public class ShapesRenderer
|
||||
if (axis == Direction.Axis.Y)
|
||||
{
|
||||
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -772,7 +760,7 @@ public class ShapesRenderer
|
||||
tessellator.draw();
|
||||
if (!isFlat)
|
||||
{
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx, cy+h, cz).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -783,14 +771,20 @@ public class ShapesRenderer
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); // quad strip to quads
|
||||
float xp = r * 1;
|
||||
float zp = r * 0;
|
||||
for (int i = 1; i <= num_steps360; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
float x = r * MathHelper.cos(theta);
|
||||
float z = r * MathHelper.sin(theta);
|
||||
builder.vertex(cx + x, cy + 0, cz + z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + xp, cy + 0, cz + zp).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + xp, cy + h, cz + zp).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + x, cy + h, cz + z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + x, cy + 0, cz + z).color(red, grn, blu, alpha).next();
|
||||
xp = x;
|
||||
zp = z;
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
@@ -798,7 +792,7 @@ public class ShapesRenderer
|
||||
}
|
||||
else if (axis == Direction.Axis.X)
|
||||
{
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -810,7 +804,7 @@ public class ShapesRenderer
|
||||
tessellator.draw();
|
||||
if (!isFlat)
|
||||
{
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx+h, cy, cz).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -821,21 +815,27 @@ public class ShapesRenderer
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); // quad strip to quads
|
||||
float yp = r * 1;
|
||||
float zp = r * 0;
|
||||
for (int i = 1; i <= num_steps360; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
float y = r * MathHelper.cos(theta);
|
||||
float z = r * MathHelper.sin(theta);
|
||||
builder.vertex(cx + 0, cy + y, cz + z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + 0, cy + yp, cz + zp).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + h, cy + yp, cz + zp).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + h, cy + y, cz + z).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + 0, cy + y, cz + z).color(red, grn, blu, alpha).next();
|
||||
yp = y;
|
||||
zp = z;
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
else if (axis == Direction.Axis.Z)
|
||||
{
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx, cy, cz).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -847,7 +847,7 @@ public class ShapesRenderer
|
||||
tessellator.draw();
|
||||
if (!isFlat)
|
||||
{
|
||||
builder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
|
||||
builder.vertex(cx, cy, cz+h).color(red, grn, blu, alpha).next();
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
@@ -858,14 +858,20 @@ public class ShapesRenderer
|
||||
}
|
||||
tessellator.draw();
|
||||
|
||||
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); // quad strip to quads
|
||||
float xp = r;
|
||||
float yp = 0;
|
||||
for (int i = 1; i <= num_steps360; i++)
|
||||
{
|
||||
float theta = step * i;
|
||||
float x = r * MathHelper.cos(theta);
|
||||
float y = r * MathHelper.sin(theta);
|
||||
builder.vertex(cx + x, cy + y, cz + 0).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + xp, cy + yp, cz + 0).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + xp, cy + yp, cz + h).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + x, cy + y, cz + h).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(cx + x, cy + y, cz + 0).color(red, grn, blu, alpha).next();
|
||||
xp = x;
|
||||
yp = y;
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
@@ -879,10 +885,10 @@ public class ShapesRenderer
|
||||
{
|
||||
float step = (float)Math.PI / (subd/2);
|
||||
int num_steps180 = (int)(Math.PI / step)+1;
|
||||
int num_steps360 = (int)(2*Math.PI / step);
|
||||
int num_steps360 = (int)(2*Math.PI / step)+1;
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
float theta = step * i ;
|
||||
for (int j = 0; j <= num_steps180; j++)
|
||||
{
|
||||
@@ -896,7 +902,7 @@ public class ShapesRenderer
|
||||
}
|
||||
for (int j = 0; j <= num_steps180; j++)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR); // line loop to line strip
|
||||
float phi = step * j ;
|
||||
|
||||
for (int i = 0; i <= num_steps360; i++)
|
||||
@@ -925,7 +931,12 @@ public class ShapesRenderer
|
||||
{
|
||||
float theta = i * step;
|
||||
float thetaprime = theta+step;
|
||||
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
|
||||
builder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); // quad strip to quads
|
||||
float xb = 0;
|
||||
float zb = 0;
|
||||
float xbp = 0;
|
||||
float zbp = 0;
|
||||
float yp = r;
|
||||
for (int j = 0; j <= num_steps180; j++)
|
||||
{
|
||||
float phi = j * step;
|
||||
@@ -934,8 +945,15 @@ public class ShapesRenderer
|
||||
float y = r * MathHelper.cos(phi);
|
||||
float xp = r * MathHelper.sin(phi) * MathHelper.cos(thetaprime);
|
||||
float zp = r * MathHelper.sin(phi) * MathHelper.sin(thetaprime);
|
||||
builder.vertex(x + cx, y + cy, z + cz).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(xb + cx, yp + cy, zb + cz).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(xbp + cx, yp + cy, zbp + cz).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(xp + cx, y + cy, zp + cz).color(red, grn, blu, alpha).next();
|
||||
builder.vertex(x + cx, y + cy, z + cz).color(red, grn, blu, alpha).next();
|
||||
xb = x;
|
||||
zb = z;
|
||||
xbp = xp;
|
||||
zbp = zp;
|
||||
yp = y;
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package carpet.script.utils;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import com.mojang.brigadier.ResultConsumer;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -41,7 +40,7 @@ public class SnoopyCommandSource extends ServerCommandSource
|
||||
public SnoopyCommandSource(ServerCommandSource original, Text[] error, List<Text> chatOutput)
|
||||
{
|
||||
super(CommandOutput.DUMMY, original.getPosition(), original.getRotation(), original.getWorld(), CarpetSettings.runPermissionLevel,
|
||||
original.getName(), original.getDisplayName(), original.getMinecraftServer(), original.getEntity(), false,
|
||||
original.getName(), original.getDisplayName(), original.getServer(), original.getEntity(), false,
|
||||
(ctx, succ, res) -> { }, EntityAnchorArgumentType.EntityAnchor.FEET);
|
||||
this.output = CommandOutput.DUMMY;
|
||||
this.position = original.getPosition();
|
||||
@@ -49,7 +48,7 @@ public class SnoopyCommandSource extends ServerCommandSource
|
||||
this.level = CarpetSettings.runPermissionLevel;
|
||||
this.simpleName = original.getName();
|
||||
this.name = original.getDisplayName();
|
||||
this.server = original.getMinecraftServer();
|
||||
this.server = original.getServer();
|
||||
this.entity = original.getEntity();
|
||||
this.resultConsumer = (ctx, succ, res) -> { };
|
||||
this.entityAnchor = original.getEntityAnchor();
|
||||
@@ -123,7 +122,8 @@ public class SnoopyCommandSource extends ServerCommandSource
|
||||
return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, error, chatOutput);
|
||||
}
|
||||
|
||||
public ServerCommandSource mergeConsumers(ResultConsumer<ServerCommandSource> consumer, BinaryOperator<ResultConsumer<ServerCommandSource>> binaryOperator) {
|
||||
public ServerCommandSource mergeConsumers(ResultConsumer<ServerCommandSource> consumer, BinaryOperator<ResultConsumer<ServerCommandSource>> binaryOperator)
|
||||
{
|
||||
ResultConsumer<ServerCommandSource> resultConsumer = binaryOperator.apply(this.resultConsumer, consumer);
|
||||
return this.withConsumer(resultConsumer);
|
||||
}
|
||||
@@ -153,18 +153,19 @@ public class SnoopyCommandSource extends ServerCommandSource
|
||||
@Override
|
||||
public ServerCommandSource withWorld(ServerWorld world)
|
||||
{
|
||||
double d = DimensionType.method_31109(this.world.getDimension(), world.getDimension());
|
||||
double d = DimensionType.getCoordinateScaleFactor(this.world.getDimension(), world.getDimension());
|
||||
Vec3d position = new Vec3d(this.position.x * d, this.position.y, this.position.z * d);
|
||||
return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerCommandSource withLookingAt(Vec3d position) throws CommandSyntaxException {
|
||||
public ServerCommandSource withLookingAt(Vec3d position)
|
||||
{
|
||||
Vec3d vec3d = this.entityAnchor.positionAt(this);
|
||||
double d = position.x - vec3d.x;
|
||||
double e = position.y - vec3d.y;
|
||||
double f = position.z - vec3d.z;
|
||||
double g = (double) MathHelper.sqrt(d * d + f * f);
|
||||
double g = (double) Math.sqrt(d * d + f * f);
|
||||
float h = MathHelper.wrapDegrees((float)(-(MathHelper.atan2(e, g) * 57.2957763671875D)));
|
||||
float i = MathHelper.wrapDegrees((float)(MathHelper.atan2(f, d) * 57.2957763671875D) - 90.0F);
|
||||
return this.withRotation(new Vec2f(h, i));
|
||||
|
||||
@@ -42,33 +42,33 @@ public class SystemInfo {
|
||||
put("app_scope", c -> StringValue.of((c.host).isPerUser()?"player":"global"));
|
||||
put("app_players", c -> ListValue.wrap(c.host.getUserList().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||
|
||||
put("world_name", c -> new StringValue(c.s.getMinecraftServer().getSaveProperties().getLevelName()));
|
||||
put("world_name", c -> new StringValue(c.s.getServer().getSaveProperties().getLevelName()));
|
||||
put("world_seed", c -> new NumericValue(c.s.getWorld().getSeed()));
|
||||
put("server_motd", c -> StringValue.of(c.s.getMinecraftServer().getServerMotd()));
|
||||
put("world_path", c -> StringValue.of(c.s.getMinecraftServer().getSavePath(WorldSavePath.ROOT).toString()));
|
||||
put("server_motd", c -> StringValue.of(c.s.getServer().getServerMotd()));
|
||||
put("world_path", c -> StringValue.of(c.s.getServer().getSavePath(WorldSavePath.ROOT).toString()));
|
||||
put("world_folder", c -> {
|
||||
Path serverPath = c.s.getMinecraftServer().getSavePath(WorldSavePath.ROOT);
|
||||
Path serverPath = c.s.getServer().getSavePath(WorldSavePath.ROOT);
|
||||
int nodeCount = serverPath.getNameCount();
|
||||
if (nodeCount < 2) return Value.NULL;
|
||||
String tlf = serverPath.getName(nodeCount-2).toString();
|
||||
return StringValue.of(tlf);
|
||||
});
|
||||
put("world_dimensions", c -> ListValue.wrap(c.s.getMinecraftServer().getWorldRegistryKeys().stream().map(k -> ValueConversions.of(k.getValue())).collect(Collectors.toList())));
|
||||
put("world_dimensions", c -> ListValue.wrap(c.s.getServer().getWorldRegistryKeys().stream().map(k -> ValueConversions.of(k.getValue())).collect(Collectors.toList())));
|
||||
put("world_spawn_point", c -> {
|
||||
WorldProperties prop = c.s.getMinecraftServer().getOverworld().getLevelProperties();
|
||||
WorldProperties prop = c.s.getServer().getOverworld().getLevelProperties();
|
||||
return ListValue.of(NumericValue.of(prop.getSpawnX()), NumericValue.of(prop.getSpawnY()), NumericValue.of(prop.getSpawnZ()));
|
||||
});
|
||||
|
||||
put("game_difficulty", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getDifficulty().getName()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.s.getMinecraftServer().getSaveProperties().isHardcore()));
|
||||
put("game_storage_format", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getFormatName(c.s.getMinecraftServer().getSaveProperties().getVersion())));
|
||||
put("game_default_gamemode", c -> StringValue.of(c.s.getMinecraftServer().getDefaultGameMode().getName()));
|
||||
put("game_max_players", c -> new NumericValue(c.s.getMinecraftServer().getMaxPlayerCount()));
|
||||
put("game_view_distance", c -> new NumericValue(c.s.getMinecraftServer().getPlayerManager().getViewDistance()));
|
||||
put("game_mod_name", c -> StringValue.of(c.s.getMinecraftServer().getServerModName()));
|
||||
put("game_version", c -> StringValue.of(c.s.getMinecraftServer().getVersion()));
|
||||
put("game_difficulty", c -> StringValue.of(c.s.getServer().getSaveProperties().getDifficulty().getName()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.s.getServer().getSaveProperties().isHardcore()));
|
||||
put("game_storage_format", c -> StringValue.of(c.s.getServer().getSaveProperties().getFormatName(c.s.getServer().getSaveProperties().getVersion())));
|
||||
put("game_default_gamemode", c -> StringValue.of(c.s.getServer().getDefaultGameMode().getName()));
|
||||
put("game_max_players", c -> new NumericValue(c.s.getServer().getMaxPlayerCount()));
|
||||
put("game_view_distance", c -> new NumericValue(c.s.getServer().getPlayerManager().getViewDistance()));
|
||||
put("game_mod_name", c -> StringValue.of(c.s.getServer().getServerModName()));
|
||||
put("game_version", c -> StringValue.of(c.s.getServer().getVersion()));
|
||||
put("game_target", c -> StringValue.of(SharedConstants.getGameVersion().getReleaseTarget()));
|
||||
put("game_protocol", c -> NumericValue.of(SharedConstants.method_31372()));
|
||||
put("game_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
|
||||
put("game_major_target", c -> {
|
||||
String [] vers = SharedConstants.getGameVersion().getReleaseTarget().split("\\.");
|
||||
return NumericValue.of((vers.length > 1)?Integer.parseInt(vers[1]):0);
|
||||
@@ -81,11 +81,11 @@ public class SystemInfo {
|
||||
put("game_data_version", c->NumericValue.of(SharedConstants.getGameVersion().getWorldVersion()));
|
||||
put("game_pack_version", c->NumericValue.of(SharedConstants.getGameVersion().getPackVersion()));
|
||||
|
||||
put("server_ip", c -> StringValue.of(c.s.getMinecraftServer().getServerIp()));
|
||||
put("server_whitelisted", c -> BooleanValue.of(c.s.getMinecraftServer().isEnforceWhitelist()));
|
||||
put("server_ip", c -> StringValue.of(c.s.getServer().getServerIp()));
|
||||
put("server_whitelisted", c -> BooleanValue.of(c.s.getServer().isEnforceWhitelist()));
|
||||
put("server_whitelist", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getMinecraftServer().getPlayerManager().getWhitelistedNames())
|
||||
for (String s: c.s.getServer().getPlayerManager().getWhitelistedNames())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class SystemInfo {
|
||||
});
|
||||
put("server_banned_players", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getMinecraftServer().getPlayerManager().getUserBanList().getNames())
|
||||
for (String s: c.s.getServer().getPlayerManager().getUserBanList().getNames())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class SystemInfo {
|
||||
});
|
||||
put("server_banned_ips", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getMinecraftServer().getPlayerManager().getIpBanList().getNames())
|
||||
for (String s: c.s.getServer().getPlayerManager().getIpBanList().getNames())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package carpet.script.utils;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListener;
|
||||
@@ -97,21 +99,21 @@ public class WorldTools
|
||||
ChunkGenerator chunkGenerator2;
|
||||
DimensionType dimensionType2;
|
||||
if (dimensionOptions == null) {
|
||||
dimensionType2 = (DimensionType)server.getRegistryManager().getDimensionTypes().getOrThrow(DimensionType.OVERWORLD_REGISTRY_KEY);
|
||||
chunkGenerator2 = GeneratorOptions.createOverworldGenerator(server.getRegistryManager().get(Registry.BIOME_KEY), server.getRegistryManager().get(Registry.NOISE_SETTINGS_WORLDGEN), (new Random()).nextLong());
|
||||
dimensionType2 = server.getRegistryManager().getMutable(Registry.DIMENSION_TYPE_KEY).getOrThrow(DimensionType.OVERWORLD_REGISTRY_KEY);
|
||||
chunkGenerator2 = GeneratorOptions.createOverworldGenerator(server.getRegistryManager().get(Registry.BIOME_KEY), server.getRegistryManager().get(Registry.CHUNK_GENERATOR_SETTINGS_KEY), (new Random()).nextLong());
|
||||
} else {
|
||||
dimensionType2 = dimensionOptions.getDimensionType();
|
||||
chunkGenerator2 = dimensionOptions.getChunkGenerator();
|
||||
}
|
||||
|
||||
RegistryKey<World> customWorld = RegistryKey.of(Registry.DIMENSION, worldId);
|
||||
RegistryKey<World> customWorld = RegistryKey.of(Registry.WORLD_KEY, worldId);
|
||||
|
||||
//chunkGenerator2 = GeneratorOptions.createOverworldGenerator(server.getRegistryManager().get(Registry.BIOME_KEY), server.getRegistryManager().get(Registry.NOISE_SETTINGS_WORLDGEN), (seed==null)?l:seed);
|
||||
|
||||
chunkGenerator2 = new NoiseChunkGenerator(
|
||||
new VanillaLayeredBiomeSource((seed==null)?l:seed, false, false, server.getRegistryManager().get(Registry.BIOME_KEY)),
|
||||
(seed==null)?l:seed,
|
||||
() -> server.getRegistryManager().get(Registry.NOISE_SETTINGS_WORLDGEN).getOrThrow(ChunkGeneratorSettings.OVERWORLD)
|
||||
() -> server.getRegistryManager().get(Registry.CHUNK_GENERATOR_SETTINGS_KEY).getOrThrow(ChunkGeneratorSettings.OVERWORLD)
|
||||
);
|
||||
|
||||
ServerWorld serverWorld = new ServerWorld(
|
||||
@@ -142,7 +144,7 @@ public class WorldTools
|
||||
List<ServerPlayerEntity> nearbyPlayers = world.getPlayers(p -> pos.getSquaredDistance(p.getX(), pos.getY(), p.getZ(), true) < vvd);
|
||||
if (!nearbyPlayers.isEmpty())
|
||||
{
|
||||
ChunkDataS2CPacket packet = new ChunkDataS2CPacket(worldChunk, 65535);
|
||||
ChunkDataS2CPacket packet = new ChunkDataS2CPacket(worldChunk);
|
||||
ChunkPos chpos = new ChunkPos(pos);
|
||||
nearbyPlayers.forEach(p -> p.networkHandler.sendPacket(packet));
|
||||
}
|
||||
@@ -154,6 +156,8 @@ public class WorldTools
|
||||
{
|
||||
@Override public void start(ChunkPos spawnPos) { }
|
||||
@Override public void setChunkStatus(ChunkPos pos, ChunkStatus status) { }
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override public void start() { }
|
||||
@Override public void stop() { }
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import net.minecraft.command.argument.BlockArgumentParser;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.dynamic.GlobalPos;
|
||||
@@ -45,7 +45,7 @@ public class BlockValue extends Value
|
||||
private BlockState blockState;
|
||||
private final BlockPos pos;
|
||||
private final ServerWorld world;
|
||||
private CompoundTag data;
|
||||
private NbtCompound data;
|
||||
|
||||
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
|
||||
{
|
||||
@@ -63,9 +63,9 @@ public class BlockValue extends Value
|
||||
BlockArgumentParser blockstateparser = (new BlockArgumentParser(new StringReader(str), false)).parse(true);
|
||||
if (blockstateparser.getBlockState() != null)
|
||||
{
|
||||
CompoundTag bd = blockstateparser.getNbtData();
|
||||
NbtCompound bd = blockstateparser.getNbtData();
|
||||
if (bd == null)
|
||||
bd = new CompoundTag();
|
||||
bd = new NbtCompound();
|
||||
bv = new BlockValue(blockstateparser.getBlockState(), null, null, bd );
|
||||
if (bvCache.size()>10000)
|
||||
bvCache.clear();
|
||||
@@ -107,7 +107,7 @@ public class BlockValue extends Value
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag getData()
|
||||
public NbtCompound getData()
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
@@ -118,13 +118,13 @@ public class BlockValue extends Value
|
||||
if (world != null && pos != null)
|
||||
{
|
||||
BlockEntity be = getBlockEntity(world, pos);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
if (be == null)
|
||||
{
|
||||
data = tag;
|
||||
return null;
|
||||
}
|
||||
data = be.toTag(tag);
|
||||
data = be.writeNbt(tag);
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
@@ -139,7 +139,7 @@ public class BlockValue extends Value
|
||||
data = null;
|
||||
}
|
||||
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position, CompoundTag nbt)
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position, NbtCompound nbt)
|
||||
{
|
||||
this.world = world;
|
||||
blockState = state;
|
||||
@@ -188,26 +188,26 @@ public class BlockValue extends Value
|
||||
public ServerWorld getWorld() { return world;}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
// follows falling block convertion
|
||||
CompoundTag tag = new CompoundTag();
|
||||
CompoundTag state = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
NbtCompound state = new NbtCompound();
|
||||
BlockState s = getBlockState();
|
||||
state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
|
||||
state.put("Name", NbtString.of(Registry.BLOCK.getId(s.getBlock()).toString()));
|
||||
Collection<Property<?>> properties = s.getProperties();
|
||||
if (!properties.isEmpty())
|
||||
{
|
||||
CompoundTag props = new CompoundTag();
|
||||
NbtCompound props = new NbtCompound();
|
||||
for (Property<?> p: properties)
|
||||
{
|
||||
props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
|
||||
props.put(p.getName(), NbtString.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
state.put("Properties", props);
|
||||
}
|
||||
tag.put("BlockState", state);
|
||||
CompoundTag dataTag = getData();
|
||||
NbtCompound dataTag = getData();
|
||||
if (dataTag != null)
|
||||
{
|
||||
tag.put("TileEntityData", dataTag);
|
||||
|
||||
@@ -2,8 +2,8 @@ package carpet.script.value;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtByte;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class BooleanValue extends NumericValue
|
||||
{
|
||||
@@ -47,8 +47,8 @@ public class BooleanValue extends NumericValue
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force) {
|
||||
return ByteTag.of(boolValue);
|
||||
public NbtElement toTag(boolean force) {
|
||||
return NbtByte.of(boolValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,8 +31,8 @@ import net.minecraft.entity.attribute.AttributeContainer;
|
||||
import net.minecraft.entity.attribute.EntityAttribute;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket;
|
||||
@@ -53,14 +53,16 @@ import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.mob.PathAwareEntity;
|
||||
import net.minecraft.entity.passive.PassiveEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TypeFilter;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
@@ -200,7 +202,7 @@ public class EntityValue extends Value
|
||||
{
|
||||
if (v instanceof EntityValue)
|
||||
{
|
||||
return getEntity().getEntityId()==((EntityValue) v).getEntity().getEntityId();
|
||||
return getEntity().getId()==((EntityValue) v).getEntity().getId();
|
||||
}
|
||||
return super.equals((Value)v);
|
||||
}
|
||||
@@ -250,7 +252,7 @@ public class EntityValue extends Value
|
||||
positive = false;
|
||||
who = who.substring(1);
|
||||
}
|
||||
net.minecraft.tag.Tag<EntityType<?>> eTag = server.getTagManager().getEntityTypes().getTag(InputValidator.identifierOf(who));
|
||||
Tag<EntityType<?>> eTag = server.getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(InputValidator.identifierOf(who));
|
||||
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor");
|
||||
if (positive)
|
||||
{
|
||||
@@ -268,7 +270,7 @@ public class EntityValue extends Value
|
||||
|
||||
public static class EntityClassDescriptor
|
||||
{
|
||||
public EntityType<? extends Entity> directType;
|
||||
public TypeFilter<Entity, ? extends Entity> directType; // interface of EntityType
|
||||
public Predicate<? super Entity> filteringPredicate;
|
||||
public List<EntityType<? extends Entity>> typeList;
|
||||
public Value listValue;
|
||||
@@ -279,11 +281,25 @@ public class EntityValue extends Value
|
||||
typeList = types;
|
||||
listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getId(et)))).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
EntityClassDescriptor( TypeFilter<Entity, ?> type, Predicate<? super Entity> predicate, List<EntityType<?>> types)
|
||||
{
|
||||
directType = type;
|
||||
filteringPredicate = predicate;
|
||||
typeList = types;
|
||||
listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getId(et)))).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
EntityClassDescriptor(EntityType<?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
{
|
||||
this(type, predicate, types.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
EntityClassDescriptor(TypeFilter<Entity, ?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
{
|
||||
this(type, predicate, types.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public final static Map<String, EntityClassDescriptor> byName = new HashMap<String, EntityClassDescriptor>() {{
|
||||
List<EntityType<?>> allTypes = Registry.ENTITY_TYPE.stream().collect(Collectors.toList());
|
||||
// nonliving types
|
||||
@@ -295,9 +311,9 @@ public class EntityValue extends Value
|
||||
EntityType.TRIDENT, EntityType.WITHER_SKULL, EntityType.FISHING_BOBBER, EntityType.SHULKER_BULLET
|
||||
);
|
||||
Set<EntityType<?>> deads = Sets.newHashSet(
|
||||
EntityType.AREA_EFFECT_CLOUD, EntityType.BOAT, EntityType.END_CRYSTAL,
|
||||
EntityType.AREA_EFFECT_CLOUD, EntityType.MARKER, EntityType.BOAT, EntityType.END_CRYSTAL,
|
||||
EntityType.EVOKER_FANGS, EntityType.EXPERIENCE_ORB, EntityType.EYE_OF_ENDER,
|
||||
EntityType.FALLING_BLOCK, EntityType.ITEM, EntityType.ITEM_FRAME,
|
||||
EntityType.FALLING_BLOCK, EntityType.ITEM, EntityType.ITEM_FRAME, EntityType.GLOW_ITEM_FRAME,
|
||||
EntityType.LEASH_KNOT, EntityType.LIGHTNING_BOLT, EntityType.PAINTING,
|
||||
EntityType.TNT, EntityType.ARMOR_STAND
|
||||
|
||||
@@ -337,49 +353,49 @@ public class EntityValue extends Value
|
||||
).collect(Collectors.toSet());
|
||||
|
||||
|
||||
put("*", new EntityClassDescriptor(null, e -> true, allTypes) );
|
||||
put("valid", new EntityClassDescriptor(null, EntityPredicates.VALID_ENTITY, allTypes));
|
||||
put("!valid", new EntityClassDescriptor(null, e -> !e.isAlive(), allTypes));
|
||||
put("*", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), e -> true, allTypes) );
|
||||
put("valid", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), EntityPredicates.VALID_ENTITY, allTypes));
|
||||
put("!valid", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), e -> !e.isAlive(), allTypes));
|
||||
|
||||
put("living", new EntityClassDescriptor(null, (e) -> (e instanceof LivingEntity && e.isAlive()), allTypes.stream().filter(living::contains)));
|
||||
put("!living", new EntityClassDescriptor(null, (e) -> (!(e instanceof LivingEntity) && e.isAlive()), allTypes.stream().filter(et -> !living.contains(et))));
|
||||
put("living", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), EntityPredicates.VALID_ENTITY, allTypes.stream().filter(living::contains)));
|
||||
put("!living", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), (e) -> (!(e instanceof LivingEntity) && e.isAlive()), allTypes.stream().filter(et -> !living.contains(et))));
|
||||
|
||||
put("projectile", new EntityClassDescriptor(null, (e) -> (e instanceof ProjectileEntity && e.isAlive()), allTypes.stream().filter(projectiles::contains)));
|
||||
put("!projectile", new EntityClassDescriptor(null, (e) -> (!(e instanceof ProjectileEntity) && e.isAlive()), allTypes.stream().filter(et -> !projectiles.contains(et) && !living.contains(et))));
|
||||
put("projectile", new EntityClassDescriptor(TypeFilter.instanceOf(ProjectileEntity.class), EntityPredicates.VALID_ENTITY, allTypes.stream().filter(projectiles::contains)));
|
||||
put("!projectile", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), (e) -> (!(e instanceof ProjectileEntity) && e.isAlive()), allTypes.stream().filter(et -> !projectiles.contains(et) && !living.contains(et))));
|
||||
|
||||
put("minecarts", new EntityClassDescriptor(null, (e) -> (e instanceof AbstractMinecartEntity && e.isAlive()), allTypes.stream().filter(minecarts::contains)));
|
||||
put("!minecarts", new EntityClassDescriptor(null, (e) -> (!(e instanceof AbstractMinecartEntity) && e.isAlive()), allTypes.stream().filter(et -> !minecarts.contains(et) && !living.contains(et))));
|
||||
put("minecarts", new EntityClassDescriptor(TypeFilter.instanceOf(AbstractMinecartEntity.class), EntityPredicates.VALID_ENTITY, allTypes.stream().filter(minecarts::contains)));
|
||||
put("!minecarts", new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), (e) -> (!(e instanceof AbstractMinecartEntity) && e.isAlive()), allTypes.stream().filter(et -> !minecarts.contains(et) && !living.contains(et))));
|
||||
|
||||
|
||||
// combat groups
|
||||
|
||||
put("arthropod", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() == EntityGroup.ARTHROPOD && e.isAlive()), allTypes.stream().filter(arthropods::contains)));
|
||||
put("!arthropod", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() != EntityGroup.ARTHROPOD && e.isAlive()), allTypes.stream().filter(et -> !arthropods.contains(et) && living.contains(et))));
|
||||
put("arthropod", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() == EntityGroup.ARTHROPOD && e.isAlive()), allTypes.stream().filter(arthropods::contains)));
|
||||
put("!arthropod", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() != EntityGroup.ARTHROPOD && e.isAlive()), allTypes.stream().filter(et -> !arthropods.contains(et) && living.contains(et))));
|
||||
|
||||
put("undead", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() == EntityGroup.UNDEAD && e.isAlive()), allTypes.stream().filter(undeads::contains)));
|
||||
put("!undead", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() != EntityGroup.UNDEAD && e.isAlive()), allTypes.stream().filter(et -> !undeads.contains(et) && living.contains(et))));
|
||||
put("undead", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() == EntityGroup.UNDEAD && e.isAlive()), allTypes.stream().filter(undeads::contains)));
|
||||
put("!undead", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() != EntityGroup.UNDEAD && e.isAlive()), allTypes.stream().filter(et -> !undeads.contains(et) && living.contains(et))));
|
||||
|
||||
put("aquatic", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() == EntityGroup.AQUATIC && e.isAlive()), allTypes.stream().filter(aquatique::contains)));
|
||||
put("!aquatic", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() != EntityGroup.AQUATIC && e.isAlive()), allTypes.stream().filter(et -> !aquatique.contains(et) && living.contains(et))));
|
||||
put("aquatic", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() == EntityGroup.AQUATIC && e.isAlive()), allTypes.stream().filter(aquatique::contains)));
|
||||
put("!aquatic", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() != EntityGroup.AQUATIC && e.isAlive()), allTypes.stream().filter(et -> !aquatique.contains(et) && living.contains(et))));
|
||||
|
||||
put("illager", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() == EntityGroup.ILLAGER && e.isAlive()), allTypes.stream().filter(illagers::contains)));
|
||||
put("!illager", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() != EntityGroup.ILLAGER && e.isAlive()), allTypes.stream().filter(et -> !illagers.contains(et) && living.contains(et))));
|
||||
put("illager", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() == EntityGroup.ILLAGER && e.isAlive()), allTypes.stream().filter(illagers::contains)));
|
||||
put("!illager", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() != EntityGroup.ILLAGER && e.isAlive()), allTypes.stream().filter(et -> !illagers.contains(et) && living.contains(et))));
|
||||
|
||||
put("regular", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() == EntityGroup.DEFAULT && e.isAlive()), allTypes.stream().filter(regular::contains)));
|
||||
put("!regular", new EntityClassDescriptor(null, e -> ((e instanceof LivingEntity) && ((LivingEntity) e).getGroup() != EntityGroup.DEFAULT && e.isAlive()), allTypes.stream().filter(et -> !regular.contains(et) && living.contains(et))));
|
||||
put("regular", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() == EntityGroup.DEFAULT && e.isAlive()), allTypes.stream().filter(regular::contains)));
|
||||
put("!regular", new EntityClassDescriptor(TypeFilter.instanceOf(LivingEntity.class), e -> (((LivingEntity) e).getGroup() != EntityGroup.DEFAULT && e.isAlive()), allTypes.stream().filter(et -> !regular.contains(et) && living.contains(et))));
|
||||
|
||||
for (Identifier typeId : Registry.ENTITY_TYPE.getIds())
|
||||
{
|
||||
EntityType<?> type = Registry.ENTITY_TYPE.get(typeId);
|
||||
String mobType = ValueConversions.simplify(typeId);
|
||||
put( mobType, new EntityClassDescriptor(type, EntityPredicates.VALID_ENTITY, Stream.of(type)));
|
||||
put("!"+mobType, new EntityClassDescriptor(null, (e) -> e.getType() != type && e.isAlive(), allTypes.stream().filter(et -> et != type)));
|
||||
put("!"+mobType, new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), (e) -> e.getType() != type && e.isAlive(), allTypes.stream().filter(et -> et != type)));
|
||||
}
|
||||
for (SpawnGroup catId : SpawnGroup.values())
|
||||
{
|
||||
String catStr = catId.getName();
|
||||
put( catStr, new EntityClassDescriptor(null, e -> ((e.getType().getSpawnGroup() == catId) && e.isAlive()), allTypes.stream().filter(et -> et.getSpawnGroup() == catId)));
|
||||
put("!"+catStr, new EntityClassDescriptor(null, e -> ((e.getType().getSpawnGroup() != catId) && e.isAlive()), allTypes.stream().filter(et -> et.getSpawnGroup() != catId)));
|
||||
put( catStr, new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), e -> ((e.getType().getSpawnGroup() == catId) && e.isAlive()), allTypes.stream().filter(et -> et.getSpawnGroup() == catId)));
|
||||
put("!"+catStr, new EntityClassDescriptor(TypeFilter.instanceOf(Entity.class), e -> ((e.getType().getSpawnGroup() != catId) && e.isAlive()), allTypes.stream().filter(et -> et.getSpawnGroup() != catId)));
|
||||
}
|
||||
}};
|
||||
}
|
||||
@@ -408,11 +424,11 @@ public class EntityValue extends Value
|
||||
|
||||
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
||||
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
||||
put("removed", (entity, arg) -> BooleanValue.of(entity.removed));
|
||||
put("removed", (entity, arg) -> BooleanValue.of(entity.isRemoved()));
|
||||
put("uuid",(e, a) -> new StringValue(e.getUuidAsString()));
|
||||
put("id",(e, a) -> new NumericValue(e.getEntityId()));
|
||||
put("id",(e, a) -> new NumericValue(e.getId()));
|
||||
put("pos", (e, a) -> ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ())));
|
||||
put("location", (e, a) -> ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ()), new NumericValue(e.yaw), new NumericValue(e.pitch)));
|
||||
put("location", (e, a) -> ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ()), new NumericValue(e.getYaw()), new NumericValue(e.getPitch())));
|
||||
put("x", (e, a) -> new NumericValue(e.getX()));
|
||||
put("y", (e, a) -> new NumericValue(e.getY()));
|
||||
put("z", (e, a) -> new NumericValue(e.getZ()));
|
||||
@@ -439,18 +455,18 @@ public class EntityValue extends Value
|
||||
put("tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||
|
||||
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTagManager().getEntityTypes().getTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList())));
|
||||
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList())));
|
||||
// deprecated
|
||||
put("has_tag", (e, a) -> BooleanValue.of(e.getScoreboardTags().contains(a.getString())));
|
||||
|
||||
put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getScoreboardTags().contains(a.getString())));
|
||||
put("has_entity_tag", (e, a) -> {
|
||||
net.minecraft.tag.Tag<EntityType<?>> tag = e.getServer().getTagManager().getEntityTypes().getTag(InputValidator.identifierOf(a.getString()));
|
||||
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(InputValidator.identifierOf(a.getString()));
|
||||
if (tag == null) return Value.NULL;
|
||||
return BooleanValue.of(e.getType().isIn(tag));
|
||||
});
|
||||
|
||||
put("yaw", (e, a)-> new NumericValue(e.yaw));
|
||||
put("yaw", (e, a)-> new NumericValue(e.getYaw()));
|
||||
put("head_yaw", (e, a)-> {
|
||||
if (e instanceof LivingEntity)
|
||||
{
|
||||
@@ -466,16 +482,19 @@ public class EntityValue extends Value
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
put("pitch", (e, a)-> new NumericValue(e.pitch));
|
||||
put("pitch", (e, a)-> new NumericValue(e.getPitch()));
|
||||
put("look", (e, a) -> {
|
||||
Vec3d look = e.getRotationVector();
|
||||
return ListValue.of(new NumericValue(look.x),new NumericValue(look.y),new NumericValue(look.z));
|
||||
});
|
||||
put("is_burning", (e, a) -> BooleanValue.of(e.isOnFire()));
|
||||
put("fire", (e, a) -> new NumericValue(e.getFireTicks()));
|
||||
put("is_freezing", (e, a) -> BooleanValue.of(e.isFreezing()));
|
||||
put("frost", (e, a) -> new NumericValue(e.getFrozenTicks()));
|
||||
put("silent", (e, a)-> BooleanValue.of(e.isSilent()));
|
||||
put("gravity", (e, a) -> BooleanValue.of(!e.hasNoGravity()));
|
||||
put("immune_to_fire", (e, a) -> BooleanValue.of(e.isFireImmune()));
|
||||
put("immune_to_frost", (e, a) -> BooleanValue.of(!e.canFreeze()));
|
||||
|
||||
put("invulnerable", (e, a) -> BooleanValue.of(e.isInvulnerable()));
|
||||
put("dimension", (e, a) -> new StringValue(nameFromRegistryId(e.world.getRegistryKey().getValue()))); // getDimId
|
||||
@@ -739,7 +758,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("selected_slot", (e, a) -> {
|
||||
if (e instanceof PlayerEntity)
|
||||
return new NumericValue(((PlayerEntity) e).inventory.selectedSlot);
|
||||
return new NumericValue(((PlayerEntity) e).getInventory().selectedSlot); //getInventory
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
@@ -858,7 +877,7 @@ public class EntityValue extends Value
|
||||
});
|
||||
|
||||
put("nbt",(e, a) -> {
|
||||
CompoundTag nbttagcompound = e.toTag((new CompoundTag()));
|
||||
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
|
||||
if (a==null)
|
||||
return new NBTSerializableValue(nbttagcompound);
|
||||
return new NBTSerializableValue(nbttagcompound).get(a);
|
||||
@@ -901,7 +920,7 @@ public class EntityValue extends Value
|
||||
EnumSet<PlayerPositionLookS2CPacket.Flag> set = EnumSet.noneOf(PlayerPositionLookS2CPacket.Flag.class);
|
||||
set.add(PlayerPositionLookS2CPacket.Flag.X_ROT);
|
||||
set.add(PlayerPositionLookS2CPacket.Flag.Y_ROT);
|
||||
((ServerPlayerEntity)e).networkHandler.teleportRequest(x, y, z, yaw, pitch, set );
|
||||
((ServerPlayerEntity)e).networkHandler.requestTeleport(x, y, z, yaw, pitch, set );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -933,7 +952,7 @@ public class EntityValue extends Value
|
||||
}
|
||||
|
||||
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
||||
put("remove", (entity, value) -> entity.remove());
|
||||
put("remove", (entity, value) -> entity.discard()); // using discard here - will see other options if valid
|
||||
put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) );
|
||||
put("health", (e, v) -> {
|
||||
float health = (float) NumericValue.asNumber(v).getDouble();
|
||||
@@ -993,25 +1012,25 @@ public class EntityValue extends Value
|
||||
NumericValue.asNumber(coords.get(0)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(1)).getDouble(),
|
||||
NumericValue.asNumber(coords.get(2)).getDouble(),
|
||||
e.yaw,
|
||||
e.pitch
|
||||
e.getYaw(),
|
||||
e.getPitch()
|
||||
);
|
||||
});
|
||||
put("x", (e, v) ->
|
||||
{
|
||||
updatePosition(e, NumericValue.asNumber(v).getDouble(), e.getY(), e.getZ(), e.yaw, e.pitch);
|
||||
updatePosition(e, NumericValue.asNumber(v).getDouble(), e.getY(), e.getZ(), e.getYaw(), e.getPitch());
|
||||
});
|
||||
put("y", (e, v) ->
|
||||
{
|
||||
updatePosition(e, e.getX(), NumericValue.asNumber(v).getDouble(), e.getZ(), e.yaw, e.pitch);
|
||||
updatePosition(e, e.getX(), NumericValue.asNumber(v).getDouble(), e.getZ(), e.getYaw(), e.getPitch());
|
||||
});
|
||||
put("z", (e, v) ->
|
||||
{
|
||||
updatePosition(e, e.getX(), e.getY(), NumericValue.asNumber(v).getDouble(), e.yaw, e.pitch);
|
||||
updatePosition(e, e.getX(), e.getY(), NumericValue.asNumber(v).getDouble(), e.getYaw(), e.getPitch());
|
||||
});
|
||||
put("yaw", (e, v) ->
|
||||
{
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), ((float)NumericValue.asNumber(v).getDouble()) % 360, e.pitch);
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), ((float)NumericValue.asNumber(v).getDouble()) % 360, e.getPitch());
|
||||
});
|
||||
put("head_yaw", (e, v) ->
|
||||
{
|
||||
@@ -1030,7 +1049,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("pitch", (e, v) ->
|
||||
{
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), e.yaw, MathHelper.clamp((float)NumericValue.asNumber(v).getDouble(), -90, 90));
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), e.getYaw(), MathHelper.clamp((float)NumericValue.asNumber(v).getDouble(), -90, 90));
|
||||
});
|
||||
|
||||
put("look", (e, v) -> {
|
||||
@@ -1045,7 +1064,7 @@ public class EntityValue extends Value
|
||||
y /= l;
|
||||
z /= l;
|
||||
float pitch = (float) -Math.asin(y) / 0.017453292F;
|
||||
float yaw = (float) (x==0 && z==0 ? e.yaw : MathHelper.atan2(-x,z) / 0.017453292F);
|
||||
float yaw = (float) (x==0 && z==0 ? e.getYaw() : MathHelper.atan2(-x,z) / 0.017453292F);
|
||||
updatePosition(e, e.getX(), e.getY(), e.getZ(), yaw, pitch);
|
||||
});
|
||||
|
||||
@@ -1063,8 +1082,8 @@ public class EntityValue extends Value
|
||||
e.getX() + NumericValue.asNumber(coords.get(0)).getDouble(),
|
||||
e.getY() + NumericValue.asNumber(coords.get(1)).getDouble(),
|
||||
e.getZ() + NumericValue.asNumber(coords.get(2)).getDouble(),
|
||||
e.yaw,
|
||||
e.pitch
|
||||
e.getYaw(),
|
||||
e.getPitch()
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1288,7 +1307,7 @@ public class EntityValue extends Value
|
||||
BlockValue bv= (BlockValue)a;
|
||||
if (bv.getPos()==null || bv.getWorld() == null)
|
||||
throw new InternalExpressionException("block for spawn modification should be localised in the world");
|
||||
spe.setSpawnPoint(bv.getWorld().getRegistryKey(), bv.getPos(), e.yaw, true, false);
|
||||
spe.setSpawnPoint(bv.getWorld().getRegistryKey(), bv.getPos(), e.getYaw(), true, false); // yaw
|
||||
}
|
||||
else if (a.isNull())
|
||||
{
|
||||
@@ -1408,7 +1427,7 @@ public class EntityValue extends Value
|
||||
GameMode toSet = v instanceof NumericValue ?
|
||||
GameMode.byId(((NumericValue) v).getInt(), null) :
|
||||
GameMode.byName(v.getString().toLowerCase(Locale.ROOT), null);
|
||||
if (toSet != null) ((ServerPlayerEntity) e).setGameMode(toSet);
|
||||
if (toSet != null) ((ServerPlayerEntity) e).changeGameMode(toSet);
|
||||
});
|
||||
|
||||
put("jumping",(e,v)->{
|
||||
@@ -1447,6 +1466,7 @@ public class EntityValue extends Value
|
||||
put("invulnerable",(e,v)-> e.setInvulnerable(v.getBoolean()));
|
||||
|
||||
put("fire",(e,v)-> e.setFireTicks((int)NumericValue.asNumber(v).getLong()));
|
||||
put("frost",(e,v)-> e.setFrozenTicks((int)NumericValue.asNumber(v).getLong()));
|
||||
|
||||
put("hunger", (e, v)-> {
|
||||
if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().setFoodLevel((int) NumericValue.asNumber(v).getLong());
|
||||
@@ -1507,7 +1527,7 @@ public class EntityValue extends Value
|
||||
Value tagValue = NBTSerializableValue.fromValue(v);
|
||||
if (tagValue instanceof NBTSerializableValue)
|
||||
{
|
||||
e.fromTag(((NBTSerializableValue) tagValue).getCompoundTag());
|
||||
e.readNbt(((NBTSerializableValue) tagValue).getCompoundTag());
|
||||
e.setUuid(uUID);
|
||||
}
|
||||
}
|
||||
@@ -1519,9 +1539,9 @@ public class EntityValue extends Value
|
||||
Value tagValue = NBTSerializableValue.fromValue(v);
|
||||
if (tagValue instanceof NBTSerializableValue)
|
||||
{
|
||||
CompoundTag nbttagcompound = e.toTag((new CompoundTag()));
|
||||
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
|
||||
nbttagcompound.copyFrom(((NBTSerializableValue) tagValue).getCompoundTag());
|
||||
e.fromTag(nbttagcompound);
|
||||
e.readNbt(nbttagcompound);
|
||||
e.setUuid(uUID);
|
||||
}
|
||||
}
|
||||
@@ -1542,12 +1562,12 @@ public class EntityValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("Data", getEntity().toTag( new CompoundTag()));
|
||||
tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
|
||||
NbtCompound tag = new NbtCompound();
|
||||
tag.put("Data", getEntity().writeNbt( new NbtCompound()));
|
||||
tag.put("Name", NbtString.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
@@ -75,10 +75,10 @@ public class FormattedTextValue extends StringValue
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(Text.Serializer.toJson(text));
|
||||
return NbtString.of(Text.Serializer.toJson(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public abstract class FrameworkValue extends Value
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public abstract class FrameworkValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
throw new UnsupportedOperationException("Scarpet language component cannot be serialized to the tag");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class FunctionAnnotationValue extends Value
|
||||
{
|
||||
@@ -37,7 +37,7 @@ public class FunctionAnnotationValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
throw new UnsupportedOperationException("Global value cannot be serialized to the tag");
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import carpet.script.exception.ContinueStatement;
|
||||
import carpet.script.exception.ExpressionException;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ReturnStatement;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -281,10 +281,10 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
public String getVarArgs() {return varArgs; }
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(getString());
|
||||
return NbtString.of(getString());
|
||||
}
|
||||
|
||||
public void assertArgsOk(List<?> list, Consumer<Boolean> feedback)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -204,9 +204,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(getString());
|
||||
return NbtString.of(getString());
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import carpet.script.LazyValue;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.minecraft.nbt.AbstractNumberTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.LongTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.AbstractNbtNumber;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtDouble;
|
||||
import net.minecraft.nbt.NbtInt;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtLong;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -477,31 +477,31 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
LIST,
|
||||
MAP,
|
||||
STRING;
|
||||
private static TagTypeCompat getType(Tag tag)
|
||||
private static TagTypeCompat getType(NbtElement tag)
|
||||
{
|
||||
if (tag instanceof IntTag) return INT;
|
||||
if (tag instanceof LongTag) return LONG;
|
||||
if (tag instanceof DoubleTag) return DBL;
|
||||
if (tag instanceof ListTag) return LIST;
|
||||
if (tag instanceof CompoundTag) return MAP;
|
||||
if (tag instanceof NbtInt) return INT;
|
||||
if (tag instanceof NbtLong) return LONG;
|
||||
if (tag instanceof NbtDouble) return DBL;
|
||||
if (tag instanceof NbtList) return LIST;
|
||||
if (tag instanceof NbtCompound) return MAP;
|
||||
return STRING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
int argSize = items.size();
|
||||
if (argSize == 0) return new ListTag();
|
||||
ListTag tag = new ListTag();
|
||||
if (argSize == 0) return new NbtList();
|
||||
NbtList tag = new NbtList();
|
||||
if (argSize ==1)
|
||||
{
|
||||
tag.add(items.get(0).toTag(force));
|
||||
return tag;
|
||||
}
|
||||
// figuring out the types
|
||||
List<Tag> tags= new ArrayList<>();
|
||||
List<NbtElement> tags= new ArrayList<>();
|
||||
items.forEach(v -> tags.add(v.toTag(force)));
|
||||
Set<TagTypeCompat> cases = EnumSet.noneOf(TagTypeCompat.class);
|
||||
tags.forEach(t -> cases.add(TagTypeCompat.getType(t)));
|
||||
@@ -515,17 +515,17 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
|| cases.contains(TagTypeCompat.STRING)) // incompatible types
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
tags.forEach(t -> tag.add(StringTag.of(t.asString())));
|
||||
tags.forEach(t -> tag.add(NbtString.of(t.asString())));
|
||||
return tag;
|
||||
}
|
||||
// only numbers / mixed types
|
||||
if (cases.contains(TagTypeCompat.DBL))
|
||||
{
|
||||
tags.forEach(t -> tag.add(DoubleTag.of(((AbstractNumberTag)t).getDouble())));
|
||||
tags.forEach(t -> tag.add(NbtDouble.of(((AbstractNbtNumber)t).doubleValue())));
|
||||
}
|
||||
else
|
||||
{
|
||||
tags.forEach(t -> tag.add(LongTag.of(((AbstractNumberTag)t).getLong())));
|
||||
tags.forEach(t -> tag.add(NbtLong.of(((AbstractNbtNumber)t).longValue())));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package carpet.script.value;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -260,9 +260,9 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
CompoundTag tag = new CompoundTag() ;
|
||||
NbtCompound tag = new NbtCompound() ;
|
||||
map.forEach( (k, v) ->
|
||||
{
|
||||
if (!force && !(k instanceof StringValue)) throw new NBTSerializableValue.IncompatibleTypeException(k);
|
||||
|
||||
@@ -19,19 +19,21 @@ import net.minecraft.command.argument.ItemStackArgument;
|
||||
import net.minecraft.command.argument.ItemStringReader;
|
||||
import net.minecraft.command.argument.NbtPathArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.InventoryOwner;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.passive.MerchantEntity;
|
||||
import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.AbstractListTag;
|
||||
import net.minecraft.nbt.AbstractNumberTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.AbstractNbtList;
|
||||
import net.minecraft.nbt.AbstractNbtNumber;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -53,8 +55,8 @@ import java.util.stream.Collectors;
|
||||
public class NBTSerializableValue extends Value implements ContainerValueInterface
|
||||
{
|
||||
private String nbtString = null;
|
||||
private Tag nbtTag = null;
|
||||
private Supplier<Tag> nbtSupplier = null;
|
||||
private NbtElement nbtTag = null;
|
||||
private Supplier<NbtElement> nbtSupplier = null;
|
||||
private boolean owned = false;
|
||||
|
||||
private NBTSerializableValue() {}
|
||||
@@ -65,7 +67,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
{
|
||||
try
|
||||
{
|
||||
return (new StringNbtReader(new StringReader(nbtString))).parseTag();
|
||||
return (new StringNbtReader(new StringReader(nbtString))).parseElement();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -75,19 +77,19 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
owned = true;
|
||||
}
|
||||
|
||||
public NBTSerializableValue(Tag tag)
|
||||
public NBTSerializableValue(NbtElement tag)
|
||||
{
|
||||
nbtTag = tag;
|
||||
owned = true;
|
||||
}
|
||||
|
||||
public static Value of(Tag tag)
|
||||
public static Value of(NbtElement tag)
|
||||
{
|
||||
if (tag == null) return Value.NULL;
|
||||
return new NBTSerializableValue(tag);
|
||||
}
|
||||
|
||||
public NBTSerializableValue(Supplier<Tag> tagSupplier)
|
||||
public NBTSerializableValue(Supplier<NbtElement> tagSupplier)
|
||||
{
|
||||
nbtSupplier = tagSupplier;
|
||||
}
|
||||
@@ -114,10 +116,10 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
public static NBTSerializableValue parseString(String nbtString, boolean fail)
|
||||
{
|
||||
Tag tag;
|
||||
NbtElement tag;
|
||||
try
|
||||
{
|
||||
tag = (new StringNbtReader(new StringReader(nbtString))).parseTag();
|
||||
tag = (new StringNbtReader(new StringReader(nbtString))).parseElement();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -163,7 +165,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof InventoryProvider) {
|
||||
inventory = ((InventoryProvider)block).getInventory(blockState, world, blockPos);
|
||||
} else if (block.hasBlockEntity()) {
|
||||
} else if (blockState.hasBlockEntity()) {
|
||||
BlockEntity blockEntity = BlockValue.getBlockEntity(world, blockPos);
|
||||
if (blockEntity instanceof Inventory) {
|
||||
inventory = (Inventory)blockEntity;
|
||||
@@ -205,7 +207,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
if (strVal.equals("enderchest"))
|
||||
{
|
||||
Value v2 = params.get(1 + offset);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(c.s.getMinecraftServer(), v2);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(c.s.getServer(), v2);
|
||||
if (player == null) throw new InternalExpressionException("enderchest inventory requires player argument");
|
||||
return new InventoryLocator(player, player.getBlockPos(), player.getEnderChestInventory(), offset + 2, true);
|
||||
}
|
||||
@@ -219,12 +221,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
boolean isEnder = strVal.startsWith("enderchest_");
|
||||
if (isEnder) strVal = strVal.substring(11); // len("enderchest_")
|
||||
ServerPlayerEntity player = c.s.getMinecraftServer().getPlayerManager().getPlayer(strVal);
|
||||
ServerPlayerEntity player = c.s.getServer().getPlayerManager().getPlayer(strVal);
|
||||
if (player == null) throw new InternalExpressionException("String description of an inventory should either denote a player or player's enderchest");
|
||||
return new InventoryLocator(
|
||||
player,
|
||||
player.getBlockPos(),
|
||||
isEnder ? player.getEnderChestInventory() : player.inventory,
|
||||
isEnder ? player.getEnderChestInventory() : player.getInventory(),
|
||||
offset + 1,
|
||||
isEnder
|
||||
);
|
||||
@@ -233,10 +235,10 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
{
|
||||
Inventory inv = null;
|
||||
Entity e = ((EntityValue) v1).getEntity();
|
||||
if (e instanceof PlayerEntity) inv = ((PlayerEntity) e).inventory;
|
||||
if (e instanceof PlayerEntity) inv = ((PlayerEntity) e).getInventory();
|
||||
else if (e instanceof Inventory) inv = (Inventory) e;
|
||||
else if (e instanceof VillagerEntity) inv = ((VillagerEntity) e).getInventory();
|
||||
else if (e instanceof InventoryBearerInterface) inv = ((InventoryBearerInterface)e).getCMInventory();
|
||||
else if (e instanceof InventoryOwner) inv = ((InventoryOwner) e).getInventory();
|
||||
else if (e instanceof InventoryBearerInterface) inv = ((InventoryBearerInterface)e).getCMInventory(); // horse only
|
||||
else if (e instanceof LivingEntity) return new InventoryLocator(e, e.getBlockPos(), new EquipmentInventory((MobEntity) e), offset+1);
|
||||
if (inv == null)
|
||||
return null;
|
||||
@@ -287,7 +289,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return parseItem(itemString, null);
|
||||
}
|
||||
|
||||
public static ItemStackArgument parseItem(String itemString, CompoundTag customTag)
|
||||
public static ItemStackArgument parseItem(String itemString, NbtCompound customTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -299,7 +301,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return new ItemStackArgument(res.getItem(), customTag);
|
||||
|
||||
ItemStringReader parser = (new ItemStringReader(new StringReader(itemString), false)).consume();
|
||||
res = new ItemStackArgument(parser.getItem(), parser.getTag());
|
||||
res = new ItemStackArgument(parser.getItem(), parser.getNbt());
|
||||
itemCache.put(itemString, res);
|
||||
if (itemCache.size()>64000)
|
||||
itemCache.clear();
|
||||
@@ -324,12 +326,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return slot;
|
||||
}
|
||||
|
||||
private static Value decodeTag(Tag t)
|
||||
private static Value decodeTag(NbtElement t)
|
||||
{
|
||||
if (t instanceof CompoundTag)
|
||||
if (t instanceof NbtCompound)
|
||||
return new NBTSerializableValue(() -> t);
|
||||
if (t instanceof AbstractNumberTag)
|
||||
return new NumericValue(((AbstractNumberTag) t).getDouble());
|
||||
if (t instanceof AbstractNbtNumber)
|
||||
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
|
||||
// more can be done here
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
@@ -349,35 +351,35 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
|
||||
private static Value decodeTagDeep(Tag t)
|
||||
private static Value decodeTagDeep(NbtElement t)
|
||||
{
|
||||
if (t instanceof CompoundTag)
|
||||
if (t instanceof NbtCompound)
|
||||
{
|
||||
Map<Value, Value> pairs = new HashMap<>();
|
||||
CompoundTag ctag = (CompoundTag)t;
|
||||
NbtCompound ctag = (NbtCompound)t;
|
||||
for (String key: ctag.getKeys())
|
||||
{
|
||||
pairs.put(new StringValue(key), decodeTagDeep(ctag.get(key)));
|
||||
}
|
||||
return MapValue.wrap(pairs);
|
||||
}
|
||||
if (t instanceof AbstractListTag)
|
||||
if (t instanceof AbstractNbtList)
|
||||
{
|
||||
List<Value> elems = new ArrayList<>();
|
||||
AbstractListTag<? extends Tag> ltag = (AbstractListTag<? extends Tag>)t;
|
||||
for (Tag elem: ltag)
|
||||
AbstractNbtList<? extends NbtElement> ltag = (AbstractNbtList<? extends NbtElement>)t;
|
||||
for (NbtElement elem: ltag)
|
||||
{
|
||||
elems.add(decodeTagDeep(elem));
|
||||
}
|
||||
return ListValue.wrap(elems);
|
||||
}
|
||||
if (t instanceof AbstractNumberTag)
|
||||
return new NumericValue(((AbstractNumberTag) t).getDouble());
|
||||
if (t instanceof AbstractNbtNumber)
|
||||
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
|
||||
// more can be done here
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
|
||||
public Tag getTag()
|
||||
public NbtElement getTag()
|
||||
{
|
||||
if (nbtTag == null)
|
||||
nbtTag = nbtSupplier.get();
|
||||
@@ -403,24 +405,24 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
@Override
|
||||
public boolean getBoolean()
|
||||
{
|
||||
Tag tag = getTag();
|
||||
if (tag instanceof CompoundTag)
|
||||
return !((CompoundTag) tag).isEmpty();
|
||||
if (tag instanceof AbstractListTag)
|
||||
return ((AbstractListTag) tag).isEmpty();
|
||||
if (tag instanceof AbstractNumberTag)
|
||||
return ((AbstractNumberTag) tag).getDouble()!=0.0;
|
||||
if (tag instanceof StringTag)
|
||||
NbtElement tag = getTag();
|
||||
if (tag instanceof NbtCompound)
|
||||
return !((NbtCompound) tag).isEmpty();
|
||||
if (tag instanceof AbstractNbtList)
|
||||
return ((AbstractNbtList) tag).isEmpty();
|
||||
if (tag instanceof AbstractNbtNumber)
|
||||
return ((AbstractNbtNumber) tag).doubleValue()!=0.0;
|
||||
if (tag instanceof NbtString)
|
||||
return tag.asString().isEmpty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public CompoundTag getCompoundTag()
|
||||
public NbtCompound getCompoundTag()
|
||||
{
|
||||
try
|
||||
{
|
||||
ensureOwnership();
|
||||
return (CompoundTag) getTag();
|
||||
return (NbtCompound) getTag();
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
@@ -440,7 +442,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
/// WIP
|
||||
ensureOwnership();
|
||||
NbtPathArgumentType.NbtPath path = cachePath(where.getString());
|
||||
Tag tagToInsert = value instanceof NBTSerializableValue ?
|
||||
NbtElement tagToInsert = value instanceof NBTSerializableValue ?
|
||||
((NBTSerializableValue) value).getTag() :
|
||||
new NBTSerializableValue(value.getString()).getTag();
|
||||
boolean modifiedTag;
|
||||
@@ -470,17 +472,17 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
|
||||
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement)
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement)
|
||||
{
|
||||
return modify_insert(index, nbtPath, newElement, this.getTag());
|
||||
}
|
||||
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement, Tag currentTag)
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement, NbtElement currentTag)
|
||||
{
|
||||
Collection<Tag> targets;
|
||||
Collection<NbtElement> targets;
|
||||
try
|
||||
{
|
||||
targets = nbtPath.getOrInit(currentTag, ListTag::new);
|
||||
targets = nbtPath.getOrInit(currentTag, NbtList::new);
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -488,16 +490,16 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
boolean modified = false;
|
||||
for (Tag target : targets)
|
||||
for (NbtElement target : targets)
|
||||
{
|
||||
if (!(target instanceof AbstractListTag))
|
||||
if (!(target instanceof AbstractNbtList))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
AbstractListTag<?> targetList = (AbstractListTag) target;
|
||||
if (!targetList.addTag(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
|
||||
AbstractNbtList<?> targetList = (AbstractNbtList) target;
|
||||
if (!targetList.addElement(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
|
||||
return false;
|
||||
modified = true;
|
||||
}
|
||||
@@ -509,22 +511,22 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
|
||||
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
{
|
||||
if (!(replacement instanceof CompoundTag))
|
||||
if (!(replacement instanceof NbtCompound))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Tag ownTag = getTag();
|
||||
NbtElement ownTag = getTag();
|
||||
try
|
||||
{
|
||||
for (Tag target : nbtPath.getOrInit(ownTag, CompoundTag::new))
|
||||
for (NbtElement target : nbtPath.getOrInit(ownTag, NbtCompound::new))
|
||||
{
|
||||
if (!(target instanceof CompoundTag))
|
||||
if (!(target instanceof NbtCompound))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
((CompoundTag) target).copyFrom((CompoundTag) replacement);
|
||||
((NbtCompound) target).copyFrom((NbtCompound) replacement);
|
||||
}
|
||||
}
|
||||
catch (CommandSyntaxException ignored)
|
||||
@@ -534,9 +536,9 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
{
|
||||
Tag tag = getTag();
|
||||
NbtElement tag = getTag();
|
||||
String pathText = nbtPath.toString();
|
||||
if (pathText.endsWith("]")) // workaround for array replacement or item in the array replacement
|
||||
{
|
||||
@@ -584,7 +586,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
NbtPathArgumentType.NbtPath path = cachePath(valString);
|
||||
try
|
||||
{
|
||||
List<Tag> tags = path.get(getTag());
|
||||
List<NbtElement> tags = path.get(getTag());
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1 && !valString.endsWith("[]"))
|
||||
@@ -681,7 +683,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
ensureOwnership();
|
||||
|
||||
@@ -4,8 +4,8 @@ import java.util.ArrayList;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
{
|
||||
@@ -80,10 +80,10 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of("null");
|
||||
return NbtString.of("null");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,10 +3,10 @@ package carpet.script.value;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.LongTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtDouble;
|
||||
import net.minecraft.nbt.NbtInt;
|
||||
import net.minecraft.nbt.NbtLong;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -278,20 +278,20 @@ public class NumericValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (longValue != null)
|
||||
return LongTag.of(longValue);
|
||||
return NbtLong.of(longValue);
|
||||
long lv = getLong();
|
||||
if (value == (double)lv)
|
||||
{
|
||||
if (abs(value) < Integer.MAX_VALUE-2)
|
||||
return IntTag.of((int)lv);
|
||||
return LongTag.of(getLong());
|
||||
return NbtInt.of((int)lv);
|
||||
return NbtLong.of(getLong());
|
||||
}
|
||||
else
|
||||
{
|
||||
return DoubleTag.of(value);
|
||||
return NbtDouble.of(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class StringValue extends Value
|
||||
{
|
||||
@@ -43,8 +43,8 @@ public class StringValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
return StringTag.of(str);
|
||||
return NbtString.of(str);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import carpet.script.Tokenizer;
|
||||
import carpet.script.exception.ExitStatement;
|
||||
import carpet.script.exception.ExpressionException;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -117,7 +117,7 @@ public class ThreadValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return getValue().toTag(true);
|
||||
|
||||
@@ -3,7 +3,7 @@ package carpet.script.value;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -236,7 +236,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Tag toTag(boolean force);
|
||||
public abstract NbtElement toTag(boolean force);
|
||||
|
||||
public JsonElement toJson()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.utils.BlockInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.MapColor;
|
||||
import net.minecraft.block.pattern.CachedBlockPosition;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ai.brain.LookTarget;
|
||||
@@ -75,7 +75,7 @@ public class ValueConversions
|
||||
return of(world.getRegistryKey().getValue());
|
||||
}
|
||||
|
||||
public static Value of(MaterialColor color) {return ListValue.of(StringValue.of(BlockInfo.mapColourName.get(color)), ofRGB(color.color));}
|
||||
public static Value of(MapColor color) {return ListValue.of(StringValue.of(BlockInfo.mapColourName.get(color)), ofRGB(color.color));}
|
||||
|
||||
public static <T extends Number> Value of(NumberRange<T> range) { return ListValue.of(NumericValue.of(range.getMin()), NumericValue.of(range.getMax()));}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class ValueConversions
|
||||
{
|
||||
PathNode node = path.getNode(i);
|
||||
nodes.add( ListValue.of(
|
||||
new BlockValue(null, world, node.getPos()),
|
||||
new BlockValue(null, world, node.getBlockPos()),
|
||||
new StringValue(node.type.name().toLowerCase(Locale.ROOT)),
|
||||
new NumericValue(node.penalty),
|
||||
BooleanValue.of(node.visited)
|
||||
@@ -310,36 +310,32 @@ public class ValueConversions
|
||||
ListValue.fromTriple(box.maxX, box.maxY, box.maxZ)
|
||||
);
|
||||
}
|
||||
|
||||
public static Value of(BlockBox box)
|
||||
{
|
||||
return ListValue.of(
|
||||
ListValue.fromTriple(box.minX, box.minY, box.minZ),
|
||||
ListValue.fromTriple(box.maxX, box.maxY, box.maxZ)
|
||||
ListValue.fromTriple(box.getMinX(), box.getMinY(), box.getMinZ()),
|
||||
ListValue.fromTriple(box.getMaxX(), box.getMaxY(), box.getMaxZ())
|
||||
);
|
||||
}
|
||||
|
||||
public static Value of(StructureStart<?> structure)
|
||||
{
|
||||
if (structure == null || structure == StructureStart.DEFAULT) return Value.NULL;
|
||||
BlockBox boundingBox = structure.getBoundingBox();
|
||||
if (boundingBox.maxX < boundingBox.minX || boundingBox.maxY < boundingBox.minY || boundingBox.maxZ < boundingBox.minZ) return Value.NULL;
|
||||
BlockBox boundingBox = structure.setBoundingBoxFromChildren();
|
||||
if (boundingBox.getMaxX() < boundingBox.getMinX() || boundingBox.getMaxY() < boundingBox.getMinY() || boundingBox.getMaxZ() < boundingBox.getMinZ()) return Value.NULL;
|
||||
Map<Value, Value> ret = new HashMap<>();
|
||||
ret.put(new StringValue("box"), ListValue.of(
|
||||
ListValue.fromTriple(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
|
||||
ListValue.fromTriple(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ)
|
||||
));
|
||||
ret.put(new StringValue("box"), of(boundingBox));
|
||||
List<Value> pieces = new ArrayList<>();
|
||||
for (StructurePiece piece : structure.getChildren())
|
||||
{
|
||||
BlockBox box = piece.getBoundingBox();
|
||||
if (box.maxX >= box.minX && box.maxY >= box.minY && box.maxZ >= box.minZ)
|
||||
if (box.getMaxX() >= box.getMinX() && box.getMaxY() >= box.getMinY() && box.getMaxZ() >= box.getMinZ())
|
||||
{
|
||||
pieces.add(ListValue.of(
|
||||
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_PIECE.getId(piece.getType()))),
|
||||
(piece.getFacing() == null) ? Value.NULL : new StringValue(piece.getFacing().getName()),
|
||||
ListValue.fromTriple(box.minX, box.minY, box.minZ),
|
||||
ListValue.fromTriple(box.maxX, box.maxY, box.maxZ)
|
||||
ListValue.fromTriple(box.getMinX(), box.getMinY(), box.getMinZ()),
|
||||
ListValue.fromTriple(box.getMaxX(), box.getMaxY(), box.getMaxZ())
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -408,7 +404,7 @@ public class ValueConversions
|
||||
BlockPredicateInterface predicateData = (BlockPredicateInterface) blockPredicate;
|
||||
return ListValue.of(
|
||||
predicateData.getCMBlockState()==null?Value.NULL:of(Registry.BLOCK.getId(predicateData.getCMBlockState().getBlock())),
|
||||
predicateData.getCMBlockTag()==null?Value.NULL:of(tagManager.getBlocks().getTagId(predicateData.getCMBlockTag())),
|
||||
predicateData.getCMBlockTag()==null?Value.NULL:of(tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getUncheckedTagId(predicateData.getCMBlockTag())),
|
||||
MapValue.wrap(predicateData.getCMProperties()),
|
||||
predicateData.getCMDataTag() == null?Value.NULL:new NBTSerializableValue(predicateData.getCMDataTag())
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user