Merge branch 'master' into 1.16

# Conflicts:
#	src/main/java/carpet/script/utils/ShapeDispatcher.java
This commit is contained in:
gnembon committed 2020-06-04 02:35:05 -03:00
commit 8fe3508fdd
5 files changed
+271 -82

No files matched your search

+3
View File
@@ -3162,6 +3162,9 @@ Available shapes:
* `to` - other end of the line, same format as `from`
* Optional attributes:
* `width` - line thickness, defaults to 2.0pt
* `follow` - entity, or player name. Shape will follow an entity instead of being static.
Follow attribute requires all positional arguments to be relative to the entity and disallow
of using entity or block as position markers. You must specify positions as a triple.
* `'box'` - draws a box with corners in specified points
* Required attributes:
+3
View File
@@ -68,6 +68,9 @@ Available shapes:
* `to` - other end of the line, same format as `from`
* Optional attributes:
* `width` - line thickness, defaults to 2.0pt
* `follow` - entity, or player name. Shape will follow an entity instead of being static.
Follow attribute requires all positional arguments to be relative to the entity and disallow
of using entity or block as position markers. You must specify positions as a triple.
* `'box'` - draws a box with corners in specified points
* Required attributes:
@@ -111,7 +111,7 @@ public class ShapeDispatcher
userParams.keySet().forEach(key -> {
Param param = Param.coders.get(key);
if (param==null) throw new InternalExpressionException("Unknown feature for shape: "+key);
userParams.put(key, param.validate(cc, userParams.get(key)));
userParams.put(key, param.validate(userParams, cc, userParams.get(key)));
});
Function<Map<String, Value>,ExpiringShape> factory = ExpiringShape.shapeProviders.get(shapeType);
if (factory == null) throw new InternalExpressionException("Unknown shape: "+shapeType);
@@ -176,6 +176,9 @@ public class ShapeDispatcher
protected int color;
protected int duration = 0;
private int key;
protected int followEntity;
protected DimensionType entityDimension;
protected ExpiringShape() { }
@@ -214,8 +217,19 @@ public class ShapeDispatcher
this.b = (float)(color >> 8 & 0xFF) / 255.0F;
this.a = (float)(color & 0xFF) / 255.0F;
key = 0;
followEntity = -1;
entityDimension = null;
if (options.containsKey("follow"))
{
followEntity = NumericValue.asNumber(options.getOrDefault("follow", optional.get("follow"))).getInt();
entityDimension = Registry.DIMENSION_TYPE.get(new Identifier(options.get("dim").getString()));
}
}
public int getExpiry() { return duration; }
public Vec3d toAbsolute(Entity e, float x, float y, float z)
{
return e.getPos().add(x,y,z);
}
public abstract Consumer<ServerPlayerEntity> alternative();
public int key()
{
@@ -227,13 +241,15 @@ public class ShapeDispatcher
{
int hash = 17;
hash = 31*hash + color;
hash = 31*hash + followEntity;
return hash;
}
// 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),
"player", Value.NULL
"player", Value.NULL,
"follow", new NumericValue(-1)
);
protected Set<String> requiredParams() {return required;}
// list of params that can be there, with defaults
@@ -283,13 +299,26 @@ public class ShapeDispatcher
@Override
public Consumer<ServerPlayerEntity> alternative()
{
String particleName = String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", r, g, b);
ParticleEffect particle = getParticleData(particleName);
double dx = x1-x2;
double dy = y1-y2;
double dz = z1-z2;
double density = Math.max(2.0, Math.sqrt(dx*dx+dy*dy+dz*dz) /50) / (a+0.1);
return p -> mesh(Collections.singletonList(p), particle, density, x1, y1, z1, x2, y2, z2);
return p ->
{
if (followEntity == -1)
{
mesh(Collections.singletonList(p), particle, density, x1, y1, z1, x2, y2, z2);
return;
}
Entity e = p.getServer().getWorld(entityDimension).getEntityById(followEntity);
if (e == null) return;
Vec3d rel1 = toAbsolute(e, x1, y1, z1);
Vec3d rel2 = toAbsolute(e, x2, y2, z2);
mesh(Collections.singletonList(p), particle, density, rel1.x, rel1.y, rel1.z, rel2.x, rel2.y, rel2.z);
};
}
@Override
@@ -373,7 +402,20 @@ public class ShapeDispatcher
double dy = y1-y2;
double dz = z1-z2;
double density = Math.max(2.0, Math.sqrt(dx*dx+dy*dy+dz*dz) /50) / (a+0.1);
return p -> drawParticleLine(Collections.singletonList(p), particle, pos1, pos2, density);
return p ->
{
if (followEntity == -1)
{
drawParticleLine(Collections.singletonList(p), particle, pos1, pos2, density);
return;
}
Entity e = p.getServer().getWorld(entityDimension).getEntityById(followEntity);
if (e == null) return;
Vec3d rel1 = toAbsolute(e, x1, y1, z1);
Vec3d rel2 = toAbsolute(e, x2, y2, z2);
drawParticleLine(Collections.singletonList(p), particle, rel1, rel2, density);
};
}
@Override
@@ -395,7 +437,11 @@ public class ShapeDispatcher
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);
private final Map<String, Value> optional = ImmutableMap.of(
"width", new NumericValue(2.0),
"level", Value.ZERO,
"fill", new NumericValue(0xffffff00)
);
@Override
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
@Override
@@ -412,6 +458,9 @@ public class ShapeDispatcher
int subdivisions;
float lineWidth;
protected float fr, fg, fb, fa;
protected int fillColor;
@Override
protected void init(Map<String, Value> options)
{
@@ -428,6 +477,11 @@ public class ShapeDispatcher
subdivisions = Math.max(10, (int)(10*Math.sqrt(radius)));
}
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
@@ -439,15 +493,32 @@ public class ShapeDispatcher
int partno = Math.min(1000,20*subdivisions);
Random rand = p.world.getRandom();
ServerWorld world = p.getServerWorld();
float ccx, ccy, ccz;
if (followEntity == -1)
{
ccx = cx; ccy = cy; ccz = cz;
}
else
{
Entity e = p.getServer().getWorld(entityDimension).getEntityById(followEntity);
if (e == null) return;
Vec3d rel1 = toAbsolute(e, cx, cy, cz);
ccx = (float)rel1.x; ccy = (float)rel1.y; ccz = (float)rel1.z;
}
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);
//float theta = 360.0f*rand.nextFloat()*pihalf;
//float phi = 180f*rand.nextFloat()*pihalf;
float theta = (float)Math.asin(rand.nextFloat()*2.0-1.0);
float phi = (float)(2*Math.PI*rand.nextFloat());
float x = radius * MathHelper.cos(theta) * MathHelper.cos(phi);
float y = radius * MathHelper.cos(theta) * MathHelper.sin(phi);
float z = radius * MathHelper.sin(theta);
world.spawnParticles(p, particle, true,
x+cx, y+cy, z+cz, 1,
x+ccx, y+ccy, z+ccz, 1,
0.0, 0.0, 0.0, 0.0);
}
};}
@@ -463,7 +534,7 @@ public class ShapeDispatcher
hash = 31*hash + Float.hashCode(radius);
hash = 31*hash + level;
hash = 31*hash + Float.hashCode(lineWidth);
if (fa != 0.0) hash = 31*hash + fillColor;
return hash;
}
}
@@ -476,6 +547,8 @@ public class ShapeDispatcher
put("dim", StringParam::decode);
put("duration", ShapeDispatcher::decodeInt);
put("color", ShapeDispatcher::decodeInt);
put("follow", EntityParam::decode);
put("from", Vec3Param::decode);
put("to", Vec3Param::decode);
put("width", ShapeDispatcher::decodeFloat);
@@ -490,6 +563,8 @@ public class ShapeDispatcher
put("dim", new DimensionParam());
put("duration", new DurationParam());
put("color", new ColorParam());
put("follow", new FollowParam());
put("from", new FromParam());
put("to", new ToParam());
put("width", new WidthParam());
@@ -499,7 +574,7 @@ public class ShapeDispatcher
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
Value validate(Map<String, Value> options, CarpetContext cc, Value value); // makes sure the value is proper
boolean appliesTo(ExpiringShape shape); // check if applies to the shape
String identify();
}
@@ -509,7 +584,7 @@ public class ShapeDispatcher
public Tag toTag(Value value) { return null; }
@Override
public Value validate(CarpetContext cc, Value value)
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getMinecraftServer(), value);
if (player == null)
@@ -528,13 +603,19 @@ public class ShapeDispatcher
{
@Override
public Tag toTag(Value value) { return StringTag.of(value.getString()); }
@Override
public Value validate(CarpetContext cc, Value value) { return value; }
public static Value decode(Tag tag) { return new StringValue(tag.asString()); }
}
public static class DimensionParam extends StringParam
{
@Override
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
String dimStr = value.getString();
Optional<DimensionType> dimOp = Registry.DIMENSION_TYPE.getOrEmpty(new Identifier(dimStr));
if (!dimOp.isPresent()) throw new InternalExpressionException("Unknown dimension "+dimStr);
return value;
}
@Override
public boolean appliesTo(ExpiringShape shape) { return true; }
@Override
@@ -543,7 +624,7 @@ public class ShapeDispatcher
public static class ShapeParam extends StringParam
{
@Override
public Value validate(CarpetContext cc, Value value)
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
String shape = value.getString();
if (!ExpiringShape.shapeProviders.containsKey(shape))
@@ -558,7 +639,7 @@ public class ShapeDispatcher
public static abstract class NumericParam implements Param
{
@Override
public Value validate(CarpetContext cc, Value value)
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
if (!(value instanceof NumericValue))
throw new InternalExpressionException("'" + identify() + "' needs to be a number");
@@ -567,9 +648,9 @@ public class ShapeDispatcher
}
public static abstract class PositiveParam extends NumericParam
{
@Override public Value validate(CarpetContext cc, Value value)
@Override public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
Value ret = super.validate(cc, value);
Value ret = super.validate(options, cc, value);
if (((NumericValue)ret).getDouble()<=0) throw new InternalExpressionException("'"+identify()+"' should be positive");
return ret;
}
@@ -610,10 +691,12 @@ public class ShapeDispatcher
public abstract String identify();
@Override
public Value validate(CarpetContext cc, Value value)
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
if (value instanceof BlockValue)
{
if (options.containsKey("follow"))
throw new InternalExpressionException(identify()+" parameter cannot use blocks as positions for relative positioning due to 'follow' attribute being present");
BlockPos pos = ((BlockValue) value).getPos();
int offset = roundsUpForBlocks()?1:0;
return ListValue.of(
@@ -635,6 +718,8 @@ public class ShapeDispatcher
}
if (value instanceof EntityValue)
{
if (options.containsKey("follow"))
throw new InternalExpressionException(identify()+" parameter cannot use entity as positions for relative positioning due to 'follow' attribute being present");
Entity e = ((EntityValue) value).getEntity();
return ListValue.of(
new NumericValue(e.getX()),
@@ -679,7 +764,7 @@ public class ShapeDispatcher
public static class FillColorParam extends ColorParam
{
@Override
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box; }
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Box || shape instanceof Sphere; }
@Override
public String identify() { return "fill"; }
}
@@ -687,7 +772,7 @@ public class ShapeDispatcher
public static class FromParam extends Vec3Param
{
@Override
public boolean appliesTo(ExpiringShape shape) { return (shape instanceof Line) || (shape instanceof Box); }
public boolean appliesTo(ExpiringShape shape) { return shape instanceof Line || shape instanceof Box; }
@Override
public boolean roundsUpForBlocks() { return false; }
@Override
@@ -727,6 +812,35 @@ public class ShapeDispatcher
@Override
public String identify() { return "level"; }
}
public abstract static class EntityParam implements Param
{
@Override
public Tag toTag(Value value)
{
return IntTag.of(NumericValue.asNumber(value).getInt());
}
@Override
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
if (value instanceof EntityValue) return new NumericValue(((EntityValue) value).getEntity().getEntityId());
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getMinecraftServer(), value);
if (player == null)
throw new InternalExpressionException(identify()+" parameter needs to represent an entity or player");
return new NumericValue(player.getEntityId());
}
@Override
public boolean appliesTo(ExpiringShape shape) { return true; }
public static Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
}
public static class FollowParam extends EntityParam
{
@Override
public String identify() { return "follow"; }
}
@@ -14,6 +14,7 @@ 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.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
@@ -52,22 +53,26 @@ public class ShapesRenderer
RegistryKey<World> dimensionType = iWorld.method_27983();
if (shapes.get(dimensionType).isEmpty()) return;
long currentTime = client.world.getTime();
RenderSystem.disableTexture();
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(515);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
//RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
RenderSystem.shadeModel(7425);
//RenderSystem.shadeModel(7425);
RenderSystem.shadeModel(GL11.GL_FLAT);
RenderSystem.enableAlphaTest();
RenderSystem.defaultAlphaFunc();
Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
//RenderSystem.alphaFunc(GL11.GL_GREATER, 0.005F);
RenderSystem.disableCull();
RenderSystem.disableLighting();
RenderSystem.depthMask(false);
//RenderSystem.polygonOffset(-3f, -3f);
//RenderSystem.enablePolygonOffset();
//Entity entity = this.client.gameRenderer.getCamera().getFocusedEntity();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
double d = 0.0D - cameraY;
double e = 256.0D - cameraY;
RenderSystem.disableTexture();
//RenderSystem.disableBlend();
double f = (double)(entity.chunkX << 4) - cameraX;
double g = (double)(entity.chunkZ << 4) - cameraZ;
// render
synchronized (shapes)
{
@@ -75,22 +80,30 @@ public class ShapesRenderer
entry -> entry.getValue().isExpired(currentTime)
);
shapes.get(dimensionType).values().forEach(
s -> s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ)
s ->
{
if ( s.shouldRender(dimensionType)) s.render2pass(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ);
}
);
//lines
shapes.get(dimensionType).values().forEach(
s -> s.render2pass(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ)
s -> {
if ( s.shouldRender(dimensionType)) s.render(tessellator, bufferBuilder, (float) cameraX, (float) cameraY, (float) cameraZ);
}
);
}
RenderSystem.enableCull();
RenderSystem.depthMask(true);
RenderSystem.lineWidth(1.0F);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableTexture();
RenderSystem.shadeModel(7424);
}
public void addShape(CompoundTag tag)
{
//CarpetSettings.LOG.error("Received tag: "+tag.asString());
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
if (shape == null) return;
BiFunction<MinecraftClient, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >> shapeFactory;
@@ -130,6 +143,7 @@ public class ShapesRenderer
public abstract static class RenderedShape<T extends ShapeDispatcher.ExpiringShape>
{
protected T shape;
protected MinecraftClient client;
long expiryTick;
float renderEpsilon = 0;
public abstract void render(Tessellator tessellator, BufferBuilder builder, float cx, float cy, float cz );
@@ -139,6 +153,7 @@ public class ShapesRenderer
this.shape = shape;
expiryTick = client.world.getTime()+shape.getExpiry();
renderEpsilon = (2+((float)shape.key())/Integer.MAX_VALUE)/1000;
this.client = client;
}
public boolean isExpired(long currentTick)
@@ -149,6 +164,20 @@ public class ShapesRenderer
{
return shape.key();
};
public boolean shouldRender(DimensionType dim)
{
if (shape.followEntity <=0 ) return true;
if (client.world == null) return false;
if (client.world.dimension.getType() != dim) return false;
if (client.world.getEntityById(shape.followEntity) == null) return false;
return true;
}
protected Vec3d relativiseRender(float x, float y, float z)
{
if (shape.followEntity <= 0) return new Vec3d(x,y,z);
Entity e = client.world.getEntityById(shape.followEntity);
return shape.toAbsolute(e, x, y, z);
}
}
public static class RenderedBox extends RenderedShape<ShapeDispatcher.Box>
@@ -162,28 +191,31 @@ public class ShapesRenderer
@Override
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.a == 0.0) return;
Vec3d v1 = relativiseRender(shape.x1, shape.y1, shape.z1);
Vec3d v2 = relativiseRender(shape.x2, shape.y2, shape.z2);
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,
(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,
shape.r, shape.g, shape.b, shape.a, shape.r, shape.g, shape.b
);
tessellator.draw();
}
@Override
public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.fa == 0.0) return;
Vec3d v1 = relativiseRender(shape.x1, shape.y1, shape.z1);
Vec3d v2 = relativiseRender(shape.x2, shape.y2, shape.z2);
RenderSystem.lineWidth(1.0F);
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,
(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,
shape.fr, shape.fg, shape.fb, shape.fa
);
}
}
public static class RenderedLine extends RenderedShape<ShapeDispatcher.Line>
@@ -195,10 +227,12 @@ public class ShapesRenderer
@Override
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
Vec3d v1 = relativiseRender(shape.x1, shape.y1, shape.z1);
Vec3d v2 = relativiseRender(shape.x2, shape.y2, shape.z2);
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,
(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,
shape.r, shape.g, shape.b, shape.a
);
}
@@ -213,12 +247,26 @@ public class ShapesRenderer
@Override
public void render(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.a == 0.0) return;
Vec3d vc = relativiseRender(shape.cx, shape.cy, shape.cz);
RenderSystem.lineWidth(shape.lineWidth);
drawSphereWireframe(tessellator, bufferBuilder,
shape.cx-cx-renderEpsilon, shape.cy-cy-renderEpsilon, shape.cz-cz-renderEpsilon,
(float)vc.x-cx-renderEpsilon, (float)vc.y-cy-renderEpsilon, (float)vc.z-cz-renderEpsilon,
shape.radius, shape.subdivisions,
shape.r, shape.g, shape.b, shape.a);
}
@Override
public void render2pass(Tessellator tessellator, BufferBuilder bufferBuilder, float cx, float cy, float cz)
{
if (shape.fa == 0.0) return;
Vec3d vc = relativiseRender(shape.cx, shape.cy, shape.cz);
RenderSystem.lineWidth(1.0f);
drawSphereFaces(tessellator, bufferBuilder,
(float)vc.x-cx-renderEpsilon, (float)vc.y-cy-renderEpsilon, (float)vc.z-cz-renderEpsilon,
shape.radius, shape.subdivisions,
shape.fr, shape.fg, shape.fb, shape.fa);
}
}
// some raw shit
@@ -230,7 +278,8 @@ public class ShapesRenderer
tessellator.draw();
}
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) {
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();
@@ -256,24 +305,26 @@ public class ShapesRenderer
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
tessellator.draw();
}
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
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);
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();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).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();
builder.vertex(x2, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
@@ -281,9 +332,9 @@ public class ShapesRenderer
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
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, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z2).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y1, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x1, y2, z1).color(red1, grn1, blu1, alpha).next();
builder.vertex(x2, y2, z1).color(red1, grn1, blu1, alpha).next();
@@ -297,14 +348,16 @@ public class ShapesRenderer
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)
float step = (float)Math.PI / (subd/2);
int num_steps180 = (int)(Math.PI / step)+1;
int num_steps360 = (int)(2*Math.PI / step);
for (int i = 0; i <= num_steps360; i++)
{
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 theta = step * i ;
for (int j = 0; j <= num_steps180; j++)
{
float phi = step * j ;
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
float y = r * MathHelper.cos(phi);
@@ -312,14 +365,14 @@ public class ShapesRenderer
}
tessellator.draw();
}
for (float j = 0f; j <= 180.0f; j+=step)
for (int j = 0; j <= num_steps180; j++)
{
builder.begin(GL11.GL_LINE_LOOP, VertexFormats.POSITION_COLOR);
float phi = j * pihalf;
float phi = step * j ;
for (float i = 0f; i <= 360.0f; i+=step)
for (int i = 0; i <= num_steps360; i++)
{
float theta = i * pihalf;
float theta = step * i;
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
float y = r * MathHelper.cos(phi);
@@ -329,4 +382,33 @@ public class ShapesRenderer
}
}
public static void drawSphereFaces(Tessellator tessellator, BufferBuilder builder,
float cx, float cy, float cz,
float r, int subd,
float red, float grn, float blu, float alpha)
{
float step = (float)Math.PI / (subd/2);
int num_steps180 = (int)(Math.PI / step)+1;
int num_steps360 = (int)(2*Math.PI / step);
for (int i = 0; i <= num_steps360; i++)
{
float theta = i * step;
float thetaprime = theta+step;
builder.begin(GL11.GL_QUAD_STRIP, VertexFormats.POSITION_COLOR);
for (int j = 0; j <= num_steps180; j++)
{
float phi = j * step;
float x = r * MathHelper.sin(phi) * MathHelper.cos(theta);
float z = r * MathHelper.sin(phi) * MathHelper.sin(theta);
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(xp + cx, y + cy, zp + cz).color(red, grn, blu, alpha).next();
}
tessellator.draw();
}
}
}
@@ -6,7 +6,7 @@ global_renderers = m(
l('handler', '__structure_renderer'),
l('tasks', m()),
l('range', 3),
l('max_pieces', 4)
l('max_pieces', 6)
)),
l('chunks', m(
l('active', false),
@@ -98,20 +98,16 @@ __structure_renderer(player_name) ->
l(from, to) = structure_data;
total_size = _euclidean(from, to);
density = max(10, total_size/10);
//particle_box('dust 0 1 1 2', from, to+1, density);
draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0x00FFFFFF, 'width', 3);
draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0x00FFFFFF, 'width', 3, 'fill', 0x00FFFF22);
structure_pieces = slice(sort_key(structure_pieces, _euclidean_sq((_:2+_:3)/2,ppos)), 0, config:'max_pieces');
for (structure_pieces, l(piece, direction, from, to) = _;
//factor = 1- _i / config:'max_pieces' / 2;
//total_size = _euclidean(from, to);
//density = max(_i+1, total_size/10);
//particle_box(str('dust %.2f %.2f 1 1',factor, factor), from, to+1, density);
r = 255 - 128 * _i/config:'max_pieces';
r = 255 - floor(128 * _i/config:'max_pieces');
g = r;
b = 255;
a = 255;
color = 256*(b+256*(g+256*r)); // leaving out a
draw_shape('box', 15, 'from', from, 'to', to+1, 'color', color+a, 'fill', color+a/6);
draw_shape('box', 15, 'from', from, 'to', to+1, 'color', color+a);
draw_shape('box', 15, 'from', from, 'to', to+1, 'color', 0xffffff00, 'fill', 0xffffff22);
)
)
);
@@ -147,15 +143,6 @@ __chunk_renderer(player_name) ->
draw_shape('line', 15, 'from', top_01, 'to', top_00, 'color', color, 'width', 3);
draw_shape('line', 15, 'from', top_00, 'to', top_11, 'color', color, 'width', 3);
draw_shape('line', 15, 'from', top_01, 'to', top_10, 'color', color, 'width', 3);
//part = 'dust 0.2 0.8 0.2 2';
//density = 2+player_distance/2;
//particle_line(part, top_00, top_10, density);
//particle_line(part, top_10, top_11, density);
//particle_line(part, top_11, top_01, density);
//particle_line(part, top_01, top_00, density);
//particle_line(part, top_00, top_11, density);
//particle_line(part, top_01, top_10, density);
)
)
)