cleanup and tilt-lean fixes for new shapes

This commit is contained in:
gnembon committed 2022-09-12 02:08:43 +02:00
1 parent 179f5a6006
commit 36aff8f9d3
3 files changed
+189 -191

No files matched your search

+39 -29
View File
@@ -91,7 +91,7 @@ Optional shared shape attributes:
value is `'xyz'`, meaning the shape will be drawn relatively to the entity in all three directions. Using `xz` for
instance makes so that the shape follows the entity, but stays at the same, absolute Y coordinate. Preceeding an axis
with `d`, like `dxdydz` would make so that entity position is treated discretely (rounded down).
* `toggleable` - if True, can toggle visibility by using F3+B. just like entities' hitbox.
* `debug` - if True, it will only be visible when F3+B entity bounding boxes is enabled.
Available shapes:
* `'line'` - draws a straight line between two points.
@@ -99,28 +99,6 @@ Available shapes:
* `from` - triple coordinates, entity, or block value indicating one end of the line
* `to` - other end of the line, same format as `from`
* `'label'` - draws a text in the world. Default `line` attribute controls main font color.
`fill` controls the color of the background.
* Required attributes:
* `pos` - position
* `text` - string or formatted text to display
* Optional attributes
* `value` - string or formatted text to display instead of the main `text`. `value` unlike `text`
is not used to determine uniqueness of the drawn text so can be used to
display smoothly dynamic elements where value of an element is constantly
changing and updates to it are being sent from the server.
* `size` - float. Default font size is 10.
* `facing` - text direction, where its facing. Possible options are: `player` (default, text
always rotates to face the player), `north`, `south`, `east`, `west`, `up`, `down`
* `doublesided` - if `true` it will make the text visible from the back as well. Default is `false` (1.16+)
* `align` - text alignment with regards to `pos`. Default is `center` (displayed text is
centered with respect to `pos`), `left` (`pos` indicates beginning of text), and `right` (`pos`
indicates the end of text).
* `tilt`, `lean`, `turn` - additional rotations of the text on the canvas along all three axis
* `indent`, `height`, `raise` - offsets for text rendering on X (`indent`), Y (`height`), and Z axis (`raise`)
with regards to the plane of the text. One unit of these corresponds to 1 line spacing, which
can be used to display multiple lines of text bound to the same `pos`
* `'box'` - draws a box with corners in specified points
* Required attributes:
* `from` - triple coordinates, entity, or block value indicating one corner of the box
@@ -152,20 +130,52 @@ Available shapes:
* `inner` - if `true` it will make the inner edges be drawn as well.
* `doublesided` - if `true` it will make the shapes visible from the back as well. Default is `true`.
* `'block'` \ `'item'`:
* `'label'` - draws a text in the world. Default `line` attribute controls main font color.
`fill` controls the color of the background.
* Required attributes:
* `pos` - position
* `text` - string or formatted text to display
* Optional attributes
* `value` - string or formatted text to display instead of the main `text`. `value` unlike `text`
is not used to determine uniqueness of the drawn text so can be used to
display smoothly dynamic elements where value of an element is constantly
changing and updates to it are being sent from the server.
* `size` - float. Default font size is 10.
* `facing` - text direction, where its facing. Possible options are: `player` (default, text
always rotates to face the player), `north`, `south`, `east`, `west`, `up`, `down`
* `doublesided` - if `true` it will make the text visible from the back as well. Default is `false` (1.16+)
* `align` - text alignment with regards to `pos`. Default is `center` (displayed text is
centered with respect to `pos`), `left` (`pos` indicates beginning of text), and `right` (`pos`
indicates the end of text).
* `tilt`, `lean`, `turn` - additional rotations of the text on the canvas along all three axis
* `indent`, `height`, `raise` - offsets for text rendering on X (`indent`), Y (`height`), and Z axis (`raise`)
with regards to the plane of the text. One unit of these corresponds to 1 line spacing, which
can be used to display multiple lines of text bound to the same `pos`
* `'block'`: draws a block at the specified position:
* Required attributes:
* `pos` - position of the object.
* `item` - the object to show. could have NBT. is a item tuple or a string-id (exclusive to `'item'`)
* `block` - the object to show. could have NBT. is a block value or a string-id (exclusive to `'block'`)
* `block` - the object to show. It is a block value or a name of a block with optional NBT data.
* Optional attributes:
* `facing` - object's direction, where its facing. Possible options are: `player` (it
rotates to face the player), `north`(default), `south`, `east`, `west`, `up`, `down`
* `tilt`, `lean`, `turn` - additional rotations along all three axis. It uses the block center as the origin.
* `scale` - scale of it in 3 axis-direction. should be a number or a list of 3 numbers (x,y,z).
* `skylight`, `blocklight` - light level. omit it to use local light level. should between 0~15.
* `'item'`: draws an item at the specified position:
* Required attributes:
* `pos` - position of the object.
* `item` - the object to show. It is an item tuple or a string identified item that may have NBT data.
* Optional attributes:
* `facing` - object's direction, where its facing. Possible options are: `player` (it
always rotates to face the player), `north`(default), `south`, `east`, `west`, `up`, `down`
* `tilt`, `lean`, `turn` - additional rotations along all three axis. for `block`, it use its block center as the origin.
* `scale` - scale of it in 3 axis-direction. should be a number or a list of 3 numbers (x,y,z).
* `skylight`, `blocklight` - light level. omit it to use local light level. should between 0~15.
* `variant` - one of "none","third_person_left_hand","third_person_right_hand","first_person_left_hand",
"first_person_right_hand","head","gui","ground","fixed". In addition to the literal meaning, it can also be used to use special models of tridents and telescopes. (exclusive to `'item'`)
* `variant` - one of `'none'`, `'third_person_left_hand'`, `'third_person_right_hand'`, `'first_person_left_hand'`,
`'first_person_right_hand'`, `'head'`, `'gui'`, `'ground'`, `'fixed'`. In addition to the literal meaning,
it can also be used to use special models of tridents and telescopes.
### `create_marker(text, pos, rotation?, block?, interactive?)`
@@ -37,7 +37,6 @@ import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
@@ -289,7 +288,7 @@ public class ShapeDispatcher
protected boolean snapX, snapY, snapZ;
protected boolean discreteX, discreteY, discreteZ;
protected ResourceKey<Level> shapeDimension;
protected boolean needf3b;
protected boolean debug;
protected ExpiringShape() { }
@@ -341,9 +340,9 @@ public class ShapeDispatcher
this.b = (float)(color >> 8 & 0xFF) / 255.0F;
this.a = (float)(color & 0xFF) / 255.0F;
needf3b = false;
if (options.containsKey("toggleable")) {
needf3b = options.get("toggleable").getBoolean();
debug = false;
if (options.containsKey("debug")) {
debug = options.get("debug").getBoolean();
}
key = 0;
@@ -410,7 +409,7 @@ public class ShapeDispatcher
hash ^= shapeDimension.hashCode(); hash *= 1099511628211L;
hash ^= color; hash *= 1099511628211L;
hash ^= followEntity; hash *= 1099511628211L;
hash ^= Boolean.hashCode(needf3b); hash *= 1099511628211L;
hash ^= Boolean.hashCode(debug); hash *= 1099511628211L;
if (followEntity >= 0)
{
hash ^= snapTo.hashCode(); hash *= 1099511628211L;
@@ -433,7 +432,7 @@ public class ShapeDispatcher
"color", new NumericValue(-1),
"follow", new NumericValue(-1),
"line", new NumericValue(2.0),
"toggleable", Value.FALSE,
"debug", Value.FALSE,
"fill", new NumericValue(0xffffff00),
"snap", new StringValue("xyz")
);
@@ -585,16 +584,13 @@ public class ShapeDispatcher
private boolean isitem;
@Override
protected Set<String> requiredParams() {
return Sets.union(Sets.union(super.requiredParams(), required), Set.of(isitem ? "item" : "block"));
}
protected Set<String> requiredParams() { return Sets.union(Sets.union(super.requiredParams(), required), Set.of(isitem ? "item" : "block"));}
@Override
protected Set<String> optionalParams() {
return Sets.union(Sets.union(super.optionalParams(), optional.keySet()),isitem ? Set.of("variant") : Set.of());
}
protected Set<String> optionalParams() { return Sets.union(Sets.union(super.optionalParams(), optional.keySet()),isitem ? Set.of("variant") : Set.of()); }
public DisplayedSprite(boolean i) {
public DisplayedSprite(boolean i)
{
isitem = i;
}
@@ -605,80 +601,81 @@ public class ShapeDispatcher
float tilt;
float lean;
float turn;
float scale_z = 1.0f;
int light_fromblock;
int light_fromsky;
float scale_y = 1.0f;
float scale_x = 1.0f;
int blockLight;
int skyLight;
float scaleX = 1.0f;
float scaleY = 1.0f;
float scaleZ = 1.0f;
CompoundTag blockEntity;
BlockState blockState;
ItemStack item = null;
TransformType item_transform_type;
String itemTransformType;
@Override
protected void init(Map<String, Value> options) {
protected void init(Map<String, Value> options)
{
super.init(options);
pos = vecFromValue(options.get("pos"));
if(!this.isitem){
blockState = ((BlockValue) options.get("block")).getBlockState();
blockEntity = ((BlockValue) options.get("block")).getData();
}else{
if (!this.isitem)
{
final BlockValue block = (BlockValue)options.get("block");
blockState = block.getBlockState();
blockEntity = block.getData();
}
else
{
this.item = ItemStack.of(((NBTSerializableValue) options.get("item")).getCompoundTag());
}
light_fromblock = NumericValue
.asNumber(options.getOrDefault("blocklight", optional.get("blocklight"))).getInt();
if (light_fromblock > 15)
light_fromblock = 15;
light_fromsky = NumericValue.asNumber(options.getOrDefault("skylight", optional.get("skylight")))
.getInt();
if (light_fromsky > 15)
light_fromsky = 15;
blockLight = NumericValue.asNumber(options.getOrDefault("blocklight", optional.get("blocklight"))).getInt();
if (blockLight > 15) blockLight = 15;
skyLight = NumericValue.asNumber(options.getOrDefault("skylight", optional.get("skylight"))).getInt();
if (skyLight > 15) skyLight = 15;
item_transform_type = TransformType.NONE;
if(options.containsKey("variant")){
item_transform_type = TransformType.valueOf(options.get("variant").getString());
itemTransformType = "none";
if (options.containsKey("variant"))
{
itemTransformType = options.get("variant").getString().toLowerCase(Locale.ROOT);
}
String dir = options.getOrDefault("facing", optional.get("facing")).getString();
facing = null;
switch (dir)
{
case "north": facing = Direction.NORTH; break;
case "south": facing = Direction.SOUTH; break;
case "east": facing = Direction.EAST; break;
case "west": facing = Direction.WEST; break;
case "up": facing = Direction.UP; break;
case "down": facing = Direction.DOWN; break;
}
facing = switch (dir) {
case "north" -> Direction.NORTH;
case "south" -> Direction.SOUTH;
case "east" -> Direction.EAST;
case "west" -> Direction.WEST;
case "up" -> Direction.UP;
case "down" -> Direction.DOWN;
default -> null;
};
tilt = NumericValue.asNumber(options.getOrDefault("tilt", optional.get("tilt"))).getFloat();
lean = NumericValue.asNumber(options.getOrDefault("lean", optional.get("lean"))).getFloat();
turn = NumericValue.asNumber(options.getOrDefault("turn", optional.get("turn"))).getFloat();
List<Value> scale = ((ListValue) options.getOrDefault("scale", optional.get("scale"))).unpack();
scale_y = NumericValue.asNumber(scale.get(1)).getFloat();
scale_x = NumericValue.asNumber(scale.get(0)).getFloat();
scale_z = NumericValue.asNumber(scale.get(2)).getFloat();
scaleY = NumericValue.asNumber(scale.get(1)).getFloat();
scaleX = NumericValue.asNumber(scale.get(0)).getFloat();
scaleZ = NumericValue.asNumber(scale.get(2)).getFloat();
}
@Override
public Consumer<ServerPlayer> alternative() {
ParticleOptions locparticledata;
if(this.isitem){
if(Block.byItem(this.item.getItem()).defaultBlockState().isAir())
return p->{};
locparticledata = getParticleData("block_marker "+Registry.BLOCK.getKey(Block.byItem(this.item.getItem())));
}else{
locparticledata = getParticleData("block_marker "+Registry.BLOCK.getKey(this.blockState.getBlock()));
ParticleOptions particle;
if(this.isitem)
{
if (Block.byItem(this.item.getItem()).defaultBlockState().isAir()) return p->{};
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(Block.byItem(this.item.getItem())));
}
else
{
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(this.blockState.getBlock()));
}
return p -> {
Vec3 v = relativiseRender(p.level, this.pos, 0);
p.getLevel().sendParticles(p,locparticledata , true,
v.x, v.y, v.z, 1,
0.0, 0.0, 0.0, 0.0);
p.getLevel().sendParticles(p, particle , true, v.x, v.y, v.z, 1,0.0, 0.0, 0.0, 0.0);
};
}
@@ -686,21 +683,21 @@ public class ShapeDispatcher
public long calcKey() {
long hash = super.calcKey();
hash ^= 7; hash *= 1099511628211L;
hash ^= Boolean.hashCode(isitem); hash *= 1099511628211L;
hash ^= vec3dhash(pos); hash *= 1099511628211L;
if (facing!= null) hash ^= facing.hashCode(); hash *= 1099511628211L;
hash ^= Float.hashCode(tilt); hash *= 1099511628211L;
hash ^= Float.hashCode(lean); hash *= 1099511628211L;
hash ^= Float.hashCode(turn); hash *= 1099511628211L;
hash ^= Float.hashCode(scale_y); hash *= 1099511628211L;
hash ^= Float.hashCode(scale_z); hash *= 1099511628211L;
hash ^= Float.hashCode(scale_x); hash *= 1099511628211L;
hash ^= Float.hashCode(light_fromsky); hash *= 1099511628211L;
hash ^= Float.hashCode(light_fromblock); hash *= 1099511628211L;
hash ^= Float.hashCode(scaleY); hash *= 1099511628211L;
hash ^= Float.hashCode(scaleZ); hash *= 1099511628211L;
hash ^= Float.hashCode(scaleX); hash *= 1099511628211L;
hash ^= Float.hashCode(skyLight); hash *= 1099511628211L;
hash ^= Float.hashCode(blockLight); hash *= 1099511628211L;
if (blockEntity!= null) hash ^= blockEntity.toString().hashCode(); hash *= 1099511628211L;
if (blockState!= null) hash ^= blockState.hashCode(); hash *= 1099511628211L;
hash ^= ValueConversions.of(item).getString().hashCode(); hash *= 1099511628211L;
//hash ^= Boolean.hashCode(needf3b); hash *= 1099511628211L;
hash ^= item_transform_type.hashCode(); hash *= 1099511628211L;
hash ^= itemTransformType.hashCode(); hash *= 1099511628211L;
return hash;
}
@@ -800,7 +797,6 @@ public class ShapeDispatcher
hash ^= Boolean.hashCode(doublesided); hash *= 1099511628211L;
hash ^= Integer.hashCode(vertex_list.size()); hash *= 1099511628211L;
hash ^= Boolean.hashCode(inneredges); hash *= 1099511628211L;
//hash ^= Boolean.hashCode(needf3b); hash *= 1099511628211L;
return hash;
}
ArrayList<Vec3> alter_point=null;
@@ -859,15 +855,11 @@ public class ShapeDispatcher
if(relative.get(1)){
vecB=relativiseRender(p.level, vecB, 0);
}
//ArrayList<Vec3> last = new ArrayList<Vec3>();
//last.add(vecA);last.add(vecB);
for(int i=2;i<vertex_list.size();i++){
Vec3 vec=vertex_list.get(i);
if(relative.get(i)){
vec=relativiseRender(p.level, vec, 0);
}
//alter_draw_triangles(last.get(0),last.get(1),vec);
//last.remove(0);last.add(vec);
alter_draw_triangles(vecA,vecB,vec);
vecA=vecB;vecB=vec;
}
@@ -927,8 +919,6 @@ public class ShapeDispatcher
{
super.init(options);
doublesided=options.getOrDefault("doublesided",optional.get("doublesided")).getBoolean();
if (options.get("points") instanceof AbstractListValue abl){
@@ -1271,7 +1261,7 @@ public class ShapeDispatcher
put("turn", new FloatParam("turn"));
put("facing", new StringChoiceParam("axis", "player", "north", "south", "east", "west", "up", "down"));
put("doublesided", new BoolParam("doublesided"));
put("toggleable", new BoolParam("toggleable"));
put("debug", new BoolParam("debug"));
}};
protected String id;
@@ -1,9 +1,9 @@
package carpet.script.utils;
import carpet.CarpetSettings;
import carpet.mixins.ShulkerBoxAccessMixin;
import carpet.utils.CarpetProfiler;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@@ -12,21 +12,17 @@ import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat.Mode;
import com.mojang.datafixers.util.Either;
import com.mojang.math.Vector3f;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.model.ShulkerModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.GameRenderer;
@@ -35,48 +31,28 @@ import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.model.ItemTransform;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.ShulkerBoxRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkSource;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.entity.LevelEntityGetter;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.ticks.LevelTickAccess;
public class ShapesRenderer
{
@@ -85,16 +61,15 @@ public class ShapesRenderer
private Minecraft client;
private Map<String, BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape >>> renderedShapes
= new HashMap<String, BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape>>>()
{{
= new HashMap<>() {{
put("line", RenderedLine::new);
put("box", RenderedBox::new);
put("sphere", RenderedSphere::new);
put("cylinder", RenderedCylinder::new);
put("label", RenderedText::new);
put("polygon", RenderedPolyface::new);
put("block",(c,s)->new RenderedSprite(c,s).set_isitem(false));
put("item",(c,s)->new RenderedSprite(c,s).set_isitem(true));
put("block", (c, s) -> new RenderedSprite(c, s, false));
put("item", (c, s) -> new RenderedSprite(c, s, true));
}};
public ShapesRenderer(Minecraft minecraftClient)
@@ -136,7 +111,7 @@ public class ShapesRenderer
double cameraX = camera.getPosition().x;
double cameraY = camera.getPosition().y;
double cameraZ = camera.getPosition().z;
boolean hasf3b = client.getEntityRenderDispatcher().shouldRenderHitBoxes();
boolean entityBoxes = client.getEntityRenderDispatcher().shouldRenderHitBoxes();
if (shapes.size() != 0) { synchronized (shapes) {
shapes.get(dimensionType).long2ObjectEntrySet().removeIf(
@@ -150,12 +125,12 @@ public class ShapesRenderer
// lines
RenderSystem.lineWidth(0.5F);
shapes.get(dimensionType).values().forEach( s -> {
if ( (!s.shape.needf3b ||hasf3b ) && s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
if ( (!s.shape.debug ||entityBoxes ) && 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.shape.needf3b ||hasf3b ) && s.shouldRender(dimensionType)) s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
if ( (!s.shape.debug ||entityBoxes ) && s.shouldRender(dimensionType)) s.renderFaces(tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
});
RenderSystem.lineWidth(1.0F);
matrixStack.popPose();
@@ -168,7 +143,7 @@ public class ShapesRenderer
entry -> entry.getValue().isExpired(currentTime)
);
labels.get(dimensionType).values().forEach(s -> {
if ( (!s.shape.needf3b || hasf3b) && s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
if ( (!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) s.renderLines(matrices, tessellator, bufferBuilder, cameraX, cameraY, cameraZ, partialTick);
});
}}
RenderSystem.enableCull();
@@ -290,24 +265,25 @@ public class ShapesRenderer
public static class RenderedSprite extends RenderedShape<ShapeDispatcher.DisplayedSprite> {
private boolean isitem;
public RenderedSprite set_isitem(boolean isitem) {
this.isitem = isitem;
return this;
}
private final boolean isitem;
private ItemTransforms.TransformType transformType = ItemTransforms.TransformType.NONE;
private BlockPos blockPos;
private BlockState blockState;
private BlockEntity BlockEntity = null;
protected RenderedSprite(Minecraft client, ShapeDispatcher.ExpiringShape shape) {
protected RenderedSprite(Minecraft client, ShapeDispatcher.ExpiringShape shape, boolean isitem) {
super(client, (ShapeDispatcher.DisplayedSprite) shape);
this.isitem = isitem;
if (isitem) {
this.transformType = ItemTransforms.TransformType.valueOf(((ShapeDispatcher.DisplayedSprite) shape).itemTransformType.toUpperCase(Locale.ROOT));
}
}
@Override
public void renderLines(PoseStack matrices, Tesselator tessellator, BufferBuilder builder, double cx, double cy,
double cz, float partialTick) {
double cz, float partialTick)
{
if (shape.a == 0.0)
return;
@@ -316,13 +292,19 @@ public class ShapesRenderer
matrices.pushPose();
if (!isitem)// blocks should use its center as the origin
{
matrices.translate(0.5, 0.5, 0.5);
}
matrices.translate(v1.x - cx, v1.y - cy, v1.z - cz);
if (shape.facing == null) {
if (shape.facing == null)
{
matrices.mulPose(camera1.rotation());
matrices.mulPose(Vector3f.YP.rotationDegrees(180));
} else {
switch (shape.facing) {
}
else
{
switch (shape.facing)
{
case NORTH:
break;
case SOUTH:
@@ -343,30 +325,28 @@ public class ShapesRenderer
}
}
if (shape.tilt != 0.0f)
matrices.mulPose(Vector3f.ZP.rotationDegrees(shape.tilt));
if (shape.lean != 0.0f)
matrices.mulPose(Vector3f.XP.rotationDegrees(shape.lean));
if (shape.turn != 0.0f)
matrices.mulPose(Vector3f.YP.rotationDegrees(shape.turn));
matrices.scale(shape.scale_x, shape.scale_y, shape.scale_z);
if (shape.tilt != 0.0f) matrices.mulPose(Vector3f.ZP.rotationDegrees(-shape.tilt));
if (shape.lean != 0.0f) matrices.mulPose(Vector3f.XP.rotationDegrees(-shape.lean));
if (shape.turn != 0.0f) matrices.mulPose(Vector3f.YP.rotationDegrees( shape.turn));
matrices.scale(shape.scaleX, shape.scaleY, shape.scaleZ);
if (!isitem)// blocks should use its center as the origin
{
matrices.translate(-0.5, -0.5, -0.5);
}
RenderSystem.depthMask(true);
RenderSystem.enableCull();
RenderSystem.enableDepthTest();
blockPos = new BlockPos(v1);
int light;
int light = 0;
if (client.level != null) {
light = LightTexture.pack(
shape.light_fromblock < 0 ? client.level.getBrightness(LightLayer.BLOCK, blockPos)
: shape.light_fromblock,
shape.light_fromsky < 0 ? client.level.getBrightness(LightLayer.SKY, blockPos)
: shape.light_fromsky);
shape.blockLight < 0 ? client.level.getBrightness(LightLayer.BLOCK, blockPos) : shape.blockLight,
shape.skyLight < 0 ? client.level.getBrightness(LightLayer.SKY, blockPos) : shape.skyLight
);
}
blockState = shape.blockState;
@@ -386,30 +366,44 @@ public class ShapesRenderer
}
// draw the block`s entity part
if (BlockEntity == null) {
if (blockState.getBlock() instanceof EntityBlock eb) {
if (BlockEntity == null)
{
if (blockState.getBlock() instanceof EntityBlock eb)
{
BlockEntity = eb.newBlockEntity(blockPos, blockState);
if (BlockEntity != null) {
if (BlockEntity != null)
{
BlockEntity.setLevel(client.level);
if (shape.blockEntity != null)
BlockEntity.load(shape.blockEntity);
if (shape.blockEntity != null) BlockEntity.load(shape.blockEntity);
}
}
}
if (BlockEntity instanceof ShulkerBoxBlockEntity sbBlockEntity){
if (BlockEntity instanceof ShulkerBoxBlockEntity sbBlockEntity)
{
sbrender(sbBlockEntity, partialTick,
matrices, immediate, light, OverlayTexture.NO_OVERLAY);
}else
if (BlockEntity != null && client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity) != null) {
client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity).render(BlockEntity, partialTick,
matrices, immediate, light, OverlayTexture.NO_OVERLAY);
}
} else {
// draw item
else
{
if (BlockEntity != null)
{
final BlockEntityRenderer<BlockEntity> blockEntityRenderer = client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity);
if (blockEntityRenderer != null) {
blockEntityRenderer.render(BlockEntity, partialTick,
matrices, immediate, light, OverlayTexture.NO_OVERLAY);
}
}
}
}
else
{
if (shape.item != null)
client.getItemRenderer().renderStatic(shape.item, shape.item_transform_type, light,
{
client.getItemRenderer().renderStatic(shape.item, transformType, light,
OverlayTexture.NO_OVERLAY, matrices, immediate, (int) shape.key());
}
}
matrices.popPose();
immediate.endBatch();
RenderSystem.disableCull();
@@ -424,34 +418,40 @@ public class ShapesRenderer
}
// copy and modifiy a bit from net.minecraft.client.renderer.blockentity.ShulkerBoxRenderer.render
public void sbrender(ShulkerBoxBlockEntity shulkerBoxBlockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j) {
public void sbrender(ShulkerBoxBlockEntity shulkerBoxBlockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j)
{
Direction direction = Direction.UP;
if (shulkerBoxBlockEntity.hasLevel()) {
if (shulkerBoxBlockEntity.hasLevel())
{
BlockState blockState = shulkerBoxBlockEntity.getBlockState();
if (blockState.getBlock() instanceof ShulkerBoxBlock) {
if (blockState.getBlock() instanceof ShulkerBoxBlock)
{
direction = blockState.getValue(ShulkerBoxBlock.FACING);
}
}
DyeColor dyeColor = shulkerBoxBlockEntity.getColor();
Material material;
if (dyeColor == null) {
if (dyeColor == null)
{
material = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
} else {
material = (Material)Sheets.SHULKER_TEXTURE_LOCATION.get(dyeColor.getId());
}
else
{
material = Sheets.SHULKER_TEXTURE_LOCATION.get(dyeColor.getId());
}
poseStack.pushPose();
poseStack.translate(0.5, 0.5, 0.5);
float g = 0.9995F;
poseStack.scale(0.9995F, 0.9995F, 0.9995F);
poseStack.mulPose(direction.getRotation());
poseStack.scale(1.0F, -1.0F, -1.0F);
poseStack.translate(0.0, -1.0, 0.0);
ModelPart modelPart = ((carpet.mixins.ShulkerBoxAccessMixin)(Object)(client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity))).getModel().getLid();
ShulkerModel<?> model = ((ShulkerBoxAccessMixin) client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity)).getModel();
ModelPart modelPart = model.getLid();
modelPart.setPos(0.0F, 24.0F - shulkerBoxBlockEntity.getProgress(f) * 0.5F * 16.0F, 0.0F);
modelPart.yRot = 270.0F * shulkerBoxBlockEntity.getProgress(f) * (float) (Math.PI / 180.0);
VertexConsumer vertexConsumer = material.buffer(multiBufferSource, RenderType::entityCutoutNoCull);
((carpet.mixins.ShulkerBoxAccessMixin)(Object)(client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity))).getModel().renderToBuffer(poseStack, vertexConsumer, i, j, 1.0F, 1.0F, 1.0F, 1.0F);
model.renderToBuffer(poseStack, vertexConsumer, i, j, 1.0F, 1.0F, 1.0F, 1.0F);
poseStack.popPose();
}
}
@@ -677,8 +677,6 @@ public class ShapesRenderer
return;
}
if (shape.mode==Mode.TRIANGLE_STRIP){
//02468
//1357*
builder.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR);
Vec3 vec=shape.vertex_list.get(1);
if(shape.relative.get(1)){