From dcb45c93b832629b74cb11e8eaf633cb8467c1e4 Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:42:59 +0100 Subject: [PATCH] 24w05a --- gradle.properties | 2 +- .../java/carpet/helpers/ParticleDisplay.java | 5 ++--- .../Guardian_renewableSpongesMixin.java | 2 +- .../LevelRenderer_scarpetRenderMixin.java | 4 ++-- .../carpet/mixins/NaturalSpawnerMixin.java | 6 +++--- ...istonMovingBlockEntity_movableBEMixin.java | 20 ++++++++++++------- src/main/java/carpet/script/api/Entities.java | 2 +- .../java/carpet/script/api/WorldAccess.java | 2 +- .../script/command/CommandArgument.java | 2 +- .../carpet/script/utils/ParticleParser.java | 7 +++---- .../carpet/script/utils/ShapeDispatcher.java | 2 +- .../carpet/script/utils/ShapesRenderer.java | 17 ++++++++++------ .../java/carpet/script/value/BlockValue.java | 2 +- .../script/value/NBTSerializableValue.java | 2 +- .../carpet/script/value/ValueConversions.java | 4 ++-- src/main/java/carpet/utils/BlockInfo.java | 2 +- src/main/java/carpet/utils/SpawnReporter.java | 2 +- 17 files changed, 46 insertions(+), 37 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3f9ec6a8..9e1bde86 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=24w04a + minecraft_version=24w05a loader_version=0.15.6 jsr305_version=3.0.2 fabric_version=0.91.1+1.20.3 diff --git a/src/main/java/carpet/helpers/ParticleDisplay.java b/src/main/java/carpet/helpers/ParticleDisplay.java index 35b693a8..0184375c 100644 --- a/src/main/java/carpet/helpers/ParticleDisplay.java +++ b/src/main/java/carpet/helpers/ParticleDisplay.java @@ -12,9 +12,8 @@ public class ParticleDisplay { public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, String main, String accent, int count, double spread) { - HolderLookup> lookup = player.level().holderLookup(Registries.PARTICLE_TYPE); - ParticleOptions accentParticle = ParticleParser.getEffect(accent, lookup); - ParticleOptions mainParticle = ParticleParser.getEffect(main, lookup); + ParticleOptions accentParticle = ParticleParser.getEffect(accent, player.server.registryAccess()); + ParticleOptions mainParticle = ParticleParser.getEffect(main, player.server.registryAccess()); if (accentParticle != null) player.serverLevel().sendParticles( player, diff --git a/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java b/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java index 69f9a9c0..42f5fdad 100644 --- a/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java +++ b/src/main/java/carpet/mixins/Guardian_renewableSpongesMixin.java @@ -28,7 +28,7 @@ public abstract class Guardian_renewableSpongesMixin extends Monster { ElderGuardian elderGuardian = new ElderGuardian(EntityType.ELDER_GUARDIAN ,this.level()); elderGuardian.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); - elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), MobSpawnType.CONVERSION, (SpawnGroupData)null, (CompoundTag)null); + elderGuardian.finalizeSpawn(serverWorld ,this.level().getCurrentDifficultyAt(elderGuardian.blockPosition()), MobSpawnType.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 9f8dc129..67119c30 100644 --- a/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java +++ b/src/main/java/carpet/mixins/LevelRenderer_scarpetRenderMixin.java @@ -36,14 +36,14 @@ public class LevelRenderer_scarpetRenderMixin //target = "Lnet/minecraft/client/render/BufferBuilderStorage;getEntityVertexConsumers()Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;", shift = At.Shift.AFTER //target = "Lnet/minecraft/client/render/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/render/Camera;)V", shift = At.Shift.AFTER // before return )) - private void renderScarpetThings(PoseStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) + private void renderScarpetThings(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f modelViewMatrix, Matrix4f matrix4f, CallbackInfo ci) { // in normal circumstances we want to render shapes at the very end so it appears correctly behind stuff. // we might actually not need to play with render hooks here. //if (!FabricAPIHooks.WORLD_RENDER_EVENTS && CarpetClient.shapes != null ) if (CarpetClient.shapes != null) { - CarpetClient.shapes.render(matrices, camera, tickDelta); + CarpetClient.shapes.render(modelViewMatrix, camera, tickDelta); } } } diff --git a/src/main/java/carpet/mixins/NaturalSpawnerMixin.java b/src/main/java/carpet/mixins/NaturalSpawnerMixin.java index fc470860..8cd2f826 100644 --- a/src/main/java/carpet/mixins/NaturalSpawnerMixin.java +++ b/src/main/java/carpet/mixins/NaturalSpawnerMixin.java @@ -176,12 +176,12 @@ public class NaturalSpawnerMixin @Redirect(method = "spawnCategoryForPosition(Lnet/minecraft/world/entity/MobCategory;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/chunk/ChunkAccess;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/NaturalSpawner$SpawnPredicate;Lnet/minecraft/world/level/NaturalSpawner$AfterSpawnCallback;)V", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/Mob;finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/MobSpawnType;Lnet/minecraft/world/entity/SpawnGroupData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/entity/SpawnGroupData;" + target = "Lnet/minecraft/world/entity/Mob;finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/MobSpawnType;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;" )) - private static SpawnGroupData spawnEntity(Mob mobEntity, ServerLevelAccessor serverWorldAccess, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData, CompoundTag entityTag) + private static SpawnGroupData spawnEntity(Mob mobEntity, ServerLevelAccessor serverWorldAccess, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData) { if (!SpawnReporter.mockSpawns) // WorldAccess - return mobEntity.finalizeSpawn(serverWorldAccess, difficulty, spawnReason, entityData, entityTag); + return mobEntity.finalizeSpawn(serverWorldAccess, difficulty, spawnReason, entityData); return null; } diff --git a/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java b/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java index 9fee32a5..45fd6c97 100644 --- a/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java +++ b/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java @@ -5,6 +5,7 @@ import carpet.fakes.BlockEntityInterface; import carpet.fakes.PistonBlockEntityInterface; import carpet.fakes.LevelInterface; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -41,6 +42,7 @@ public abstract class PistonMovingBlockEntity_movableBEMixin extends BlockEntity /** * @author 2No2Name */ + @Override public BlockEntity getCarriedBlockEntity() { return carriedBlockEntity; @@ -52,6 +54,7 @@ public abstract class PistonMovingBlockEntity_movableBEMixin extends BlockEntity if (carriedBlockEntity != null) carriedBlockEntity.setLevel(world); } + @Override public void setCarriedBlockEntity(BlockEntity blockEntity) { this.carriedBlockEntity = blockEntity; @@ -63,17 +66,20 @@ public abstract class PistonMovingBlockEntity_movableBEMixin extends BlockEntity } // this.carriedBlockEntity.setPos(this.pos); } - + + @Override public boolean isRenderModeSet() { return renderSet; } - + + @Override public boolean getRenderCarriedBlockEntity() { return renderCarriedBlockEntity; } - + + @Override public void setRenderCarriedBlockEntity(boolean b) { renderCarriedBlockEntity = b; @@ -128,25 +134,25 @@ public abstract class PistonMovingBlockEntity_movableBEMixin extends BlockEntity } @Inject(method = "load", at = @At(value = "TAIL")) - private void onFromTag(CompoundTag NbtCompound_1, CallbackInfo ci) + private void onFromTag(CompoundTag NbtCompound_1, HolderLookup.Provider registries, CallbackInfo ci) { if (CarpetSettings.movableBlockEntities && NbtCompound_1.contains("carriedTileEntityCM", 10)) { if (this.movedState.getBlock() instanceof EntityBlock) this.carriedBlockEntity = ((EntityBlock) (this.movedState.getBlock())).newBlockEntity(worldPosition, movedState);// this.world); if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null - this.carriedBlockEntity.load(NbtCompound_1.getCompound("carriedTileEntityCM")); + this.carriedBlockEntity.load(NbtCompound_1.getCompound("carriedTileEntityCM"), registries); setCarriedBlockEntity(carriedBlockEntity); } } @Inject(method = "saveAdditional", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) - private void onToTag(CompoundTag NbtCompound_1, CallbackInfo ci) + private void onToTag(CompoundTag NbtCompound_1, HolderLookup.Provider registries, CallbackInfo ci) { if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null) { //Leave name "carriedTileEntityCM" instead of "carriedBlockEntityCM" for upgrade compatibility with 1.13.2 movable TE - NbtCompound_1.put("carriedTileEntityCM", this.carriedBlockEntity.saveWithoutMetadata()); + NbtCompound_1.put("carriedTileEntityCM", this.carriedBlockEntity.saveWithoutMetadata(registries)); } } } diff --git a/src/main/java/carpet/script/api/Entities.java b/src/main/java/carpet/script/api/Entities.java index c4919f6f..744f8c43 100644 --- a/src/main/java/carpet/script/api/Entities.java +++ b/src/main/java/carpet/script/api/Entities.java @@ -152,7 +152,7 @@ public class Entities } if (!hasTag && entity instanceof final Mob mob) { - mob.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null, null); + mob.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null); } if (!serverWorld.tryAddFreshEntityWithPassengers(entity)) { diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 655e22df..084d9934 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -827,7 +827,7 @@ public class WorldAccess destTag.putInt("x", targetPos.getX()); destTag.putInt("y", targetPos.getY()); destTag.putInt("z", targetPos.getZ()); - be.load(destTag); + be.load(destTag, world.registryAccess()); be.setChanged(); success = true; } diff --git a/src/main/java/carpet/script/command/CommandArgument.java b/src/main/java/carpet/script/command/CommandArgument.java index f8a05dd1..a6d83f3d 100644 --- a/src/main/java/carpet/script/command/CommandArgument.java +++ b/src/main/java/carpet/script/command/CommandArgument.java @@ -199,7 +199,7 @@ public abstract class CommandArgument ), // operation // not sure if we need it, you have scarpet for that new VanillaUnconfigurableArgument("particle", ParticleArgument::particle, - (c, p) -> ValueConversions.of(ParticleArgument.getParticle(c, p)), (c, b) -> SharedSuggestionProvider.suggestResource(c.getSource().getServer().registryAccess().registryOrThrow(Registries.PARTICLE_TYPE).keySet(), b) + (c, p) -> ValueConversions.of(ParticleArgument.getParticle(c, p), c.getSource().registryAccess()), (c, b) -> SharedSuggestionProvider.suggestResource(c.getSource().getServer().registryAccess().registryOrThrow(Registries.PARTICLE_TYPE).keySet(), b) ), // resource / identifier section diff --git a/src/main/java/carpet/script/utils/ParticleParser.java b/src/main/java/carpet/script/utils/ParticleParser.java index 94485d31..b386f52e 100644 --- a/src/main/java/carpet/script/utils/ParticleParser.java +++ b/src/main/java/carpet/script/utils/ParticleParser.java @@ -3,9 +3,8 @@ package carpet.script.utils; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.arguments.ParticleArgument; -import net.minecraft.core.HolderLookup; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleType; import javax.annotation.Nullable; import java.util.HashMap; @@ -15,7 +14,7 @@ public class ParticleParser { private static final Map particleCache = new HashMap<>(); // we reset this on reloads, but probably need something better - private static ParticleOptions parseParticle(String name, HolderLookup> lookup) + private static ParticleOptions parseParticle(String name, RegistryAccess lookup) { try { @@ -28,7 +27,7 @@ public class ParticleParser } @Nullable - public static ParticleOptions getEffect(@Nullable String name, HolderLookup> lookup) + public static ParticleOptions getEffect(@Nullable String name, RegistryAccess lookup) { if (name == null) { diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index e2b02644..64aad343 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -185,7 +185,7 @@ public class ShapeDispatcher { try { - return ParticleParser.getEffect(name, regs.lookupOrThrow(Registries.PARTICLE_TYPE)); + return ParticleParser.getEffect(name, regs); } catch (IllegalArgumentException e) { diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 6d3a8c8c..a36d9edf 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -54,6 +54,8 @@ 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.phys.Vec3; +import org.joml.Matrix4f; +import org.joml.Matrix4fStack; public class ShapesRenderer { @@ -110,9 +112,12 @@ public class ShapesRenderer labels = new HashMap<>(); } - public void render(PoseStack matrices, Camera camera, float partialTick) + public void render(Matrix4f modelViewMatrix, Camera camera, float partialTick) { Runnable token = Carpet.startProfilerSection("Scarpet client"); + // posestack is not needed anymore - left as TODO to cleanup later + PoseStack matrices = new PoseStack(); + //Camera camera = this.client.gameRenderer.getCamera(); ClientLevel iWorld = this.client.level; ResourceKey dimensionType = iWorld.dimension(); @@ -151,9 +156,9 @@ public class ShapesRenderer shapes.get(dimensionType).long2ObjectEntrySet().removeIf( entry -> entry.getValue().isExpired(currentTime) ); - PoseStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.pushPose(); - matrixStack.mulPoseMatrix(matrices.last().pose()); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.pushMatrix(); + matrixStack.mul(matrices.last().pose()); RenderSystem.applyModelViewMatrix(); // lines @@ -173,7 +178,7 @@ public class ShapesRenderer } }); RenderSystem.lineWidth(1.0F); - matrixStack.popPose(); + matrixStack.popMatrix(); RenderSystem.applyModelViewMatrix(); } @@ -428,7 +433,7 @@ public class ShapesRenderer BlockEntity.setLevel(client.level); if (shape.blockEntity != null) { - BlockEntity.load(shape.blockEntity); + BlockEntity.load(shape.blockEntity, client.level.registryAccess()); } } } diff --git a/src/main/java/carpet/script/value/BlockValue.java b/src/main/java/carpet/script/value/BlockValue.java index b4e47e54..09075505 100644 --- a/src/main/java/carpet/script/value/BlockValue.java +++ b/src/main/java/carpet/script/value/BlockValue.java @@ -140,7 +140,7 @@ public class BlockValue extends Value data = new CompoundTag(); return null; } - data = be.saveWithoutMetadata(); + data = be.saveWithoutMetadata(be.getLevel().registryAccess()); return data; } return null; diff --git a/src/main/java/carpet/script/value/NBTSerializableValue.java b/src/main/java/carpet/script/value/NBTSerializableValue.java index 2c367517..1a812c2d 100644 --- a/src/main/java/carpet/script/value/NBTSerializableValue.java +++ b/src/main/java/carpet/script/value/NBTSerializableValue.java @@ -355,7 +355,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa { return customTag == null ? res : new ItemInput(Holder.direct(res.getItem()), customTag); } - ItemParser.ItemResult parser = ItemParser.parseForItem(regs.lookupOrThrow(Registries.ITEM), new StringReader(itemString)); + ItemParser.ItemResult parser = (new ItemParser(regs)).parse(new StringReader(itemString)); res = new ItemInput(parser.item(), parser.nbt()); itemCache.put(itemString, res); diff --git a/src/main/java/carpet/script/value/ValueConversions.java b/src/main/java/carpet/script/value/ValueConversions.java index d3f9ad03..7ead030a 100644 --- a/src/main/java/carpet/script/value/ValueConversions.java +++ b/src/main/java/carpet/script/value/ValueConversions.java @@ -134,9 +134,9 @@ public class ValueConversions } - public static Value of(ParticleOptions particle) + public static Value of(ParticleOptions particle, RegistryAccess regs) { - String repr = particle.writeToString(); + String repr = particle.writeToString(regs); return StringValue.of(repr.startsWith("minecraft:") ? repr.substring(10) : repr); } diff --git a/src/main/java/carpet/utils/BlockInfo.java b/src/main/java/carpet/utils/BlockInfo.java index 9547b6c0..fee3a328 100644 --- a/src/main/java/carpet/utils/BlockInfo.java +++ b/src/main/java/carpet/utils/BlockInfo.java @@ -75,7 +75,7 @@ public class BlockInfo private static Component wander_chances(BlockPos pos, ServerLevel worldIn) { PathfinderMob creature = new ZombifiedPiglin(EntityType.ZOMBIFIED_PIGLIN, worldIn); - creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), MobSpawnType.NATURAL, null, null); + creature.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(pos), MobSpawnType.NATURAL, null); creature.moveTo(pos, 0.0F, 0.0F); RandomStrollGoal wander = new RandomStrollGoal(creature, 0.8D); int success = 0; diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index 4bee4ad4..512431c9 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -459,7 +459,7 @@ public class SpawnReporter willSpawn += 1; } } - mob.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.NATURAL, null, null); + mob.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.NATURAL, null); // the code invokes onInitialSpawn after getCanSpawHere fits = fits && worldIn.noCollision(mob);