diff --git a/gradle.properties b/gradle.properties index 6087de9b75..2fb407e40c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=23w51b - loader_version=0.15.3 + minecraft_version=24w03a + 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/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 63971585b9..6d18c4d0a7 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -9,7 +9,6 @@ import carpet.utils.Translations; import carpet.utils.CommandHelper; import carpet.utils.Messenger; -import carpet.utils.SpawnChunks; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.registries.Registries; @@ -770,37 +769,6 @@ private static class SimulationDistanceValidator extends Validator ) public static int simulationDistance = 0; - public static class ChangeSpawnChunksValidator extends Validator { - @Override public Integer validate(CommandSourceStack source, CarpetRule currentRule, Integer newValue, String string) { - if (source == null) return newValue; - if (newValue < 0 || newValue > 32) - { - Messenger.m(source, "r spawn chunk size has to be between 0 and 32"); - return null; - } - if (currentRule.value().intValue() == newValue.intValue()) - { - //must been some startup thing - return newValue; - } - ServerLevel currentOverworld = source.getServer().overworld(); - if (currentOverworld != null) - { - SpawnChunks.changeSpawnSize(currentOverworld, newValue); - } - return newValue; - } - } - @Rule( - desc = "Changes size of spawn chunks", - extra = {"Defines new radius", "setting it to 0 - disables spawn chunks"}, - category = CREATIVE, - strict = false, - options = {"0", "11"}, - validate = ChangeSpawnChunksValidator.class - ) - public static int spawnChunksSize = MinecraftServer.START_CHUNK_RADIUS; - public enum RenewableCoralMode { FALSE, EXPANDED, diff --git a/src/main/java/carpet/helpers/BlockRotator.java b/src/main/java/carpet/helpers/BlockRotator.java index ea876368d3..a815c8da2e 100644 --- a/src/main/java/carpet/helpers/BlockRotator.java +++ b/src/main/java/carpet/helpers/BlockRotator.java @@ -131,7 +131,7 @@ else if (block instanceof PistonBaseBlock) } else if (block instanceof SlabBlock) { - if (((SlabBlock) block).useShapeForLightOcclusion(state)) + if (state.getValue(SlabBlock.TYPE) != SlabType.DOUBLE) { newState = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP); } diff --git a/src/main/java/carpet/helpers/CarpetTaintedList.java b/src/main/java/carpet/helpers/CarpetTaintedList.java new file mode 100644 index 0000000000..5ab22b15c5 --- /dev/null +++ b/src/main/java/carpet/helpers/CarpetTaintedList.java @@ -0,0 +1,12 @@ +package carpet.helpers; + +import java.util.ArrayList; +import java.util.List; + +public class CarpetTaintedList extends ArrayList +{ + public CarpetTaintedList(final List list) + { + super(list); + } +} diff --git a/src/main/java/carpet/helpers/OptimizedExplosion.java b/src/main/java/carpet/helpers/OptimizedExplosion.java index 589e3a22c2..6af3277609 100644 --- a/src/main/java/carpet/helpers/OptimizedExplosion.java +++ b/src/main/java/carpet/helpers/OptimizedExplosion.java @@ -215,7 +215,7 @@ public static void doExplosionB(Explosion e, boolean spawnParticles) // explosionSound incremented till disabling the explosion particles and sound if (explosionSound < 100 || explosionSound % 100 == 0) { - world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, + world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE.value(), SoundSource.BLOCKS, 4.0F, (1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F); if (spawnParticles) diff --git a/src/main/java/carpet/helpers/RedstoneWireTurbo.java b/src/main/java/carpet/helpers/RedstoneWireTurbo.java index 33aa2ddcf6..30a1c37de1 100644 --- a/src/main/java/carpet/helpers/RedstoneWireTurbo.java +++ b/src/main/java/carpet/helpers/RedstoneWireTurbo.java @@ -676,7 +676,7 @@ private void breadthFirstWalk(final Level worldIn) { // call BlockStateBase#neighborChanged directly. This change mostly // restores old behavior, at the cost of bypassing the // max-chained-neighbor-updates server property. - worldIn.getBlockState(upd.self).neighborChanged(worldIn, upd.self, wire, upd.parent, false); + worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, upd.parent, false); } } diff --git a/src/main/java/carpet/mixins/ClientboundCustomPayloadPacket_customPacketMixin.java b/src/main/java/carpet/mixins/ClientboundCustomPayloadPacket_customPacketMixin.java deleted file mode 100644 index 6933c13e18..0000000000 --- a/src/main/java/carpet/mixins/ClientboundCustomPayloadPacket_customPacketMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package carpet.mixins; - - -import carpet.network.CarpetClient; -import carpet.network.ClientNetworkHandler; -import net.minecraft.client.Minecraft; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.network.protocol.common.custom.DiscardedPayload; -import net.minecraft.resources.ResourceLocation; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ClientboundCustomPayloadPacket.class) -public class ClientboundCustomPayloadPacket_customPacketMixin -{ - @Inject(method = "readPayload", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;"), - cancellable = true) - private static void onOnCustomPayloadR(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable cir) - { - if (resourceLocation.equals(CarpetClient.CARPET_CHANNEL)) - { - cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf)); - } - } -} diff --git a/src/main/java/carpet/mixins/CustomPacketPayload_networkStuffMixin.java b/src/main/java/carpet/mixins/CustomPacketPayload_networkStuffMixin.java new file mode 100644 index 0000000000..7e9c88e3df --- /dev/null +++ b/src/main/java/carpet/mixins/CustomPacketPayload_networkStuffMixin.java @@ -0,0 +1,31 @@ +package carpet.mixins; + +import carpet.helpers.CarpetTaintedList; +import carpet.network.CarpetClient; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(CustomPacketPayload.class) +public interface CustomPacketPayload_networkStuffMixin +{ + @Inject(method = "codec(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$FallbackProvider;Ljava/util/List;)Lnet/minecraft/network/codec/StreamCodec;", at = @At("HEAD"), cancellable = true) + private static void onCodec(final CustomPacketPayload.FallbackProvider fallbackProvider, final List> list, final CallbackInfoReturnable> cir) + { + // this is stupid hack to make sure carpet payloads are always registered + // that might collide with other mods that do the same thing + // so we may need to adjust this in the future + if (!(list instanceof CarpetTaintedList)) + { + List> extendedList = new CarpetTaintedList<>(list); + extendedList.add(new CustomPacketPayload.TypeAndCodec<>(CarpetClient.CarpetPayload.TYPE, CarpetClient.CarpetPayload.STREAM_CODEC)); + cir.setReturnValue(CustomPacketPayload.codec(fallbackProvider, extendedList)); + } + } +} diff --git a/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java b/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java index eb9b3911dc..3cf32d6cf8 100644 --- a/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java +++ b/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java @@ -5,8 +5,8 @@ import carpet.logging.LoggerRegistry; import carpet.logging.logHelpers.ExplosionLogHelper; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.core.Holder; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.sounds.SoundEvent; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.breeze.Breeze; import org.jetbrains.annotations.Nullable; @@ -81,9 +81,9 @@ private BlockState noBlockCalcsWithNoBLockDamage(Level world, BlockPos pos) return world.getBlockState(pos); } - @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V", at = @At(value = "RETURN")) - private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci) + private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder soundEvent, CallbackInfo ci) { if (LoggerRegistry.__explosions && ! world.isClientSide) { diff --git a/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java b/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java index 97c0f8df6e..12e9bf2b61 100644 --- a/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java @@ -1,8 +1,8 @@ package carpet.mixins; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.core.Holder; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.sounds.SoundEvent; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -45,9 +45,9 @@ public abstract class Explosion_scarpetEventMixin private List affectedEntities; - @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V", at = @At(value = "RETURN")) - private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci) + private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder soundEvent, CallbackInfo ci) { if (EXPLOSION_OUTCOME.isNeeded() && !world.isClientSide()) { diff --git a/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java b/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java index e8b5aba016..b227c40bd8 100644 --- a/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java +++ b/src/main/java/carpet/mixins/MinecraftServer_coreMixin.java @@ -1,12 +1,9 @@ package carpet.mixins; import carpet.CarpetServer; -import carpet.CarpetSettings; import carpet.utils.CarpetProfiler; -import carpet.utils.SpawnChunks; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.progress.ChunkProgressListener; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -61,11 +58,4 @@ private void serverDoneClosed(CallbackInfo ci) @Shadow public abstract ServerLevel overworld(); - - @Inject(method = "prepareLevels", at = @At("RETURN")) - private void afterSpawnCreated(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci) - { - if (CarpetSettings.spawnChunksSize != 11) - SpawnChunks.changeSpawnSize(overworld(), CarpetSettings.spawnChunksSize); - } } diff --git a/src/main/java/carpet/mixins/PickaxeItem_missingToolsMixin.java b/src/main/java/carpet/mixins/PickaxeItem_missingToolsMixin.java index 890dcdfbd6..bbe2d33978 100644 --- a/src/main/java/carpet/mixins/PickaxeItem_missingToolsMixin.java +++ b/src/main/java/carpet/mixins/PickaxeItem_missingToolsMixin.java @@ -21,7 +21,7 @@ protected PickaxeItem_missingToolsMixin(float attackDamage, float attackSpeed, T @Override public float getDestroySpeed(ItemStack stack, BlockState state) { - if (CarpetSettings.missingTools && state.getBlock().getSoundType(state) == SoundType.GLASS) + if (CarpetSettings.missingTools && state.getSoundType() == SoundType.GLASS) { return speed; } diff --git a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java index 3bef4f5ab7..b9b870b311 100644 --- a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java @@ -66,7 +66,7 @@ private Explosion.BlockInteraction getCMDestroyType(final GameRules.Key cir) + private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder soundEvent, CallbackInfoReturnable cir) { if (EXPLOSION.isNeeded()) { Explosion.BlockInteraction var10000 = switch (explosionInteraction) { diff --git a/src/main/java/carpet/mixins/ServerLevel_spawnChunksMixin.java b/src/main/java/carpet/mixins/ServerLevel_spawnChunksMixin.java deleted file mode 100644 index c00b6dc3cc..0000000000 --- a/src/main/java/carpet/mixins/ServerLevel_spawnChunksMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package carpet.mixins; - -import carpet.CarpetSettings; -import net.minecraft.server.level.ServerLevel; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(ServerLevel.class) -public class ServerLevel_spawnChunksMixin -{ - @ModifyConstant(method = "setDefaultSpawnPos", constant = @Constant(intValue = 11), expect = 2) - private int pushLimit(int original) - { - return CarpetSettings.spawnChunksSize; - } -} diff --git a/src/main/java/carpet/mixins/ServerPlayerGameMode_antiCheatMixin.java b/src/main/java/carpet/mixins/ServerPlayerGameMode_antiCheatMixin.java index 002eaad0e5..ea8dfa6855 100644 --- a/src/main/java/carpet/mixins/ServerPlayerGameMode_antiCheatMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayerGameMode_antiCheatMixin.java @@ -1,38 +1,43 @@ package carpet.mixins; import carpet.CarpetSettings; -import com.mojang.authlib.GameProfile; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = ServerPlayer.class) -public abstract class ServerPlayerGameMode_antiCheatMixin extends Player +@Mixin(value = Player.class) +public abstract class ServerPlayerGameMode_antiCheatMixin extends LivingEntity { - public ServerPlayerGameMode_antiCheatMixin(final Level level, final BlockPos blockPos, final float f, final GameProfile gameProfile) + @Shadow public abstract double entityInteractionRange(); + + @Shadow public abstract double blockInteractionRange(); + + protected ServerPlayerGameMode_antiCheatMixin(final EntityType entityType, final Level level) { - super(level, blockPos, f, gameProfile); + super(entityType, level); } @Inject(method = "canInteractWithBlock", at = @At("HEAD"), cancellable = true) - private void canInteractLongRangeBlock(BlockPos pos, CallbackInfoReturnable cir) + private void canInteractLongRangeBlock(BlockPos pos, double d, CallbackInfoReturnable cir) { - double maxRange = blockInteractionRange() + 1.0; + double maxRange = blockInteractionRange() + d; maxRange = maxRange * maxRange; if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) < 1024) cir.setReturnValue(true); } - @Inject(method = "canInteractWithEntity", at = @At("HEAD"), cancellable = true) - private void canInteractLongRangeEntity(AABB aabb, CallbackInfoReturnable cir) + @Inject(method = "canInteractWithEntity(Lnet/minecraft/world/phys/AABB;D)Z", at = @At("HEAD"), cancellable = true) + private void canInteractLongRangeEntity(AABB aabb, double d, CallbackInfoReturnable cir) { - double maxRange = entityInteractionRange() + 1.0; + double maxRange = entityInteractionRange() + d; maxRange = maxRange * maxRange; if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && aabb.distanceToSqr(getEyePosition()) < 1024) cir.setReturnValue(true); } diff --git a/src/main/java/carpet/mixins/ServerboundCustomPayloadPacket_mixin.java b/src/main/java/carpet/mixins/ServerboundCustomPayloadPacket_mixin.java deleted file mode 100644 index 2408ad38fd..0000000000 --- a/src/main/java/carpet/mixins/ServerboundCustomPayloadPacket_mixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package carpet.mixins; - -import carpet.network.CarpetClient; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ServerboundCustomPayloadPacket.class) -public class ServerboundCustomPayloadPacket_mixin -{ - @Inject(method = "readPayload", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/network/protocol/common/ServerboundCustomPayloadPacket;readUnknownPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/DiscardedPayload;" - ), cancellable = true) - private static void onOnCustomPayload(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable cir) - { - if (CarpetClient.CARPET_CHANNEL.equals(resourceLocation)) - { - cir.setReturnValue(new CarpetClient.CarpetPayload(friendlyByteBuf)); - } - } -} diff --git a/src/main/java/carpet/network/CarpetClient.java b/src/main/java/carpet/network/CarpetClient.java index 5be5f45306..35f6708032 100644 --- a/src/main/java/carpet/network/CarpetClient.java +++ b/src/main/java/carpet/network/CarpetClient.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; @@ -16,21 +17,23 @@ public class CarpetClient { public record CarpetPayload(CompoundTag data) implements CustomPacketPayload { + public static final StreamCodec STREAM_CODEC = CustomPacketPayload.codec(CarpetPayload::write, CarpetPayload::new); + + public static final Type TYPE = new CustomPacketPayload.Type<>(CARPET_CHANNEL); + public CarpetPayload(FriendlyByteBuf input) { this(input.readNbt()); } - @Override public void write(FriendlyByteBuf output) { output.writeNbt(data); } - @Override - public ResourceLocation id() + @Override public Type type() { - return CARPET_CHANNEL; + return TYPE; } } diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index b4519bea43..563d1a3ad0 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -74,7 +74,7 @@ public static boolean createFake(String username, MinecraftServer server, Vec3 p } EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false); instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch); - server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation())); + server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation(), false)); instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch); instance.setHealth(20.0F); instance.unsetRemoved(); @@ -101,7 +101,7 @@ public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlay GameProfile gameprofile = player.getGameProfile(); EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, player.clientInformation(), true); playerShadow.setChatSession(player.getChatSession()); - server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation())); + server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation(), true)); playerShadow.setHealth(player.getHealth()); playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot()); diff --git a/src/main/java/carpet/patches/FakeClientConnection.java b/src/main/java/carpet/patches/FakeClientConnection.java index 5a7f8bafab..8a1a1b5644 100644 --- a/src/main/java/carpet/patches/FakeClientConnection.java +++ b/src/main/java/carpet/patches/FakeClientConnection.java @@ -4,6 +4,7 @@ import io.netty.channel.embedded.EmbeddedChannel; import net.minecraft.network.Connection; import net.minecraft.network.PacketListener; +import net.minecraft.network.ProtocolInfo; import net.minecraft.network.protocol.PacketFlow; public class FakeClientConnection extends Connection @@ -27,7 +28,12 @@ public void handleDisconnection() } @Override - public void setListener(PacketListener packetListener) + public void setListenerForServerboundHandshake(PacketListener packetListener) + { + } + + @Override + public void setupInboundProtocol(ProtocolInfo protocolInfo, T packetListener) { } } \ No newline at end of file diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 2bf8699f95..655e22df7e 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -58,6 +58,7 @@ import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureType; +import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; @@ -898,7 +899,7 @@ else if (args.get(0) instanceof final MapValue map) } world.levelEvent(null, 2001, where, Block.getId(state)); - boolean toolBroke = false; + final MutableBoolean toolBroke = new MutableBoolean(false); boolean dropLoot = true; if (playerBreak) { @@ -914,7 +915,8 @@ else if (item instanceof TridentItem || item instanceof SwordItem) { damageAmount = 2; } - toolBroke = damageAmount > 0 && tool.hurt(damageAmount, world.getRandom(), null); + final int finalDamageAmount = damageAmount; + tool.hurtAndBreak(damageAmount, world.getRandom(), null, () -> { if (finalDamageAmount > 0) toolBroke.setTrue(); } ); if (!isUsingEffectiveTool) { dropLoot = false; @@ -931,7 +933,7 @@ else if (item instanceof TridentItem || item instanceof SwordItem) { if (how > 0) { - tool.enchant(Enchantments.BLOCK_FORTUNE, (int) how); + tool.enchant(Enchantments.FORTUNE, (int) how); } if (DUMMY_ENTITY == null) { @@ -944,7 +946,7 @@ else if (item instanceof TridentItem || item instanceof SwordItem) { return Value.TRUE; } - if (toolBroke) + if (toolBroke.booleanValue()) { return Value.NULL; } diff --git a/src/main/java/carpet/script/utils/SystemInfo.java b/src/main/java/carpet/script/utils/SystemInfo.java index 4db445edc8..7a0d5e77ab 100644 --- a/src/main/java/carpet/script/utils/SystemInfo.java +++ b/src/main/java/carpet/script/utils/SystemInfo.java @@ -59,10 +59,7 @@ public class SystemInfo return StringValue.of(tlf); }); put("world_dimensions", c -> ListValue.wrap(c.server().levelKeys().stream().map(k -> ValueConversions.of(k.location())))); - put("world_spawn_point", c -> { - LevelData prop = c.server().overworld().getLevelData(); - return ListValue.of(NumericValue.of(prop.getXSpawn()), NumericValue.of(prop.getYSpawn()), NumericValue.of(prop.getZSpawn())); - }); + put("world_spawn_point", c -> ValueConversions.of(c.server().overworld().getLevelData().getSpawnPos())); put("world_bottom", c -> new NumericValue(c.level().getMinBuildHeight())); diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index f2ac387504..156500b489 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -34,6 +34,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.tags.EntityTypeTags; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; @@ -46,7 +47,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; -import net.minecraft.world.entity.MobType; import net.minecraft.world.entity.PathfinderMob; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.RelativeMovement; @@ -359,20 +359,26 @@ public Value listValue(RegistryAccess regs) // combat groups - put("arthropod", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() == MobType.ARTHROPOD && e.isAlive()), allTypes.stream().filter(arthropods::contains))); - put("!arthropod", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() != MobType.ARTHROPOD && e.isAlive()), allTypes.stream().filter(et -> !arthropods.contains(et) && living.contains(et)))); + put("arthropod", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (e.getType().is(EntityTypeTags.ARTHROPOD) && e.isAlive()), allTypes.stream().filter(arthropods::contains))); + put("!arthropod", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (!e.getType().is(EntityTypeTags.ARTHROPOD) && e.isAlive()), allTypes.stream().filter(et -> !arthropods.contains(et) && living.contains(et)))); - put("undead", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() == MobType.UNDEAD && e.isAlive()), allTypes.stream().filter(undeads::contains))); - put("!undead", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() != MobType.UNDEAD && e.isAlive()), allTypes.stream().filter(et -> !undeads.contains(et) && living.contains(et)))); + put("undead", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (e.getType().is(EntityTypeTags.UNDEAD) && e.isAlive()), allTypes.stream().filter(undeads::contains))); + put("!undead", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (!e.getType().is(EntityTypeTags.UNDEAD) && e.isAlive()), allTypes.stream().filter(et -> !undeads.contains(et) && living.contains(et)))); - put("aquatic", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() == MobType.WATER && e.isAlive()), allTypes.stream().filter(aquatique::contains))); - put("!aquatic", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() != MobType.WATER && e.isAlive()), allTypes.stream().filter(et -> !aquatique.contains(et) && living.contains(et)))); + put("aquatic", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (e.getType().is(EntityTypeTags.AQUATIC) && e.isAlive()), allTypes.stream().filter(aquatique::contains))); + put("!aquatic", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (!e.getType().is(EntityTypeTags.AQUATIC) && e.isAlive()), allTypes.stream().filter(et -> !aquatique.contains(et) && living.contains(et)))); - put("illager", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() == MobType.ILLAGER && e.isAlive()), allTypes.stream().filter(illagers::contains))); - put("!illager", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() != MobType.ILLAGER && e.isAlive()), allTypes.stream().filter(et -> !illagers.contains(et) && living.contains(et)))); + put("illager", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (e.getType().is(EntityTypeTags.ILLAGER) && e.isAlive()), allTypes.stream().filter(illagers::contains))); + put("!illager", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (!e.getType().is(EntityTypeTags.ILLAGER) && e.isAlive()), allTypes.stream().filter(et -> !illagers.contains(et) && living.contains(et)))); - put("regular", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() == MobType.UNDEFINED && e.isAlive()), allTypes.stream().filter(regular::contains))); - put("!regular", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> (((LivingEntity) e).getMobType() != MobType.UNDEFINED && e.isAlive()), allTypes.stream().filter(et -> !regular.contains(et) && living.contains(et)))); + put("regular", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> { + EntityType type = e.getType(); + return !illagers.contains(type) && !arthropods.contains(type) && !undeads.contains(type) && !aquatique.contains(type) && living.contains(type) && e.isAlive(); + }, allTypes.stream().filter(regular::contains))); + put("!regular", new EntityClassDescriptor(EntityTypeTest.forClass(LivingEntity.class), e -> { + EntityType type = e.getType(); + return (illagers.contains(type) || arthropods.contains(type) || undeads.contains(type) || aquatique.contains(type)) && e.isAlive(); + }, allTypes.stream().filter(et -> !regular.contains(et) && living.contains(et)))); for (ResourceLocation typeId : BuiltInRegistries.ENTITY_TYPE.keySet()) { diff --git a/src/main/java/carpet/utils/BlockInfo.java b/src/main/java/carpet/utils/BlockInfo.java index 1ca6d0c9f8..9547b6c0dc 100644 --- a/src/main/java/carpet/utils/BlockInfo.java +++ b/src/main/java/carpet/utils/BlockInfo.java @@ -39,7 +39,7 @@ public static List blockInfo(BlockPos pos, ServerLevel world) lst.add(Messenger.s("=====================================")); lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):", blocks.getKey(block),metastring, blocks.getId(block), metastring ))); lst.add(Messenger.s(String.format(" - Map colour: %s", Colors.mapColourName.get(state.getMapColor(world, pos))))); - lst.add(Messenger.s(String.format(" - Sound type: %s", Colors.soundName.get(block.getSoundType(state))))); + lst.add(Messenger.s(String.format(" - Sound type: %s", Colors.soundName.get(state.getSoundType())))); lst.add(Messenger.s("")); lst.add(Messenger.s(String.format(" - Full block: %s", state.isCollisionShapeFullBlock(world, pos)))); // isFullCube() ))); lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isRedstoneConductor(world, pos)))); //isNormalCube()))); isSimpleFullBlock @@ -61,7 +61,7 @@ public static List blockInfo(BlockPos pos, ServerLevel world) lst.add(Messenger.s(String.format(" - Can burn: %s", state.ignitedByLava()))); lst.add(Messenger.s(String.format(" - Hardness: %.2f", state.getDestroySpeed(world, pos)))); lst.add(Messenger.s(String.format(" - Blast resistance: %.2f", block.getExplosionResistance()))); - lst.add(Messenger.s(String.format(" - Ticks randomly: %s", block.isRandomlyTicking(state)))); + lst.add(Messenger.s(String.format(" - Ticks randomly: %s", state.isRandomlyTicking()))); lst.add(Messenger.s("")); lst.add(Messenger.s(String.format(" - Can provide power: %s", state.isSignalSource()))); lst.add(Messenger.s(String.format(" - Strong power level: %d", world.getDirectSignalTo(pos)))); diff --git a/src/main/java/carpet/utils/SpawnChunks.java b/src/main/java/carpet/utils/SpawnChunks.java deleted file mode 100644 index 1d7042ca1a..0000000000 --- a/src/main/java/carpet/utils/SpawnChunks.java +++ /dev/null @@ -1,21 +0,0 @@ -package carpet.utils; - -import carpet.fakes.ChunkTicketManagerInterface; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.DistanceManager; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.ChunkPos; - -public class SpawnChunks -{ - public static void changeSpawnSize(ServerLevel overworld, int size) - { - ChunkPos centerChunk = new ChunkPos(new BlockPos( - overworld.getLevelData().getXSpawn(), - overworld.getLevelData().getYSpawn(), - overworld.getLevelData().getZSpawn() - )); - DistanceManager ticketManager = overworld.getChunkSource().chunkMap.getDistanceManager(); - ((ChunkTicketManagerInterface)ticketManager).changeSpawnChunks(centerChunk, size); - } -} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index a68896207b..c43e4b5a86 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -47,7 +47,6 @@ "LayerLightEngine_scarpetChunkCreationMixin", "LayerLightSectionStorage_scarpetChunkCreationMixin", "DistanceManager_spawnChunksMixin", - "ServerLevel_spawnChunksMixin", "ThreadedLevelLightEngine_scarpetChunkCreationMixin", "LivingEntity_cleanLogsMixin", "MobMixin", @@ -181,9 +180,8 @@ "ChestBlock_customStickyMixin", "PistonStructureResolver_customStickyMixin", - "ServerboundCustomPayloadPacket_mixin", - "ServerCommonPacketListenerimpl_connectionMixin", - "ClientboundCustomPayloadPacket_customPacketMixin" + "CustomPacketPayload_networkStuffMixin", + "ServerCommonPacketListenerimpl_connectionMixin" ], "client": [