diff --git a/gradle.properties b/gradle.properties index 0286acb9..be8ea5ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=1.21.10 - loader_version=0.17.2 + minecraft_version=25w41a + loader_version=0.17.3 jsr305_version=3.0.2 - fabric_version=0.119.5+1.21.5 + fabric_version=0.134.0+1.21.9 # Mod Properties mod_version = 1.4.186 diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 82bba777..34fc202a 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -12,12 +12,16 @@ import carpet.utils.Messenger; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.SemanticVersion; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.ServerInterface; import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.permissions.LevelBasedPermissionSet; +import net.minecraft.server.permissions.PermissionCheck; +import net.minecraft.server.permissions.PermissionSet; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; @@ -56,7 +60,7 @@ public class CarpetSettings public static final Logger LOG = LoggerFactory.getLogger("carpet"); public static final ThreadLocal skipGenerationChecks = ThreadLocal.withInitial(() -> false); public static final ThreadLocal impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false); - public static int runPermissionLevel = 2; + public static PermissionSet runPermissionLevel = LevelBasedPermissionSet.GAMEMASTER; public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID; private static class LanguageValidator extends Validator { @Override public String validate(CommandSourceStack source, CarpetRule currentRule, String newValue, String string) { @@ -129,7 +133,7 @@ public class CarpetSettings private static class CarpetPermissionLevel extends Validator { @Override public String validate(CommandSourceStack source, CarpetRule currentRule, String newValue, String string) { - if (source == null || source.hasPermission(4)) + if (source == null || Commands.LEVEL_OWNERS.check(source.permissions())) return newValue; return null; } @@ -423,10 +427,32 @@ public class CarpetSettings @Rule( desc = "Required permission level for /perf command", options = {"2", "4"}, - category = CREATIVE + category = CREATIVE, + validate = PermissionValidator.class ) public static int perfPermissionLevel = 4; + public static class PermissionValidator extends Validator { + @Override + public Integer validate(CommandSourceStack source, CarpetRule currentRule, Integer newValue, String string) { + if (newValue == 2) { + perfPermissionCheck = Commands.LEVEL_GAMEMASTERS; + + } else if (newValue == 4) { + perfPermissionCheck = Commands.LEVEL_OWNERS; + + } + return newValue; + } + + @Override + public String description() { + return "You must have the permission level you are trying to set"; + } + } + public static PermissionCheck perfPermissionCheck = Commands.LEVEL_OWNERS; + + @Rule(desc = "Enables /log command to monitor events via chat and overlays", category = COMMAND) public static String commandLog = "true"; @@ -476,17 +502,21 @@ public class CarpetSettings private static class ModulePermissionLevel extends Validator { @Override public String validate(CommandSourceStack source, CarpetRule currentRule, String newValue, String string) { - int permissionLevel = switch (newValue) { - case "false" -> 0; - case "true", "ops" -> 2; - case "0", "1", "2", "3", "4" -> Integer.parseInt(newValue); + PermissionCheck permissionLevel = switch (newValue) { + case "0", "false" -> Commands.LEVEL_ALL; + case "1" -> Commands.LEVEL_MODERATORS; + case "2", "true", "ops" -> Commands.LEVEL_GAMEMASTERS; + case "3" -> Commands.LEVEL_ADMINS; + case "4" -> Commands.LEVEL_OWNERS; default -> throw new IllegalArgumentException(); // already checked by previous validator }; - if (source != null && !source.hasPermission(permissionLevel)) + if (source != null && !permissionLevel.check(source.permissions())) return null; - CarpetSettings.runPermissionLevel = permissionLevel; - if (source != null) + CarpetSettings.runPermissionLevel = LevelBasedPermissionSet.GAMEMASTER; + if (source != null) { CommandHelper.notifyPlayersCommandsChanged(source.getServer()); + CarpetSettings.runPermissionLevel =source.permissions(); + } return newValue; } @Override diff --git a/src/main/java/carpet/commands/InfoCommand.java b/src/main/java/carpet/commands/InfoCommand.java index 4e36964c..b1e5f77a 100644 --- a/src/main/java/carpet/commands/InfoCommand.java +++ b/src/main/java/carpet/commands/InfoCommand.java @@ -68,7 +68,7 @@ public class InfoCommand private static int infoBlock(CommandSourceStack source, BlockPos pos, String grep) { - if (!source.hasPermission(Commands.LEVEL_GAMEMASTERS)) { + if (!Commands.LEVEL_GAMEMASTERS.check(source.permissions())) { //check id pos is loaded if (!source.getLevel().hasChunkAt(pos)) { Messenger.m(source, "r Chunk is not loaded"); diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index a20934c2..f050915f 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -19,6 +19,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.SharedConstants; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.GameModeArgument; import net.minecraft.commands.arguments.coordinates.RotationArgument; @@ -98,13 +99,13 @@ public class PlayerCommand .then(literal("left").executes(manipulation(ap -> ap.setStrafing(1)))) .then(literal("right").executes(manipulation(ap -> ap.setStrafing(-1)))) ).then(literal("spawn").executes(PlayerCommand::spawn) - .then(literal("in").requires((player) -> player.hasPermission(2)) + .then(literal("in").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) .then(argument("gamemode", GameModeArgument.gameMode()) .executes(PlayerCommand::spawn))) .then(literal("at").then(argument("position", Vec3Argument.vec3()).executes(PlayerCommand::spawn) .then(literal("facing").then(argument("direction", RotationArgument.rotation()).executes(PlayerCommand::spawn) .then(literal("in").then(argument("dimension", DimensionArgument.dimension()).executes(PlayerCommand::spawn) - .then(literal("in").requires((player) -> player.hasPermission(2)) + .then(literal("in").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) .then(argument("gamemode", GameModeArgument.gameMode()) .executes(PlayerCommand::spawn) ))) @@ -230,7 +231,7 @@ public class PlayerCommand Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is banned on this server"); return true; } - if (manager.isUsingWhitelist() && manager.isWhiteListed(profile) && !context.getSource().hasPermission(2)) + if (manager.isUsingWhitelist() && manager.isWhiteListed(profile) && !Commands.LEVEL_GAMEMASTERS.check(context.getSource().permissions())) { Messenger.m(context.getSource(), "r Whitelisted players can only be spawned by operators"); return true; diff --git a/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java b/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java index 492da31a..0605d667 100644 --- a/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java +++ b/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java @@ -26,7 +26,7 @@ public abstract class Guardian_renewableSpongesMixin extends Monster { ElderGuardian elderGuardian = new ElderGuardian(EntityType.ELDER_GUARDIAN ,this.level()); elderGuardian.snapTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); - elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), EntitySpawnReason.CONVERSION, null); + elderGuardian.finalizeSpawn(serverWorld ,serverWorld.getCurrentDifficultyAt(elderGuardian.blockPosition()), EntitySpawnReason.CONVERSION, null); elderGuardian.setNoAi(this.isNoAi()); if (this.hasCustomName()) diff --git a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java index 66de25e9..b6fa65b8 100644 --- a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java +++ b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java @@ -51,7 +51,7 @@ public class LevelRenderer_scarpetRenderMixin final float deltaPartialTick = deltaTracker.getGameTimeDeltaPartialTick(false); FramePass pass = frameGraphBuilder.addPass("scarpet_shapes"); targets.main = pass.readsAndWrites(targets.main); - pass.executes(() -> CarpetClient.shapes.render(null, levelRenderState, deltaPartialTick)); + pass.executes(() -> CarpetClient.shapes.render(renderBuffers, levelRenderState, matrix4f, deltaPartialTick)); featureRenderDispatcher.renderAllFeatures(); renderBuffers.bufferSource().endLastBatch(); } diff --git a/src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java b/src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java index d11d32d4..a6b80dcb 100644 --- a/src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java +++ b/src/main/java/carpet/mixins/LivingEntity_cleanLogsMixin.java @@ -23,6 +23,6 @@ public abstract class LivingEntity_cleanLogsMixin extends Entity @Redirect(method = "die", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hasCustomName()Z")) private boolean shouldLogDeaths(LivingEntity livingEntity) { - return livingEntity.hasCustomName() && CarpetSettings.cleanLogs && livingEntity.level().getServer().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); + return livingEntity.hasCustomName() && livingEntity.level() instanceof ServerLevel serverLevel && CarpetSettings.cleanLogs && serverLevel.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); } } diff --git a/src/main/java/carpet/mixins/PerfCommand_permissionMixin.java b/src/main/java/carpet/mixins/PerfCommand_permissionMixin.java index d0c9f58f..6a637df9 100644 --- a/src/main/java/carpet/mixins/PerfCommand_permissionMixin.java +++ b/src/main/java/carpet/mixins/PerfCommand_permissionMixin.java @@ -2,9 +2,9 @@ package carpet.mixins; import carpet.CarpetSettings; import net.minecraft.commands.Commands; -import net.minecraft.commands.PermissionSource; import net.minecraft.server.commands.PerfCommand; -import net.minecraft.server.commands.PermissionCheck; +import net.minecraft.server.permissions.PermissionCheck; +import net.minecraft.server.permissions.PermissionProviderCheck; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -14,11 +14,11 @@ public class PerfCommand_permissionMixin { @Redirect(method = "register", at = @At( value = "INVOKE", - target = "Lnet/minecraft/commands/Commands;hasPermission(I)Lnet/minecraft/server/commands/PermissionCheck;" + target = "Lnet/minecraft/commands/Commands;hasPermission(Lnet/minecraft/server/permissions/PermissionCheck;)Lnet/minecraft/server/permissions/PermissionProviderCheck;" )) - private static PermissionCheck canRun(int i) + private static PermissionProviderCheck canRun(PermissionCheck permissionCheck) { - return Commands.hasPermission(CarpetSettings.perfPermissionLevel); + return Commands.hasPermission(CarpetSettings.perfPermissionCheck); } } diff --git a/src/main/java/carpet/mixins/Player_fakePlayersMixin.java b/src/main/java/carpet/mixins/Player_fakePlayersMixin.java index 5004a848..a585c0e2 100644 --- a/src/main/java/carpet/mixins/Player_fakePlayersMixin.java +++ b/src/main/java/carpet/mixins/Player_fakePlayersMixin.java @@ -14,7 +14,7 @@ public abstract class Player_fakePlayersMixin * To make sure player attacks are able to knockback fake players */ @Redirect( - method = "attack", + method = "causeExtraKnockback", at = @At( value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;hurtMarked:Z", diff --git a/src/main/java/carpet/script/CarpetScriptHost.java b/src/main/java/carpet/script/CarpetScriptHost.java index c9c0314d..073db7e8 100644 --- a/src/main/java/carpet/script/CarpetScriptHost.java +++ b/src/main/java/carpet/script/CarpetScriptHost.java @@ -31,6 +31,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import net.minecraft.core.BlockPos; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -202,6 +203,17 @@ public class CarpetScriptHost extends ScriptHost return command; } + private static boolean sourceHasPermissionLevel(CommandSourceStack source, int level) { + return switch (level) { + case 0 -> Commands.LEVEL_ALL.check(source.permissions()); + case 1 -> Commands.LEVEL_MODERATORS.check(source.permissions()); + case 2 -> Commands.LEVEL_GAMEMASTERS.check(source.permissions()); + case 3 -> Commands.LEVEL_ADMINS.check(source.permissions()); + case 4 -> Commands.LEVEL_OWNERS.check(source.permissions()); + default -> false; + }; + } + public Predicate getCommandConfigPermissions() throws CommandSyntaxException { Value confValue = appConfig.get(StringValue.of("command_permission")); @@ -216,13 +228,13 @@ public class CarpetScriptHost extends ScriptHost { throw CommandArgument.error("Numeric permission level for custom commands should be between 1 and 4"); } - return s -> s.hasPermission(level); + return s -> sourceHasPermissionLevel(s, level); } if (!(confValue instanceof final FunctionValue fun)) { String perm = confValue.getString().toLowerCase(Locale.ROOT); return switch (perm) { - case "ops" -> s -> s.hasPermission(2); + case "ops" -> s -> sourceHasPermissionLevel(s, 2); case "server" -> s -> !(s.getEntity() instanceof ServerPlayer); case "players" -> s -> s.getEntity() instanceof ServerPlayer; case "all" -> s -> true; diff --git a/src/main/java/carpet/script/ScriptCommand.java b/src/main/java/carpet/script/ScriptCommand.java index 8383849a..3894d757 100644 --- a/src/main/java/carpet/script/ScriptCommand.java +++ b/src/main/java/carpet/script/ScriptCommand.java @@ -15,6 +15,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraft.world.level.GameRules; import org.apache.commons.lang3.StringUtils; @@ -225,7 +226,7 @@ public class ScriptCommand BlockPosArgument.getSpawnablePos(cc, "to"), StringArgumentType.getString(cc, "arguments") )))))); - LiteralArgumentBuilder i = literal("scan").requires((player) -> player.hasPermission(2)). + LiteralArgumentBuilder i = literal("scan").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)). then(argument("origin", BlockPosArgument.blockPos()). then(argument("from", BlockPosArgument.blockPos()). then(argument("to", BlockPosArgument.blockPos()). @@ -238,7 +239,7 @@ public class ScriptCommand BlockPosArgument.getSpawnablePos(cc, "to"), StringArgumentType.getString(cc, "expr") )))))); - LiteralArgumentBuilder e = literal("fill").requires((player) -> player.hasPermission(2)). + LiteralArgumentBuilder e = literal("fill").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)). then(argument("origin", BlockPosArgument.blockPos()). then(argument("from", BlockPosArgument.blockPos()). then(argument("to", BlockPosArgument.blockPos()). @@ -265,7 +266,7 @@ public class ScriptCommand BlockPredicateArgument.getBlockPredicate(cc, "filter"), "solid" ))))))))); - LiteralArgumentBuilder t = literal("outline").requires((player) -> player.hasPermission(2)). + LiteralArgumentBuilder t = literal("outline").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)). then(argument("origin", BlockPosArgument.blockPos()). then(argument("from", BlockPosArgument.blockPos()). then(argument("to", BlockPosArgument.blockPos()). @@ -666,7 +667,7 @@ public class ScriptCommand BoundingBox area = BoundingBox.fromCorners(a, b); CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin); int int_1 = area.getXSpan() * area.getYSpan() * area.getZSpan(); // X Y Z - if (int_1 > source.getServer().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT)) + if (int_1 > source.getLevel().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT)) { Carpet.Messenger_message(source, "r too many blocks to evaluate: " + int_1); return 1; @@ -718,7 +719,7 @@ public class ScriptCommand BoundingBox area = BoundingBox.fromCorners(a, b); CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin); int int_1 = area.getXSpan() * area.getYSpan() * area.getZSpan(); - if (int_1 > source.getServer().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT)) + if (int_1 > source.getLevel().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT)) { Carpet.Messenger_message(source, "r too many blocks to evaluate: " + int_1); return 1; diff --git a/src/main/java/carpet/script/external/Vanilla.java b/src/main/java/carpet/script/external/Vanilla.java index 942157b6..4da04a67 100644 --- a/src/main/java/carpet/script/external/Vanilla.java +++ b/src/main/java/carpet/script/external/Vanilla.java @@ -29,6 +29,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayerGameMode; import net.minecraft.server.level.Ticket; +import net.minecraft.server.permissions.PermissionSet; import net.minecraft.tags.TagKey; import net.minecraft.world.Container; import net.minecraft.world.entity.Entity; @@ -140,7 +141,7 @@ public class Vanilla ServerNetworkHandler.sendCustomCommand(player, "scShapes", data); } - public static int MinecraftServer_getRunPermissionLevel(MinecraftServer server) + public static PermissionSet MinecraftServer_getRunPermissionLevel(MinecraftServer server) { return CarpetSettings.runPermissionLevel; } diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index fca460ff..9c69224e 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -300,7 +300,9 @@ public class ShapeDispatcher float lineWidth; protected float r, g, b, a; protected int color; + protected int argb; protected float fr, fg, fb, fa; + protected int fargb; protected int fillColor; protected int duration = 0; private long key; @@ -310,6 +312,7 @@ public class ShapeDispatcher protected boolean discreteX, discreteY, discreteZ; protected ResourceKey shapeDimension; protected boolean debug; + protected boolean seethrough; protected ExpiringShape() @@ -351,6 +354,11 @@ public class ShapeDispatcher init(options, regs); } + private int rgba2argb(int color) { + // return shift bits from alpha + return ((color & 0xFF) << 24) + (color >> 8 & 0xFFFFFF); + } + protected void init(Map options, RegistryAccess regs) { @@ -360,12 +368,14 @@ public class ShapeDispatcher lineWidth = NumericValue.asNumber(options.getOrDefault("line", optional.get("line"))).getFloat(); fillColor = NumericValue.asNumber(options.getOrDefault("fill", optional.get("fill"))).getInt(); + this.fargb = rgba2argb(fillColor); this.fr = (fillColor >> 24 & 0xFF) / 255.0F; this.fg = (fillColor >> 16 & 0xFF) / 255.0F; this.fb = (fillColor >> 8 & 0xFF) / 255.0F; this.fa = (fillColor & 0xFF) / 255.0F; color = NumericValue.asNumber(options.getOrDefault("color", optional.get("color"))).getInt(); + this.argb = rgba2argb(color); this.r = (color >> 24 & 0xFF) / 255.0F; this.g = (color >> 16 & 0xFF) / 255.0F; this.b = (color >> 8 & 0xFF) / 255.0F; @@ -377,6 +387,12 @@ public class ShapeDispatcher debug = options.get("debug").getBoolean(); } + seethrough = false; + if (options.containsKey("debug")) + { + seethrough = options.get("seethrough").getBoolean(); + } + key = 0; followEntity = -1; shapeDimension = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(options.get("dim").getString())); @@ -464,6 +480,7 @@ public class ShapeDispatcher hash ^= followEntity; hash *= 1099511628211L; hash ^= Boolean.hashCode(debug); + hash ^= Boolean.hashCode(seethrough); hash *= 1099511628211L; if (followEntity >= 0) { @@ -496,6 +513,7 @@ public class ShapeDispatcher "follow", new NumericValue(-1), "line", new NumericValue(2.0), "debug", Value.FALSE, + "seethrough", Value.FALSE, "fill", new NumericValue(0xffffff00), "snap", new StringValue("xyz") ); diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index c797a228..a322b869 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -4,14 +4,11 @@ import carpet.script.CarpetScriptServer; import carpet.script.external.Carpet; import carpet.script.utils.shapes.ShapeDirection; +import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.ByteBufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; -//import com.mojang.blaze3d.vertex.VertexBuffer; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat.Mode; import com.mojang.math.Axis; @@ -30,10 +27,12 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderBuffers; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; import net.minecraft.client.renderer.entity.state.EntityRenderState; +import net.minecraft.client.renderer.gizmos.DrawableGizmoPrimitives; import net.minecraft.client.renderer.item.ItemStackRenderState; import net.minecraft.client.renderer.state.LevelRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; @@ -88,7 +87,7 @@ public class ShapesRenderer case DOWN -> poseStack.mulPose(Axis.XP.rotationDegrees(-90)); case CAMERA -> poseStack.mulPose(camera.rotation()); case PLAYER -> { - Vec3 vector = objectPos.subtract(camera.getPosition()); + Vec3 vector = objectPos.subtract(camera.position()); double x = vector.x; double y = vector.y; double z = vector.z; @@ -112,7 +111,7 @@ public class ShapesRenderer labels = new HashMap<>(); } - public void render(Matrix4f modelViewMatrix, LevelRenderState cameraa, float partialTick) + public void render(RenderBuffers renderBuffers, LevelRenderState cameraa, Matrix4f matrix4f, float partialTick) { Runnable token = Carpet.startProfilerSection("Scarpet client"); // posestack is not needed anymore - left as TODO to cleanup later @@ -145,11 +144,14 @@ public class ShapesRenderer Tesselator tesselator = Tesselator.getInstance(); // render - double cameraX = camera.getPosition().x; - double cameraY = camera.getPosition().y; - double cameraZ = camera.getPosition().z; + double cameraX = camera.position().x; + double cameraY = camera.position().y; + double cameraZ = camera.position().z; boolean entityBoxes = client.debugEntries.isCurrentlyEnabled(DebugScreenEntries.ENTITY_HITBOXES); + final DrawableGizmoPrimitives normal = new DrawableGizmoPrimitives(); + final DrawableGizmoPrimitives onTop = new DrawableGizmoPrimitives(); + if (!shapes.isEmpty()) { shapes.get(dimensionType).long2ObjectEntrySet().removeIf( @@ -160,22 +162,21 @@ public class ShapesRenderer matrixStack.mul(matrices.last().pose()); // lines - RenderSystem.lineWidth(0.5F); + //RenderSystem.lineWidth(0.5F); shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) { - s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick, cameraa); + s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick, cameraa, s.shape.seethrough ? onTop : normal); } }); // faces - RenderSystem.lineWidth(0.1F); shapes.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) { - s.renderFaces(tesselator, cameraX, cameraY, cameraZ, partialTick); + s.renderFaces(tesselator, cameraX, cameraY, cameraZ, partialTick, s.shape.seethrough ? onTop : normal); } }); - RenderSystem.lineWidth(1.0F); + //RenderSystem.lineWidth(1.0F); matrixStack.popMatrix(); } @@ -187,10 +188,29 @@ public class ShapesRenderer labels.get(dimensionType).values().forEach(s -> { if ((!s.shape.debug || entityBoxes) && s.shouldRender(dimensionType)) { - s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick, cameraa); + s.renderLines(matrices, tesselator, cameraX, cameraY, cameraZ, partialTick, cameraa, s.shape.seethrough ? onTop : normal); } }); } + MultiBufferSource.BufferSource bufferSource = renderBuffers.bufferSource(); + bufferSource.endLastBatch(); + + + + normal.render(matrices, bufferSource, cameraa.cameraRenderState, matrix4f); + bufferSource.endLastBatch(); + + if (false) { + final RenderTarget mainRenderTarget = Minecraft.getInstance().getMainRenderTarget(); + RenderSystem.getDevice().createCommandEncoder().clearDepthTexture(mainRenderTarget.getDepthTexture(), 1.0); + onTop.render(matrices, bufferSource, cameraa.cameraRenderState, matrix4f); + bufferSource.endLastBatch(); + + RenderSystem.getDevice().createCommandEncoder().clearDepthTexture(Minecraft.getInstance().getMainRenderTarget().getDepthTexture(), 1.0); + + } + + ////RenderSystem.enableCull(); ////RenderSystem.depthMask(true); ////RenderSystem.enableBlend(); @@ -263,9 +283,9 @@ public class ShapesRenderer long expiryTick; double renderEpsilon; - public abstract void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState); + public abstract void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives); - public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick) + public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick, DrawableGizmoPrimitives primitives) { } @@ -337,7 +357,7 @@ public class ShapesRenderer @Override public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, - double cz, float partialTick, LevelRenderState levelRenderState) + double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0.0) { @@ -411,7 +431,7 @@ public class ShapesRenderer float green = (color >> 8 & 0xFF) / 255.0F; float blue = (color & 0xFF) / 255.0F; RenderType type; - if (blockState.getBlock() instanceof LeavesBlock && !Minecraft.useFancyGraphics()) { + if (blockState.getBlock() instanceof LeavesBlock && !Minecraft.getInstance().options.cutoutLeaves().get()) { type = RenderType.solid(); } else { type = ItemBlockRenderTypes.getRenderType(blockState); @@ -493,7 +513,7 @@ public class ShapesRenderer } @Override - public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState) + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0.0) { @@ -582,7 +602,7 @@ public class ShapesRenderer } @Override - public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState) + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0.0) { @@ -590,16 +610,16 @@ public class ShapesRenderer } Vec3 v1 = shape.relativiseRender(client.level, shape.from, partialTick); Vec3 v2 = shape.relativiseRender(client.level, shape.to, partialTick); - drawBoxWireGLLines(tesselator, - (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), + drawBoxWireGLLines(primitives, + (float) (v1.x - renderEpsilon), (float) (v1.y - renderEpsilon), (float) (v1.z - renderEpsilon), + (float) (v2.x + renderEpsilon), (float) (v2.y + renderEpsilon), (float) (v2.z + renderEpsilon), v1.x != v2.x, v1.y != v2.y, v1.z != v2.z, - shape.r, shape.g, shape.b, shape.a, shape.r, shape.g, shape.b + shape.argb, shape.lineWidth ); } @Override - public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick) + public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick, DrawableGizmoPrimitives primitives) { if (shape.fa == 0.0) { @@ -609,11 +629,11 @@ public class ShapesRenderer Vec3 v2 = shape.relativiseRender(client.level, shape.to, partialTick); // 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(tesselator, - (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), + drawBoxFaces(primitives, + (float) (v1.x - renderEpsilon), (float) (v1.y - renderEpsilon), (float) (v1.z - renderEpsilon), + (float) (v2.x + renderEpsilon), (float) (v2.y + renderEpsilon), (float) (v2.z + renderEpsilon), v1.x != v2.x, v1.y != v2.y, v1.z != v2.z, - shape.fr, shape.fg, shape.fb, shape.fa + shape.fargb ); } } @@ -626,38 +646,29 @@ public class ShapesRenderer } @Override - public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState) + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { Vec3 v1 = shape.relativiseRender(client.level, shape.from, partialTick); Vec3 v2 = shape.relativiseRender(client.level, shape.to, partialTick); - drawLine(tesselator, - (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 + primitives.addLine( + new Vec3((v1.x - renderEpsilon), (v1.y - renderEpsilon), (v1.z - renderEpsilon)), + new Vec3((v2.x + renderEpsilon), (v2.y + renderEpsilon), (v2.z + renderEpsilon)), + shape.argb, shape.lineWidth ); } } - private static void drawWithShader(MeshData mesh, RenderType type) { - type.draw(mesh); - //VertexBuffer buffre = mesh.drawState().format().getImmediateDrawVertexBuffer(); - //buffre.bind(); - //buffre.upload(mesh); - //buffre.drawWithShader(RenderSystem.getModelViewMatrix(), RenderSystem.getProjectionMatrix(), RenderType. RenderSystem.getShader()); - } - - public static class RenderedPolyface extends RenderedShape { // mode now can only be 4, 5, or 6 private static final VertexFormat.Mode[] faceIndices = new VertexFormat.Mode[]{ - Mode.LINES, Mode.LINE_STRIP, Mode.DEBUG_LINES, Mode.DEBUG_LINE_STRIP, Mode.TRIANGLES, Mode.TRIANGLE_STRIP, Mode.TRIANGLE_FAN, Mode.QUADS}; + Mode.LINES, Mode.LINES, Mode.DEBUG_LINES, Mode.DEBUG_LINE_STRIP, Mode.TRIANGLES, Mode.TRIANGLE_STRIP, Mode.TRIANGLE_FAN, Mode.QUADS}; private static final RenderType [] renderTypes = new RenderType[] { - RenderType.debugLineStrip(1), - RenderType.debugLineStrip(1), - RenderType.debugLineStrip(1), - RenderType.debugLineStrip(1), + RenderType.lines(), + RenderType.lines(), + RenderType.lines(), + RenderType.lines(), RenderType.debugTriangleFan(), // TODO wrong RenderType.debugTriangleFan(), // TODO wrong RenderType.debugTriangleFan(), @@ -670,7 +681,7 @@ public class ShapesRenderer } @Override - public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick) + public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick, DrawableGizmoPrimitives primitives) { if (shape.fa == 0) { @@ -686,7 +697,7 @@ public class ShapesRenderer ////RenderSystem.enableCull(); } - BufferBuilder builder = tesselator.begin(faceIndices[shape.mode], DefaultVertexFormat.POSITION_COLOR); + //BufferBuilder builder = tesselator.begin(faceIndices[shape.mode], DefaultVertexFormat.POSITION_COLOR); for (int i = 0; i < shape.vertexList.size(); i++) { Vec3 vec = shape.vertexList.get(i); @@ -694,9 +705,9 @@ public class ShapesRenderer { vec = shape.relativiseRender(client.level, vec, partialTick); } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.fr, shape.fg, shape.fb, shape.fa); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.fr, shape.fg, shape.fb, shape.fa); } - drawWithShader(builder.buildOrThrow(), renderTypes[shape.mode]); + //drawWithShader(builder.buildOrThrow(), renderTypes[shape.mode]); ////RenderSystem.disableCull(); ////RenderSystem.depthMask(false); @@ -707,7 +718,7 @@ public class ShapesRenderer @Override public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, - double cz, float partialTick, LevelRenderState levelRenderState) + double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0) { @@ -716,7 +727,7 @@ public class ShapesRenderer if (shape.mode == 6) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); + //BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); Vec3 vec0 = null; for (int i = 0; i < shape.vertexList.size(); i++) { @@ -729,13 +740,13 @@ public class ShapesRenderer { vec0 = vec; } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); } - builder.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + //builder.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); if (shape.inneredges) { - BufferBuilder builderr = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); + //BufferBuilder builderr = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); for (int i = 1; i < shape.vertexList.size() - 1; i++) { Vec3 vec = shape.vertexList.get(i); @@ -743,23 +754,23 @@ public class ShapesRenderer { vec = shape.relativiseRender(client.level, vec, partialTick); } - builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - builderr.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builderr.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builderr.addVertex((float) (vec0.x() - cx), (float) (vec0.y() - cy), (float) (vec0.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); } - drawWithShader(builderr.buildOrThrow(), RenderType.debugLineStrip(1)); + //drawWithShader(builderr.buildOrThrow(), RenderType.debugLineStrip(1)); } return; } if (shape.mode == 5) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); + //BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); Vec3 vec = shape.vertexList.get(1); if (shape.relative.get(1)) { vec = shape.relativiseRender(client.level, vec, partialTick); } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); int i; for (i = 0; i < shape.vertexList.size(); i += 2) { @@ -768,7 +779,7 @@ public class ShapesRenderer { vec = shape.relativiseRender(client.level, vec, partialTick); } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); } i = shape.vertexList.size() - 1; for (i -= 1 - i % 2; i > 0; i -= 2) @@ -778,7 +789,7 @@ public class ShapesRenderer { vec = shape.relativiseRender(client.level, vec, partialTick); } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); } if (shape.inneredges) { @@ -789,10 +800,10 @@ public class ShapesRenderer { vec = shape.relativiseRender(client.level, vec, partialTick); } - builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vec.x() - cx), (float) (vec.y() - cy), (float) (vec.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); } } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + //drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); return; } if (shape.mode == 4) @@ -800,7 +811,7 @@ public class ShapesRenderer // for (int i = 0; i < shape.vertexList.size(); i++) { - BufferBuilder builder = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); + //BufferBuilder builder = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); Vec3 vecA = shape.vertexList.get(i); if (shape.relative.get(i)) { @@ -818,16 +829,16 @@ public class ShapesRenderer { vecC = shape.relativiseRender(client.level, vecC, partialTick); } - builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - builder.addVertex((float) (vecB.x() - cx), (float) (vecB.y() - cy), (float) (vecB.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vecB.x() - cx), (float) (vecB.y() - cy), (float) (vecB.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); //builder.addVertex((float) (vecB.x() - cx), (float) (vecB.y() - cy), (float) (vecB.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - builder.addVertex((float) (vecC.x() - cx), (float) (vecC.y() - cy), (float) (vecC.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vecC.x() - cx), (float) (vecC.y() - cy), (float) (vecC.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); //builder.addVertex((float) (vecC.x() - cx), (float) (vecC.y() - cy), (float) (vecC.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); + //builder.addVertex((float) (vecA.x() - cx), (float) (vecA.y() - cy), (float) (vecA.z() - cz)).setColor(shape.r, shape.g, shape.b, shape.a); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + //drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } //drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } @@ -842,31 +853,31 @@ public class ShapesRenderer } @Override - public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState) + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0.0) { return; } Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick); - drawSphereWireframe(tesselator, - (float) (vc.x - cx), (float) (vc.y - cy), (float) (vc.z - cz), + drawSphereWireframe(primitives, + (float) (vc.x), (float) (vc.y), (float) (vc.z), (float) (shape.radius + renderEpsilon), shape.subdivisions, - shape.r, shape.g, shape.b, shape.a); + shape.argb, shape.lineWidth); } @Override - public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick) + public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick, DrawableGizmoPrimitives primitives) { if (shape.fa == 0.0) { return; } Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick); - drawSphereFaces(tesselator, - (float) (vc.x - cx), (float) (vc.y - cy), (float) (vc.z - cz), + drawSphereFaces(primitives, + (float) (vc.x ), (float) (vc.y ), (float) (vc.z ), (float) (shape.radius + renderEpsilon), shape.subdivisions, - shape.fr, shape.fg, shape.fb, shape.fa); + shape.fargb); } } @@ -878,7 +889,7 @@ public class ShapesRenderer } @Override - public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState) + public void renderLines(PoseStack matrices, Tesselator tesselator, double cx, double cy, double cz, float partialTick, LevelRenderState levelRenderState, DrawableGizmoPrimitives primitives) { if (shape.a == 0.0) { @@ -886,16 +897,16 @@ public class ShapesRenderer } Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick); double dir = Mth.sign(shape.height); - drawCylinderWireframe(tesselator, - (float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon), + drawCylinderWireframe(primitives, + (float) (vc.x - dir * renderEpsilon), (float) (vc.y - dir * renderEpsilon), (float) (vc.z - dir * renderEpsilon), (float) (shape.radius + renderEpsilon), (float) (shape.height + 2 * dir * renderEpsilon), shape.axis, shape.subdivisions, shape.height == 0, - shape.r, shape.g, shape.b, shape.a); + shape.argb, shape.lineWidth); } @Override - public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick) + public void renderFaces(Tesselator tesselator, double cx, double cy, double cz, float partialTick, DrawableGizmoPrimitives primitives) { if (shape.fa == 0.0) { @@ -903,188 +914,87 @@ public class ShapesRenderer } Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick); double dir = Mth.sign(shape.height); - drawCylinderFaces(tesselator, - (float) (vc.x - cx - dir * renderEpsilon), (float) (vc.y - cy - dir * renderEpsilon), (float) (vc.z - cz - dir * renderEpsilon), + drawCylinderFaces(primitives, + (float) (vc.x - dir * renderEpsilon), (float) (vc.y - dir * renderEpsilon), (float) (vc.z - dir * renderEpsilon), (float) (shape.radius + renderEpsilon), (float) (shape.height + 2 * dir * renderEpsilon), shape.axis, shape.subdivisions, shape.radius == 0, - shape.fr, shape.fg, shape.fb, shape.fa); + shape.fargb); } } // some raw shit - public static void drawLine(Tesselator tesselator, float x1, float y1, float z1, float x2, float y2, float z2, float red1, float grn1, float blu1, float alpha) - { - BufferBuilder builder = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); - builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); - } - public static void drawBoxWireGLLines( - Tesselator tesselator, + DrawableGizmoPrimitives primitives, float x1, float y1, float z1, float x2, float y2, float z2, boolean xthick, boolean ythick, boolean zthick, - float red1, float grn1, float blu1, float alpha, float red2, float grn2, float blu2) + int color, float width) { - BufferBuilder builder = tesselator.begin(Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); - /* old lines not using strip if (xthick) { - builder.addVertex(x1, y1, z1).setColor(red1, grn2, blu2, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn2, blu2, alpha); - - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); + primitives.addLine(new Vec3(x1, y1, z1), new Vec3(x2, y1, z1), color, width); + primitives.addLine(new Vec3(x2, y2, z1), new Vec3(x1, y2, z1), color, width); + primitives.addLine(new Vec3(x1, y1, z2), new Vec3(x2, y1, z2), color, width); + primitives.addLine(new Vec3(x1, y2, z2), new Vec3(x2, y2, z2), color, width); } if (ythick) { - builder.addVertex(x1, y1, z1).setColor(red2, grn1, blu2, alpha); - builder.addVertex(x1, y2, z1).setColor(red2, grn1, blu2, alpha); - - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); + primitives.addLine(new Vec3(x1, y1, z1), new Vec3(x1, y2, z1), color, width); + primitives.addLine(new Vec3(x2, y1, z1), new Vec3(x2, y2, z1), color, width); + primitives.addLine(new Vec3(x1, y2, z2), new Vec3(x1, y1, z2), color, width); + primitives.addLine(new Vec3(x2, y1, z2), new Vec3(x2, y2, z2), color, width); } if (zthick) { - builder.addVertex(x1, y1, z1).setColor(red2, grn2, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red2, grn2, blu1, alpha); - - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); + primitives.addLine(new Vec3(x1, y1, z1), new Vec3(x1, y1, z2), color, width); + primitives.addLine(new Vec3(x1, y2, z1), new Vec3(x1, y2, z2), color, width); + primitives.addLine(new Vec3(x2, y1, z2), new Vec3(x2, y1, z1), color, width); + primitives.addLine(new Vec3(x2, y2, z1), new Vec3(x2, y2, z2), color, width); } - */ - - if (xthick) - - { - builder.addVertex(x1, y1, z1).setColor(red1, grn2, blu2, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn2, blu2, alpha); - - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - } - if (ythick) - { - builder.addVertex(x1, y1, z1).setColor(red2, grn1, blu2, alpha); - builder.addVertex(x1, y2, z1).setColor(red2, grn1, blu2, alpha); - - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - } - if (zthick) - { - builder.addVertex(x1, y1, z1).setColor(red2, grn2, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red2, grn2, blu1, alpha); - - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } public static void drawBoxFaces( - Tesselator tesselator, + DrawableGizmoPrimitives primitives, float x1, float y1, float z1, float x2, float y2, float z2, boolean xthick, boolean ythick, boolean zthick, - float red1, float grn1, float blu1, float alpha) + int argb) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - if (xthick && ythick) { - builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); + primitives.addQuad(new Vec3(x1, y1, z1), new Vec3(x2, y1, z1), new Vec3(x2, y2, z1), new Vec3(x1, y2, z1), argb); if (zthick) { - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); + primitives.addQuad(new Vec3(x1, y1, z2), new Vec3(x1, y2, z2), new Vec3(x2, y2, z2), new Vec3(x2, y1, z2), argb); } } - if (zthick && ythick) { - builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); + primitives.addQuad(new Vec3(x1, y1, z1), new Vec3(x1, y2, z1), new Vec3(x1, y2, z2), new Vec3(x1, y1, z2), argb); if (xthick) { - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); + primitives.addQuad(new Vec3(x2, y1, z1), new Vec3(x2, y1, z2), new Vec3(x2, y2, z2), new Vec3(x2, y2, z1), argb); } } // now at least drawing one if (zthick && xthick) { - builder.addVertex(x1, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y1, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y1, z2).setColor(red1, grn1, blu1, alpha); - - + primitives.addQuad(new Vec3(x1, y1, z1), new Vec3(x2, y1, z1), new Vec3(x2, y1, z2), new Vec3(x1, y1, z2), argb); if (ythick) { - builder.addVertex(x1, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z1).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x2, y2, z2).setColor(red1, grn1, blu1, alpha); - builder.addVertex(x1, y2, z2).setColor(red1, grn1, blu1, alpha); + primitives.addQuad(new Vec3(x1, y2, z1), new Vec3(x1, y2, z2), new Vec3(x2, y2, z2), new Vec3(x2, y2, z1), argb); } } - drawWithShader(builder.buildOrThrow(), RenderType.debugQuads()); } - public static void drawCylinderWireframe(Tesselator tesselator, + public static void drawCylinderWireframe(DrawableGizmoPrimitives primitives, float cx, float cy, float cz, float r, float h, Direction.Axis axis, int subd, boolean isFlat, - float red, float grn, float blu, float alpha) + int argb, float width) { float step = (float) Math.PI / (subd / 2); int num_steps180 = (int) (Math.PI / step) + 1; @@ -1102,34 +1012,35 @@ public class ShapesRenderer for (int dh = 0; dh < hsteps; dh++) { float hh = dh * hstep; - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip + Vec3 from = null; for (int i = 0; i <= num_steps360 + 1; i++) { float theta = step * i; float x = r * Mth.cos(theta); float y = hh; float z = r * Mth.sin(theta); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + Vec3 to = new Vec3(x + cx, y + cy, z + cz); + if (from != null) { + primitives.addLine(from, to, argb, width); + } + from = to; } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } if (!isFlat) { for (int i = 0; i <= num_steps180; i++) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip float theta = step * i; float x = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builder.addVertex(cx - x, cy + 0, cz + z).setColor(red, grn, blu, alpha); - builder.addVertex(cx + x, cy + 0, cz - z).setColor(red, grn, blu, alpha); - builder.addVertex(cx + x, cy + h, cz - z).setColor(red, grn, blu, alpha); - builder.addVertex(cx - x, cy + h, cz + z).setColor(red, grn, blu, alpha); - builder.addVertex(cx - x, cy + 0, cz + z).setColor(red, grn, blu, alpha); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + primitives.addLine(new Vec3(cx- x, cy+ 0,cz + z), new Vec3(cx + x, cy + 0, cz - z), argb, width); + primitives.addLine(new Vec3(cx + x, cy + 0, cz - z), new Vec3(cx + x, cy + h, cz - z), argb, width); + primitives.addLine(new Vec3(cx + x, cy + h, cz - z), new Vec3(cx - x, cy + h, cz + z), argb, width); + primitives.addLine(new Vec3(cx - x, cy + h, cz + z), new Vec3(cx - x, cy + 0, cz + z), argb, width); + } } /* else @@ -1152,33 +1063,35 @@ public class ShapesRenderer for (int dh = 0; dh < hsteps; dh++) { float hh = dh * hstep; - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip + Vec3 from = null; for (int i = 0; i <= num_steps360; i++) { float theta = step * i; float z = r * Mth.cos(theta); float x = hh; float y = r * Mth.sin(theta); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + Vec3 to = new Vec3(x + cx, y + cy, z + cz); + if (from != null) { + primitives.addLine(from, to, argb, width); + } + from = to; } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } if (!isFlat) { for (int i = 0; i <= num_steps180; i++) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip float theta = step * i; float y = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builder.addVertex(cx + 0, cy - y, cz + z).setColor(red, grn, blu, alpha); - builder.addVertex(cx + 0, cy + y, cz - z).setColor(red, grn, blu, alpha); - builder.addVertex(cx + h, cy + y, cz - z).setColor(red, grn, blu, alpha); - builder.addVertex(cx + h, cy - y, cz + z).setColor(red, grn, blu, alpha); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + primitives.addLine(new Vec3(cx + 0, cy - y, cz + z), new Vec3(cx + 0, cy + y, cz - z), argb, width); + primitives.addLine(new Vec3(cx + 0, cy + y, cz - z), new Vec3(cx + h, cy + y, cz - z), argb, width); + primitives.addLine(new Vec3(cx + h, cy + y, cz - z), new Vec3(cx + h, cy - y, cz + z), argb, width); + primitives.addLine(new Vec3(cx + h, cy - y, cz + z), new Vec3(cx + 0, cy - y, cz + z), argb, width); + } } /*else @@ -1200,32 +1113,33 @@ public class ShapesRenderer for (int dh = 0; dh < hsteps; dh++) { float hh = dh * hstep; - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip + Vec3 from = null; for (int i = 0; i <= num_steps360; i++) { float theta = step * i; float y = r * Mth.cos(theta); float z = hh; float x = r * Mth.sin(theta); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + Vec3 to = new Vec3(x + cx, y + cy, z + cz); + if (from != null) { + primitives.addLine(from, to, argb, width); + } + from = to; } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } if (!isFlat) { for (int i = 0; i <= num_steps180; i++) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip float theta = step * i; float x = r * Mth.cos(theta); float y = r * Mth.sin(theta); - builder.addVertex(cx + x, cy - y, cz + 0).setColor(red, grn, blu, alpha); - builder.addVertex(cx - x, cy + y, cz + 0).setColor(red, grn, blu, alpha); - builder.addVertex(cx - x, cy + y, cz + h).setColor(red, grn, blu, alpha); - builder.addVertex(cx + x, cy - y, cz + h).setColor(red, grn, blu, alpha); - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); + primitives.addLine(new Vec3(cx + x, cy - y, cz + 0), new Vec3(cx - x, cy + y, cz + 0), argb, width); + primitives.addLine(new Vec3(cx - x, cy + y, cz + 0), new Vec3(cx - x, cy + y, cz + h), argb, width); + primitives.addLine(new Vec3(cx - x, cy + y, cz + h), new Vec3(cx + x, cy - y, cz + h), argb, width); + primitives.addLine(new Vec3(cx + x, cy - y, cz + h), new Vec3(cx + x, cy - y, cz + 0), argb, width); } } /*else @@ -1244,10 +1158,10 @@ public class ShapesRenderer } } - public static void drawCylinderFaces(Tesselator tesselator, + public static void drawCylinderFaces(DrawableGizmoPrimitives primitives, float cx, float cy, float cz, float r, float h, Direction.Axis axis, int subd, boolean isFlat, - float red, float grn, float blu, float alpha) + int argb) { float step = (float) Math.PI / (subd / 2); //final int num_steps180 = (int) (Math.PI / step) + 1; @@ -1255,31 +1169,31 @@ public class ShapesRenderer if (axis == Direction.Axis.Y) { - - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builder.addVertex(cx, cy, cz).setColor(red, grn, blu, alpha); - for (int i = 0; i <= num_steps360; i++) { - float theta = step * i; - float x = r * Mth.cos(theta); - float z = r * Mth.sin(theta); - builder.addVertex(x + cx, cy, z + cz).setColor(red, grn, blu, alpha); + final Vec3[] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx, cy, cz); + for (int i = 0; i <= num_steps360; i++) { + float theta = step * i; + float x = r * Mth.cos(theta); + float z = r * Mth.sin(theta); + points[i + 1] = new Vec3(x + cx, cy, z + cz); + } + primitives.addTriangleFan(points, argb); } - drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan()); + if (!isFlat) { - BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builderr.addVertex(cx, cy + h, cz).setColor(red, grn, blu, alpha); + final Vec3[] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx, cy + h, cz); for (int i = 0; i <= num_steps360; i++) { float theta = step * i; float x = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builderr.addVertex(x + cx, cy + h, z + cz).setColor(red, grn, blu, alpha); + points[i + 1] = new Vec3(x + cx, cy + h, z + cz); } - drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan()); + primitives.addTriangleFan(points, argb); - BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads float xp = r * 1; float zp = r * 0; for (int i = 1; i <= num_steps360; i++) @@ -1287,43 +1201,42 @@ public class ShapesRenderer float theta = step * i; float x = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builderrr.addVertex(cx + xp, cy + 0, cz + zp).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + xp, cy + h, cz + zp).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + x, cy + h, cz + z).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + x, cy + 0, cz + z).setColor(red, grn, blu, alpha); + primitives.addQuad(new Vec3(cx + xp, cy + 0, cz + zp), new Vec3(cx + xp, cy + h, cz + zp), + new Vec3(cx + x, cy + h, cz + z), new Vec3(cx - x, cy + h, cz + z), argb); xp = x; zp = z; } - drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads()); } } else if (axis == Direction.Axis.X) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builder.addVertex(cx, cy, cz).setColor(red, grn, blu, alpha); - for (int i = 0; i <= num_steps360; i++) { - float theta = step * i; - float y = r * Mth.cos(theta); - float z = r * Mth.sin(theta); - builder.addVertex(cx, cy + y, z + cz).setColor(red, grn, blu, alpha); + Vec3[] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx, cy, cz); + for (int i = 0; i <= num_steps360; i++) { + float theta = step * i; + float y = r * Mth.cos(theta); + float z = r * Mth.sin(theta); + points[i + 1] = new Vec3(cx, cy + y, cz + z); + + } + primitives.addTriangleFan(points, argb); } - drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan()); + if (!isFlat) { - BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builderr.addVertex(cx + h, cy, cz).setColor(red, grn, blu, alpha); + Vec3[] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx + h, cy, cz); for (int i = 0; i <= num_steps360; i++) { float theta = step * i; float y = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builderr.addVertex(cx + h, cy + y, cz + z).setColor(red, grn, blu, alpha); + points[i + 1] = new Vec3(cx, cy + y, cz + z); } - drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan()); + primitives.addTriangleFan(points, argb); - BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads float yp = r * 1; float zp = r * 0; for (int i = 1; i <= num_steps360; i++) @@ -1331,42 +1244,40 @@ public class ShapesRenderer float theta = step * i; float y = r * Mth.cos(theta); float z = r * Mth.sin(theta); - builderrr.addVertex(cx + 0, cy + yp, cz + zp).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + h, cy + yp, cz + zp).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + h, cy + y, cz + z).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + 0, cy + y, cz + z).setColor(red, grn, blu, alpha); + + primitives.addQuad(new Vec3(cx + 0, cy + yp, cz + zp), new Vec3(cx + h, cy + yp, cz + zp), + new Vec3(cx + h, cy + y, cz + z), new Vec3(cx + 0, cy + y, cz + z), argb); yp = y; zp = z; } - drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads()); } } else if (axis == Direction.Axis.Z) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builder.addVertex(cx, cy, cz).setColor(red, grn, blu, alpha); - for (int i = 0; i <= num_steps360; i++) { - float theta = step * i; - float x = r * Mth.cos(theta); - float y = r * Mth.sin(theta); - builder.addVertex(x + cx, cy + y, cz).setColor(red, grn, blu, alpha); + Vec3[] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx, cy, cz); + for (int i = 0; i <= num_steps360; i++) { + float theta = step * i; + float x = r * Mth.cos(theta); + float y = r * Mth.sin(theta); + points[i + 1] = new Vec3(x + cx, cy + y, cz); + } + primitives.addTriangleFan(points, argb); } - drawWithShader(builder.buildOrThrow(), RenderType.debugTriangleFan()); if (!isFlat) { - BufferBuilder builderr = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); - builderr.addVertex(cx, cy, cz + h).setColor(red, grn, blu, alpha); + Vec3 [] points = new Vec3[num_steps360 + 2]; + points[0] = new Vec3(cx, cy, cz + h); for (int i = 0; i <= num_steps360; i++) { float theta = step * i; float x = r * Mth.cos(theta); float y = r * Mth.sin(theta); - builderr.addVertex(x + cx, cy + y, cz + h).setColor(red, grn, blu, alpha); + points[i + 1] = new Vec3(x + cx, cy + y, cz + h); } - drawWithShader(builderr.buildOrThrow(), RenderType.debugTriangleFan()); + primitives.addTriangleFan(points, argb); - BufferBuilder builderrr = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads float xp = r; float yp = 0; for (int i = 1; i <= num_steps360; i++) @@ -1374,29 +1285,26 @@ public class ShapesRenderer float theta = step * i; float x = r * Mth.cos(theta); float y = r * Mth.sin(theta); - builderrr.addVertex(cx + xp, cy + yp, cz + 0).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + xp, cy + yp, cz + h).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + x, cy + y, cz + h).setColor(red, grn, blu, alpha); - builderrr.addVertex(cx + x, cy + y, cz + 0).setColor(red, grn, blu, alpha); + primitives.addQuad(new Vec3(cx + xp, cy + yp, cz + 0), new Vec3(cx + xp, cy + yp, cz + h), + new Vec3(cx + x, cy + y, cz + h), new Vec3(cx + x, cy + y, cz + 0), argb); xp = x; yp = y; } - drawWithShader(builderrr.buildOrThrow(), RenderType.debugQuads()); } } } - public static void drawSphereWireframe(Tesselator tesselator, + public static void drawSphereWireframe(DrawableGizmoPrimitives primitives, float cx, float cy, float cz, float r, int subd, - float red, float grn, float blu, float alpha) + int argb, float width) { float step = (float) Math.PI / (subd / 2); int num_steps180 = (int) (Math.PI / step) + 1; int num_steps360 = (int) (2 * Math.PI / step) + 1; for (int i = 0; i <= num_steps360; i++) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); + Vec3 from = null; float theta = step * i; for (int j = 0; j <= num_steps180; j++) { @@ -1404,13 +1312,16 @@ public class ShapesRenderer float x = r * Mth.sin(phi) * Mth.cos(theta); float z = r * Mth.sin(phi) * Mth.sin(theta); float y = r * Mth.cos(phi); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + Vec3 to = new Vec3(x + cx, y + cy, z + cz); + if (from != null) { + primitives.addLine(from, to, argb, width); + } + from = to; } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } for (int j = 0; j <= num_steps180; j++) { - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR); // line loop to line strip + Vec3 from = null; float phi = step * j; for (int i = 0; i <= num_steps360; i++) @@ -1419,17 +1330,20 @@ public class ShapesRenderer float x = r * Mth.sin(phi) * Mth.cos(theta); float z = r * Mth.sin(phi) * Mth.sin(theta); float y = r * Mth.cos(phi); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + Vec3 to = new Vec3(x + cx, y + cy, z + cz); + if (from != null) { + primitives.addLine(from, to, argb, width); + } + from = to; } - drawWithShader(builder.buildOrThrow(), RenderType.debugLineStrip(1)); } } - public static void drawSphereFaces(Tesselator tesselator, + public static void drawSphereFaces(DrawableGizmoPrimitives primitives, float cx, float cy, float cz, float r, int subd, - float red, float grn, float blu, float alpha) + int argb) { float step = (float) Math.PI / (subd / 2); @@ -1439,7 +1353,6 @@ public class ShapesRenderer { float theta = i * step; float thetaprime = theta + step; - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // quad strip to quads float xb = 0; float zb = 0; float xbp = 0; @@ -1453,17 +1366,16 @@ public class ShapesRenderer float y = r * Mth.cos(phi); float xp = r * Mth.sin(phi) * Mth.cos(thetaprime); float zp = r * Mth.sin(phi) * Mth.sin(thetaprime); - builder.addVertex(xb + cx, yp + cy, zb + cz).setColor(red, grn, blu, alpha); - builder.addVertex(xbp + cx, yp + cy, zbp + cz).setColor(red, grn, blu, alpha); - builder.addVertex(xp + cx, y + cy, zp + cz).setColor(red, grn, blu, alpha); - builder.addVertex(x + cx, y + cy, z + cz).setColor(red, grn, blu, alpha); + + primitives.addQuad(new Vec3(xb + cx, yp + cy, zb + cz), new Vec3(xbp + cx, yp + cy, zbp + cz), + new Vec3(xp + cx, y + cy, zp + cz), new Vec3(x + cx, y + cy, z + cz), argb); + xb = x; zb = z; xbp = xp; zbp = zp; yp = y; } - drawWithShader(builder.buildOrThrow(), RenderType.debugQuads()); } } } diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 720910c9..d100b6ec 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -10,6 +10,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.PermissionSet; import net.minecraft.util.Mth; import net.minecraft.util.TaskChainer; import net.minecraft.world.entity.Entity; @@ -28,7 +29,7 @@ public class SnoopyCommandSource extends CommandSourceStack private final CommandSource output; private final Vec3 position; private final ServerLevel world; - private final int level; + private final PermissionSet level; private final String simpleName; private final Component name; private final MinecraftServer server; @@ -47,8 +48,9 @@ public class SnoopyCommandSource extends CommandSourceStack public SnoopyCommandSource(CommandSourceStack original, Component[] error, List chatOutput, OptionalLong[] returnValue) { super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()), - original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false, - (b, i) -> returnValue[0] = OptionalLong.of(i), EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer())); + original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity() + //,false ,(b, i) -> returnValue[0] = OptionalLong.of(i), EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()) + ); this.output = CommandSource.NULL; this.position = original.getPosition(); this.world = original.getLevel(); @@ -89,13 +91,14 @@ public class SnoopyCommandSource extends CommandSourceStack this.taskChainer = TaskChainer.immediate(player.level().getServer()); } - private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, + private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, PermissionSet level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, Component[] error, List chatOutput ) { super(output, pos, rot, world, level, - simpleName, name, server, entity, false, - consumer, entityAnchor, context, chainer); + simpleName, name, server, entity + // , false, consumer, entityAnchor, context, chainer + ); this.output = output; this.position = pos; this.rotation = rot; @@ -149,13 +152,13 @@ public class SnoopyCommandSource extends CommandSourceStack //public ServerCommandSource withSilent() { return this; } @Override - public CommandSourceStack withPermission(int level) + public CommandSourceStack withPermission(PermissionSet level) { return this; } @Override - public CommandSourceStack withMaximumPermission(int level) + public CommandSourceStack withMaximumPermission(PermissionSet level) { return this; } diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 9bedb9ab..f63526eb 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -13,6 +13,7 @@ import carpet.script.utils.InputValidator; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.commands.arguments.selector.EntitySelectorParser; import net.minecraft.core.BlockPos; @@ -35,6 +36,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.LevelBasedPermissionSet; import net.minecraft.tags.EntityTypeTags; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; @@ -120,11 +122,11 @@ public class EntityValue extends Value EntitySelector entitySelector = selectorCache.get(selector); if (entitySelector != null) { - return entitySelector.findEntities(source.withMaximumPermission(4)); + return entitySelector.findEntities(source.withMaximumPermission(LevelBasedPermissionSet.OWNER)); } entitySelector = new EntitySelectorParser(new StringReader(selector), true).parse(); selectorCache.put(selector, entitySelector); - return entitySelector.findEntities(source.withMaximumPermission(4)); + return entitySelector.findEntities(source.withMaximumPermission(LevelBasedPermissionSet.OWNER)); } catch (CommandSyntaxException e) { @@ -599,13 +601,21 @@ public class EntityValue extends Value put("permission_level", (e, a) -> { if (e instanceof ServerPlayer spe) { - for (int i = 4; i >= 0; i--) + if (Commands.LEVEL_OWNERS.check(spe.permissions())) { - if (spe.hasPermissions(i)) - { - return new NumericValue(i); - } - + return new NumericValue(4); + } + if (Commands.LEVEL_ADMINS.check(spe.permissions())) + { + return new NumericValue(3); + } + if (Commands.LEVEL_GAMEMASTERS.check(spe.permissions())) + { + return new NumericValue(2); + } + if (Commands.LEVEL_MODERATORS.check(spe.permissions())) + { + return new NumericValue(1); } return new NumericValue(0); } diff --git a/src/main/java/carpet/script/value/ScreenValue.java b/src/main/java/carpet/script/value/ScreenValue.java index eb1625fe..dd398770 100644 --- a/src/main/java/carpet/script/value/ScreenValue.java +++ b/src/main/java/carpet/script/value/ScreenValue.java @@ -24,6 +24,7 @@ import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.PermissionSet; import net.minecraft.world.Container; import net.minecraft.world.MenuProvider; import net.minecraft.world.SimpleContainer; @@ -200,7 +201,7 @@ public class ScreenValue extends Value this.screenHandler = null; return false; } - int runPermissionLevel = Vanilla.MinecraftServer_getRunPermissionLevel(player.level().getServer()); + PermissionSet runPermissionLevel = Vanilla.MinecraftServer_getRunPermissionLevel(player.level().getServer()); CommandSourceStack source = player.createCommandSourceStack().withPermission(runPermissionLevel); CarpetScriptHost executingHost = appHost.retrieveForExecution(source, player); try diff --git a/src/main/java/carpet/utils/CommandHelper.java b/src/main/java/carpet/utils/CommandHelper.java index 9b97f652..0f4064e0 100644 --- a/src/main/java/carpet/utils/CommandHelper.java +++ b/src/main/java/carpet/utils/CommandHelper.java @@ -2,6 +2,7 @@ package carpet.utils; import carpet.CarpetSettings; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import net.minecraft.server.MinecraftServer; import net.minecraft.server.TickTask; import net.minecraft.server.level.ServerPlayer; @@ -48,8 +49,12 @@ public final class CommandHelper { { case "true" -> true; case "false" -> false; - case "ops" -> source.hasPermission(2); // typical for other cheaty commands - case "0", "1", "2", "3", "4" -> source.hasPermission(Integer.parseInt(commandLevelString)); + case "ops" -> Commands.LEVEL_GAMEMASTERS.check(source.permissions()); // typical for other cheaty commands + case "0" -> Commands.LEVEL_ALL.check(source.permissions()); + case "1" -> Commands.LEVEL_MODERATORS.check(source.permissions()); + case "2" -> Commands.LEVEL_GAMEMASTERS.check(source.permissions()); + case "3" -> Commands.LEVEL_ADMINS.check(source.permissions()); + case "4" -> Commands.LEVEL_OWNERS.check(source.permissions()); default -> false; }; } diff --git a/src/main/resources/carpet.accesswidener b/src/main/resources/carpet.accesswidener index df9b0bd1..b5c8fd8a 100644 --- a/src/main/resources/carpet.accesswidener +++ b/src/main/resources/carpet.accesswidener @@ -8,8 +8,10 @@ accessible class net/minecraft/world/level/border/WorldBorder$StaticBorderExtent accessible class net/minecraft/server/MinecraftServer$ReloadableResources accessible class net/minecraft/world/level/biome/Biome$ClimateSettings accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$VibrationUser +#accessible class net/minecraft/commands/CommandSourceStack #TODO fields and methods should be fetched via interfaces unless there is a good reason not to +#accessible method net/minecraft/commands/CommandSourceStack (Lnet/minecraft/commands/CommandSource;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec2;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/permissions/PermissionSet;Ljava/lang/String;Lnet/minecraft/network/chat/Component;Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/world/entity/Entity;BLnet/minecraft/commands/CommandResultCallback;Lnet/minecraft/commands/arguments/EntityAnchorArgument$Anchor;Lnet/minecraft/commands/CommandSigningContext;Lnet/minecraft/util/TaskChainer;)V accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List; accessible method net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator calculateTargetStrength (Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)I