Merge branch 'master' into 1.16
This commit is contained in:
commit
bf2d412a66
19 files changed
+690
-78
No files matched your search
@@ -62,7 +62,7 @@ public class CarpetSettings
|
||||
@Rule(
|
||||
desc = "sets the language for carpet",
|
||||
category = FEATURE,
|
||||
options = {"none", "zh_cn"},
|
||||
options = {"none", "zh_cn", "zh_tw"},
|
||||
strict = false,
|
||||
validate = LanguageValidator.class
|
||||
)
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
|
||||
|
||||
@Mixin(PlayerManager.class)
|
||||
public class PlayerManager_coreMixin
|
||||
{
|
||||
@@ -16,5 +18,6 @@ public class PlayerManager_coreMixin
|
||||
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.onPlayerLoggedIn(player);
|
||||
PLAYER_CONNECTS.onPlayerEvent(player);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_DISCONNECTS;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class ServerPlayNetworkHandler_coreMixin {
|
||||
@Shadow
|
||||
@@ -21,5 +23,6 @@ public class ServerPlayNetworkHandler_coreMixin {
|
||||
@Inject(method = "onDisconnected", at = @At("HEAD"))
|
||||
private void onPlayerDisconnect(Text reason, CallbackInfo ci) {
|
||||
CarpetServer.onPlayerLoggedOut(this.player);
|
||||
if (PLAYER_DISCONNECTS.isNeeded()) PLAYER_DISCONNECTS.onPlayerMessage(player, reason.asString());
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ClientNetworkHandler
|
||||
}
|
||||
});
|
||||
put("TickRate", (p, t) -> TickSpeed.tickrate(((AbstractNumberTag)t).getFloat(), false));
|
||||
put("renderShape", (p, t) -> {
|
||||
put("scShape", (p, t) -> {
|
||||
if (CarpetClient.shapes != null)
|
||||
CarpetClient.shapes.addShape((CompoundTag)t);
|
||||
});
|
||||
|
||||
@@ -128,7 +128,13 @@ public class CarpetEventServer
|
||||
List<LazyValue> argv = argumentSupplier.get(); // empty for onTickDone
|
||||
ServerCommandSource source = cmdSourceSupplier.get();
|
||||
assert argv.size() == reqArgs;
|
||||
callList.removeIf(call -> !CarpetServer.scriptServer.runas(source, call.host, call.function, argv)); // this actually does the calls
|
||||
List<Callback> fails = new ArrayList<>();
|
||||
for (Callback call: callList)
|
||||
{
|
||||
if (!CarpetServer.scriptServer.runas(source, call.host, call.function, argv))
|
||||
fails.add(call);
|
||||
}
|
||||
for (Callback call : fails) callList.remove(call);
|
||||
}
|
||||
}
|
||||
public boolean addEventCall(ServerCommandSource source, String hostName, String funName, Function<ScriptHost, Boolean> verifier)
|
||||
@@ -549,6 +555,23 @@ public class CarpetEventServer
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CONNECTS("player_connects", 1, false) {
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DISCONNECTS("player_disconnects", 2, false) {
|
||||
@Override
|
||||
public void onPlayerMessage(ServerPlayerEntity player, String message)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new StringValue(message))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
STATISTICS("statistic", 4, false)
|
||||
{
|
||||
private <T> Identifier getStatId(Stat<T> stat)
|
||||
@@ -613,6 +636,7 @@ public class CarpetEventServer
|
||||
public void onTick() { }
|
||||
public void onChunkGenerated(ServerWorld world, Chunk chunk) { }
|
||||
public void onPlayerEvent(ServerPlayerEntity player) { }
|
||||
public void onPlayerMessage(ServerPlayerEntity player, String message) { }
|
||||
public void onPlayerStatistic(ServerPlayerEntity player, Stat<?> stat, int amount) { }
|
||||
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking) { }
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack) { }
|
||||
|
||||
@@ -2704,7 +2704,7 @@ public class CarpetExpression
|
||||
ServerPlayerEntity player = null;
|
||||
if (params.containsKey("player"))
|
||||
{
|
||||
player = (ServerPlayerEntity) ((EntityValue)params.get("player")).getEntity();
|
||||
player = (ServerPlayerEntity)((EntityValue)params.get("player")).getEntity();
|
||||
}
|
||||
ShapeDispatcher.sendShape(
|
||||
(player==null)?cc.s.getWorld().getPlayers():Collections.singletonList(player),
|
||||
@@ -2987,6 +2987,12 @@ public class CarpetExpression
|
||||
return (cc, tt) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("view_distance", 0, (c, t, lv) -> {
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
Value retval = new NumericValue(s.getMinecraftServer().getPlayerManager().getViewDistance());
|
||||
return (cc, tt) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
ServerCommandSource outerSource = ((CarpetContext)c).s;
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
public void addUserDefinedFunction(Context ctx, Module module, String funName, FunctionValue function)
|
||||
{
|
||||
super.addUserDefinedFunction(ctx, module, funName, function);
|
||||
// mcarpet
|
||||
if (ctx.host.main != module) return; // not dealing with automatic imports / exports /configs / apps from imports
|
||||
if (funName.startsWith("__")) // potential fishy activity
|
||||
{
|
||||
if (funName.startsWith("__on_")) // here we can make a determination if we want to only accept events from main module.
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.arguments.ParticleArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.FloatTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
@@ -27,6 +28,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
@@ -39,6 +41,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -59,7 +62,7 @@ public class ShapeDispatcher
|
||||
if (ServerNetworkHandler.validCarpetPlayers.contains(player))
|
||||
{
|
||||
if (tag == null) tag = ExpiringShape.toTag(params);
|
||||
ServerNetworkHandler.sendCustomCommand(player,"renderShape", tag);
|
||||
ServerNetworkHandler.sendCustomCommand(player,"scShape", tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -105,16 +108,14 @@ public class ShapeDispatcher
|
||||
public static ExpiringShape create(CarpetContext cc, String shapeType, Map<String, Value> userParams)
|
||||
{
|
||||
userParams.put("shape", new StringValue(shapeType));
|
||||
Map<String, Value> validatedParams = new HashMap<>();
|
||||
userParams.forEach((key, value) ->
|
||||
{
|
||||
userParams.keySet().forEach(key -> {
|
||||
Param param = Param.coders.get(key);
|
||||
if (param==null) throw new InternalExpressionException("Unknown feature for shape: "+key);
|
||||
validatedParams.put(key, param.validate(cc, value));
|
||||
userParams.put(key, param.validate(cc, userParams.get(key)));
|
||||
});
|
||||
Function<Map<String, Value>,ExpiringShape> factory = ExpiringShape.shapeProviders.get(shapeType);
|
||||
if (factory == null) throw new InternalExpressionException("Unknown shape: "+shapeType);
|
||||
return factory.apply(validatedParams);
|
||||
return factory.apply(userParams);
|
||||
}
|
||||
|
||||
// client
|
||||
@@ -126,7 +127,7 @@ public class ShapeDispatcher
|
||||
Function<Tag, Value> decoder = Param.decoders.get(key);
|
||||
if (decoder==null)
|
||||
{
|
||||
CarpetSettings.LOG.error("Unknown parameter for shape: "+key);
|
||||
CarpetSettings.LOG.info("Unknown parameter for shape: "+key);
|
||||
return null;
|
||||
}
|
||||
Value decodedValue = decoder.apply(tag.get(key));
|
||||
@@ -135,13 +136,13 @@ public class ShapeDispatcher
|
||||
Value shapeValue = options.get("shape");
|
||||
if (shapeValue == null)
|
||||
{
|
||||
CarpetSettings.LOG.error("Shape id missing in "+ String.join(", ", tag.getKeys()));
|
||||
CarpetSettings.LOG.info("Shape id missing in "+ String.join(", ", tag.getKeys()));
|
||||
return null;
|
||||
}
|
||||
Function<Map<String, Value>,ExpiringShape> factory = ExpiringShape.shapeProviders.get(shapeValue.getString());
|
||||
if (factory == null)
|
||||
{
|
||||
CarpetSettings.LOG.error("Unknown shape: "+shapeValue.getString());
|
||||
CarpetSettings.LOG.info("Unknown shape: "+shapeValue.getString());
|
||||
return null;
|
||||
}
|
||||
try
|
||||
@@ -150,7 +151,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
catch (InternalExpressionException exc)
|
||||
{
|
||||
CarpetSettings.LOG.error(exc.getMessage());
|
||||
CarpetSettings.LOG.info(exc.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -160,6 +161,7 @@ public class ShapeDispatcher
|
||||
public static final Map<String, Function<Map<String, Value>,ExpiringShape>> shapeProviders = new HashMap<String, Function<Map<String, Value>, ExpiringShape>>(){{
|
||||
put("line", creator(Line::new));
|
||||
put("box", creator(Box::new));
|
||||
put("sphere", creator(Sphere::new));
|
||||
}};
|
||||
private static Function<Map<String, Value>,ExpiringShape> creator(Supplier<ExpiringShape> shapeFactory)
|
||||
{
|
||||
@@ -229,7 +231,10 @@ public class ShapeDispatcher
|
||||
}
|
||||
// list of params that need to be there
|
||||
private final Set<String> required = ImmutableSet.of("duration", "shape", "dim");
|
||||
private final Map<String, Value> optional = ImmutableMap.of("color", new NumericValue(-1));
|
||||
private final Map<String, Value> optional = ImmutableMap.of(
|
||||
"color", new NumericValue(-1),
|
||||
"player", Value.NULL
|
||||
);
|
||||
protected Set<String> requiredParams() {return required;}
|
||||
// list of params that can be there, with defaults
|
||||
protected Set<String> optionalParams() {return optional.keySet();}
|
||||
@@ -238,7 +243,10 @@ public class ShapeDispatcher
|
||||
public static class Box extends ExpiringShape
|
||||
{
|
||||
private final Set<String> required = ImmutableSet.of("from", "to");
|
||||
private final Map<String, Value> optional = ImmutableMap.of();
|
||||
private final Map<String, Value> optional = ImmutableMap.of(
|
||||
"width", new NumericValue(2.0),
|
||||
"fill", new NumericValue(0xffffff00)
|
||||
);
|
||||
@Override
|
||||
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
|
||||
@Override
|
||||
@@ -247,6 +255,10 @@ public class ShapeDispatcher
|
||||
|
||||
float x1, y1, z1;
|
||||
float x2, y2, z2;
|
||||
float lineWidth;
|
||||
|
||||
protected float fr, fg, fb, fa;
|
||||
protected int fillColor;
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Value> options)
|
||||
@@ -260,6 +272,12 @@ public class ShapeDispatcher
|
||||
x2 = NumericValue.asNumber(to.get(0)).getFloat();
|
||||
y2 = NumericValue.asNumber(to.get(1)).getFloat();
|
||||
z2 = NumericValue.asNumber(to.get(2)).getFloat();
|
||||
lineWidth = NumericValue.asNumber(options.getOrDefault("width", optional.get("width"))).getFloat();
|
||||
fillColor = NumericValue.asNumber(options.getOrDefault("fill", optional.get("fill"))).getInt();
|
||||
this.fr = (float)(fillColor >> 24 & 0xFF) / 255.0F;
|
||||
this.fg = (float)(fillColor >> 16 & 0xFF) / 255.0F;
|
||||
this.fb = (float)(fillColor >> 8 & 0xFF) / 255.0F;
|
||||
this.fa = (float)(fillColor & 0xFF) / 255.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,6 +303,8 @@ public class ShapeDispatcher
|
||||
hash = 31*hash + Float.hashCode(x2);
|
||||
hash = 31*hash + Float.hashCode(y2);
|
||||
hash = 31*hash + Float.hashCode(z2);
|
||||
hash = 31*hash + Float.hashCode(lineWidth);
|
||||
if (fa != 0.0) hash = 31*hash + fillColor;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -312,7 +332,7 @@ public class ShapeDispatcher
|
||||
public static class Line extends ExpiringShape
|
||||
{
|
||||
private final Set<String> required = ImmutableSet.of("from", "to");
|
||||
private final Map<String, Value> optional = ImmutableMap.of();
|
||||
private final Map<String, Value> optional = ImmutableMap.of("width", new NumericValue(2.0));
|
||||
@Override
|
||||
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
|
||||
@Override
|
||||
@@ -325,6 +345,7 @@ public class ShapeDispatcher
|
||||
|
||||
float x1, y1, z1;
|
||||
float x2, y2, z2;
|
||||
float lineWidth;
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Value> options)
|
||||
@@ -338,6 +359,7 @@ public class ShapeDispatcher
|
||||
x2 = NumericValue.asNumber(to.get(0)).getFloat();
|
||||
y2 = NumericValue.asNumber(to.get(1)).getFloat();
|
||||
z2 = NumericValue.asNumber(to.get(2)).getFloat();
|
||||
lineWidth = NumericValue.asNumber(options.getOrDefault("width", optional.get("width"))).getFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -365,10 +387,88 @@ public class ShapeDispatcher
|
||||
hash = 31*hash + Float.hashCode(x2);
|
||||
hash = 31*hash + Float.hashCode(y2);
|
||||
hash = 31*hash + Float.hashCode(z2);
|
||||
hash = 31*hash + Float.hashCode(lineWidth);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sphere extends ExpiringShape
|
||||
{
|
||||
private final Set<String> required = ImmutableSet.of("center", "radius");
|
||||
private final Map<String, Value> optional = ImmutableMap.of("width", new NumericValue(2.0), "level", Value.ZERO);
|
||||
@Override
|
||||
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
|
||||
@Override
|
||||
protected Set<String> optionalParams() { return Sets.union(super.optionalParams(), optional.keySet()); }
|
||||
|
||||
private Sphere()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
float cx, cy, cz;
|
||||
float radius;
|
||||
int level;
|
||||
int subdivisions;
|
||||
float lineWidth;
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Value> options)
|
||||
{
|
||||
super.init(options);
|
||||
List<Value> from = ((ListValue)options.get("center")).getItems();
|
||||
cx = NumericValue.asNumber(from.get(0)).getFloat();
|
||||
cy = NumericValue.asNumber(from.get(1)).getFloat();
|
||||
cz = NumericValue.asNumber(from.get(2)).getFloat();
|
||||
radius = NumericValue.asNumber(options.get("radius")).getFloat();
|
||||
level = NumericValue.asNumber(options.getOrDefault("level", optional.get("level"))).getInt();
|
||||
subdivisions = level;
|
||||
if (subdivisions <= 0)
|
||||
{
|
||||
subdivisions = Math.max(10, (int)(10*Math.sqrt(radius)));
|
||||
}
|
||||
lineWidth = NumericValue.asNumber(options.getOrDefault("width", optional.get("width"))).getFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer<ServerPlayerEntity> alternative() { return p ->
|
||||
{
|
||||
String particleName = String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", r, g, b);
|
||||
ParticleEffect particle = getParticleData(particleName);
|
||||
float pihalf = (float)(Math.PI / 180.0f);
|
||||
int partno = Math.min(1000,20*subdivisions);
|
||||
Random rand = p.world.getRandom();
|
||||
ServerWorld world = p.getServerWorld();
|
||||
for (int i=0; i<partno; i++)
|
||||
{
|
||||
float theta = 360.0f*rand.nextFloat()*pihalf;
|
||||
float phi = 180f*rand.nextFloat()*pihalf;
|
||||
float x = radius * MathHelper.sin(phi) * MathHelper.cos(theta);
|
||||
float y = radius * MathHelper.sin(phi) * MathHelper.sin(theta);
|
||||
float z = radius * MathHelper.cos(phi);
|
||||
world.spawnParticles(p, particle, true,
|
||||
x+cx, y+cy, z+cz, 1,
|
||||
0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
};}
|
||||
|
||||
@Override
|
||||
public int calcKey()
|
||||
{
|
||||
int hash = super.calcKey();
|
||||
hash = 31*hash + 3;
|
||||
hash = 31*hash + Float.hashCode(cx);
|
||||
hash = 31*hash + Float.hashCode(cy);
|
||||
hash = 31*hash + Float.hashCode(cz);
|
||||
hash = 31*hash + Float.hashCode(radius);
|
||||
hash = 31*hash + level;
|
||||
hash = 31*hash + Float.hashCode(lineWidth);
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface Param
|
||||
{
|
||||
Map<String, Function<Tag, Value>> decoders = new HashMap<String, Function<Tag, Value>>(){{
|
||||
@@ -378,16 +478,25 @@ public class ShapeDispatcher
|
||||
put("color", ShapeDispatcher::decodeInt);
|
||||
put("from", Vec3Param::decode);
|
||||
put("to", Vec3Param::decode);
|
||||
|
||||
put("width", ShapeDispatcher::decodeFloat);
|
||||
put("fill", ShapeDispatcher::decodeInt);
|
||||
put("center", Vec3Param::decode);
|
||||
put("radius", ShapeDispatcher::decodeFloat);
|
||||
put("level", ShapeDispatcher::decodeInt);
|
||||
}};
|
||||
Map<String, Param> coders = new HashMap<String, Param>(){{
|
||||
put("shape", new ShapeParam());
|
||||
put("player", new PlayerParam());
|
||||
put("shape", new ShapeParam());
|
||||
put("dim", new DimensionParam());
|
||||
put("duration", new DurationParam());
|
||||
put("color", new ColorParam());
|
||||
put("from", new FromParam());
|
||||
put("to", new ToParam());
|
||||
put("width", new WidthParam());
|
||||
put("fill", new FillColorParam());
|
||||
put("center", new CenterParam());
|
||||
put("radius", new RadiusParam());
|
||||
put("level", new LevelParam());
|
||||
}};
|
||||
Tag toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
|
||||
Value validate(CarpetContext cc, Value value); // makes sure the value is proper
|
||||
@@ -448,8 +557,6 @@ public class ShapeDispatcher
|
||||
}
|
||||
public static abstract class NumericParam implements Param
|
||||
{
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value).getInt()); }
|
||||
@Override
|
||||
public Value validate(CarpetContext cc, Value value)
|
||||
{
|
||||
@@ -467,15 +574,34 @@ public class ShapeDispatcher
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
public static abstract class PositiveFloatParam extends PositiveParam
|
||||
{
|
||||
@Override
|
||||
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value).getFloat()); }
|
||||
|
||||
}
|
||||
public static abstract class PositiveIntParam extends PositiveParam
|
||||
{
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value).getInt()); }
|
||||
|
||||
}
|
||||
public static Value decodeInt(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
|
||||
public static class DurationParam extends PositiveParam
|
||||
public static Value decodeFloat(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
|
||||
public static class DurationParam extends PositiveIntParam
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return true; }
|
||||
@Override
|
||||
public String identify() { return "duration"; }
|
||||
}
|
||||
public static class WidthParam extends PositiveFloatParam
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box || shape instanceof Line; }
|
||||
@Override
|
||||
public String identify() { return "width"; }
|
||||
}
|
||||
|
||||
public static abstract class Vec3Param implements Param
|
||||
{
|
||||
@@ -542,12 +668,22 @@ public class ShapeDispatcher
|
||||
}
|
||||
public static class ColorParam extends NumericParam
|
||||
{
|
||||
@Override
|
||||
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value).getInt()); }
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return true; }
|
||||
@Override
|
||||
public String identify() { return "color"; }
|
||||
}
|
||||
|
||||
public static class FillColorParam extends ColorParam
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box; }
|
||||
@Override
|
||||
public String identify() { return "fill"; }
|
||||
}
|
||||
|
||||
public static class FromParam extends Vec3Param
|
||||
{
|
||||
@Override
|
||||
@@ -568,6 +704,30 @@ public class ShapeDispatcher
|
||||
public String identify() { return "to"; }
|
||||
}
|
||||
|
||||
public static class CenterParam extends Vec3Param
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return (shape instanceof Sphere); }
|
||||
@Override
|
||||
public boolean roundsUpForBlocks() { return false; }
|
||||
@Override
|
||||
public String identify() { return "center"; }
|
||||
}
|
||||
public static class RadiusParam extends PositiveFloatParam
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Sphere; }
|
||||
@Override
|
||||
public String identify() { return "radius"; }
|
||||
}
|
||||
public static class LevelParam extends PositiveIntParam
|
||||
{
|
||||
@Override
|
||||
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Sphere; }
|
||||
@Override
|
||||
public String identify() { return "level"; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static boolean isStraight(Vec3d from, Vec3d to, double density)
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
@@ -32,6 +33,7 @@ public class ShapesRenderer
|
||||
{{
|
||||
put("line", RenderedLine::new);
|
||||
put("box", RenderedBox::new);
|
||||
put("sphere", RenderedSphere::new);
|
||||
}};
|
||||
|
||||
public ShapesRenderer(MinecraftClient minecraftClient)
|
||||
@@ -93,12 +95,9 @@ public class ShapesRenderer
|
||||
if (shape == null) return;
|
||||
BiFunction<MinecraftClient, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
|
||||
shapeFactory = renderedShapes.get(tag.getString("shape"));
|
||||
|
||||
|
||||
|
||||
if (shapeFactory == null)
|
||||
{
|
||||
CarpetSettings.LOG.error("Unrecognized shape: "+tag.getString("shape"));
|
||||
CarpetSettings.LOG.info("Unrecognized shape: "+tag.getString("shape"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -163,9 +162,9 @@ public class ShapesRenderer
|
||||
@Override
|
||||
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
|
||||
{
|
||||
RenderSystem.lineWidth(2.0F);
|
||||
bufferBuilder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
|
||||
drawBoxWireGLLines(bufferBuilder,
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
|
||||
drawBoxWireGLLines(tessellator, bufferBuilder,
|
||||
shape.x1 - cx-renderEpsilon, shape.y1 - cy-renderEpsilon, shape.z1 - cz-renderEpsilon,
|
||||
shape.x2 - cx+renderEpsilon, shape.y2 - cy+renderEpsilon, shape.z2 - cz+renderEpsilon,
|
||||
shape.r, shape.g, shape.b, shape.a, shape.r, shape.g, shape.b
|
||||
@@ -175,14 +174,15 @@ public class ShapesRenderer
|
||||
@Override
|
||||
public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
|
||||
{
|
||||
if (shape.fa == 0.0) return;
|
||||
RenderSystem.lineWidth(1.0F);
|
||||
bufferBuilder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); // 3
|
||||
drawBox(bufferBuilder,
|
||||
|
||||
drawBoxFaces(tessellator, bufferBuilder,
|
||||
shape.x1-cx-renderEpsilon, shape.y1-cy-renderEpsilon, shape.z1-cz-renderEpsilon,
|
||||
shape.x2-cx+renderEpsilon, shape.y2-cy+renderEpsilon, shape.z2-cz+renderEpsilon,
|
||||
shape.r, shape.g, shape.b, shape.a/6
|
||||
shape.fr, shape.fg, shape.fb, shape.fa
|
||||
);
|
||||
tessellator.draw();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,26 +195,43 @@ public class ShapesRenderer
|
||||
@Override
|
||||
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
|
||||
{
|
||||
RenderSystem.lineWidth(2.0F);
|
||||
bufferBuilder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
|
||||
drawLine(bufferBuilder,
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
drawLine(tessellator, bufferBuilder,
|
||||
shape.x1-cx-renderEpsilon, shape.y1-cy-renderEpsilon, shape.z1-cz-renderEpsilon,
|
||||
shape.x2-cx+renderEpsilon, shape.y2-cy+renderEpsilon, shape.z2-cz+renderEpsilon,
|
||||
shape.r, shape.g, shape.b, shape.a
|
||||
);
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public static class RenderedSphere extends RenderedShape<ShapeDispatcher.Sphere>
|
||||
{
|
||||
public RenderedSphere(MinecraftClient client, ShapeDispatcher.ExpiringShape shape)
|
||||
{
|
||||
super(client, (ShapeDispatcher.Sphere)shape);
|
||||
}
|
||||
@Override
|
||||
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
|
||||
{
|
||||
RenderSystem.lineWidth(shape.lineWidth);
|
||||
drawSphereWireframe(tessellator, bufferBuilder,
|
||||
shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon,
|
||||
shape.radius, shape.subdivisions,
|
||||
shape.r, shape.g, shape.b, shape.a);
|
||||
}
|
||||
}
|
||||
|
||||
// some raw shit
|
||||
|
||||
public static void drawLine(BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) {
|
||||
|
||||
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.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawBoxWireGLLines(BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) {
|
||||
public static void drawBoxWireGLLines(Tessellator tessellator, BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) {
|
||||
builder.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR); // 3
|
||||
builder.vertex(x1, y1, z1).color(red1, grn2, blu2, alpha).next();
|
||||
builder.vertex(x2, y1, z1).color(red1, grn2, blu2, alpha).next();
|
||||
builder.vertex(x1, y1, z1).color(red2, grn1, blu2, alpha).next();
|
||||
@@ -241,7 +258,8 @@ public class ShapesRenderer
|
||||
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
|
||||
}
|
||||
|
||||
public static void drawBox(BufferBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) {
|
||||
public static void drawBoxFaces(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_QUADS, VertexFormats.POSITION_COLOR); // 3
|
||||
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
|
||||
@@ -271,5 +289,44 @@ public class ShapesRenderer
|
||||
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
|
||||
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawSphereWireframe(Tessellator tessellator, BufferBuilder builder,
|
||||
float cx, float cy, float cz,
|
||||
float r, int subd,
|
||||
float red, float grn, float blu, float alpha)
|
||||
{
|
||||
float pihalf = (float)(Math.PI / 180.0f);
|
||||
float step = 180f / (subd/2);
|
||||
for (float i = 0f; i <= 360.0f; i+=step)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
float theta = i * pihalf;
|
||||
for (float j = 0f; j <= 180.0f; j+=step) {
|
||||
float phi = j * pihalf;
|
||||
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
|
||||
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
|
||||
float y = r * MathHelper.cos(phi);
|
||||
builder.vertex(x+cx, y+cy, z+cz).color(red, grn, blu, alpha).next();
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
for (float j = 0f; j <= 180.0f; j+=step)
|
||||
{
|
||||
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
|
||||
float phi = j * pihalf;
|
||||
|
||||
for (float i = 0f; i <= 360.0f; i+=step)
|
||||
{
|
||||
float theta = i * pihalf;
|
||||
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
|
||||
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
|
||||
float y = r * MathHelper.cos(phi);
|
||||
builder.vertex(x+cx, y+cy, z+cz).color(red, grn, blu, alpha).next();
|
||||
}
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import carpet.script.Expression;
|
||||
import carpet.script.Fluff;
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.Tokenizer;
|
||||
import carpet.script.bundled.Module;
|
||||
import carpet.script.exception.BreakStatement;
|
||||
import carpet.script.exception.ContinueStatement;
|
||||
import carpet.script.exception.ExitStatement;
|
||||
@@ -58,6 +59,8 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
return name;
|
||||
}
|
||||
|
||||
public Module getModule() {return expression.module;}
|
||||
|
||||
@Override
|
||||
public String getPrettyString()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user