diff --git a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java index db8d929c..81929187 100644 --- a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java @@ -78,7 +78,6 @@ public abstract class ServerLevel_scarpetMixin extends Level implements ServerWo case MOB -> this.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) ? this.getCMDestroyType(GameRules.RULE_MOB_EXPLOSION_DROP_DECAY) : Explosion.BlockInteraction.KEEP; case TNT -> this.getCMDestroyType(GameRules.RULE_TNT_EXPLOSION_DROP_DECAY); case TRIGGER -> Explosion.BlockInteraction.TRIGGER_BLOCK; - default -> throw new IncompatibleClassChangeError(); }; boolean cancelled = EXPLOSION.onExplosion((ServerLevel) (Object) this, entity, null, new Vec3(x, y, z), g, bl, null, null, var10000); diff --git a/src/main/java/carpet/script/ScriptCommand.java b/src/main/java/carpet/script/ScriptCommand.java index 5c73f6b1..8383849a 100644 --- a/src/main/java/carpet/script/ScriptCommand.java +++ b/src/main/java/carpet/script/ScriptCommand.java @@ -16,6 +16,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.commands.CommandBuildContext; import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameRules; import org.apache.commons.lang3.StringUtils; import java.io.IOException; @@ -665,7 +666,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 > Vanilla.MinecraftServer_getFillLimit(source.getServer()) ) + if (int_1 > source.getServer().getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT)) { Carpet.Messenger_message(source, "r too many blocks to evaluate: " + int_1); return 1; @@ -717,7 +718,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 > Vanilla.MinecraftServer_getFillLimit(source.getServer())) + if (int_1 > source.getServer().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/Carpet.java b/src/main/java/carpet/script/external/Carpet.java index a6fdc1c6..223fc98b 100644 --- a/src/main/java/carpet/script/external/Carpet.java +++ b/src/main/java/carpet/script/external/Carpet.java @@ -85,6 +85,7 @@ public class Carpet return () -> CarpetProfiler.end_current_section(token); } + // not needed in vanilla public static void MinecraftServer_addScriptServer(MinecraftServer server, CarpetScriptServer scriptServer) { ((MinecraftServerInterface) server).addScriptServer(scriptServer); diff --git a/src/main/java/carpet/script/external/Vanilla.java b/src/main/java/carpet/script/external/Vanilla.java index fc5b338b..942157b6 100644 --- a/src/main/java/carpet/script/external/Vanilla.java +++ b/src/main/java/carpet/script/external/Vanilla.java @@ -1,23 +1,7 @@ package carpet.script.external; import carpet.CarpetSettings; -import carpet.fakes.BiomeInterface; -import carpet.fakes.BlockPredicateInterface; -import carpet.fakes.BlockStateArgumentInterface; -import carpet.fakes.TicketsFetcherInterface; -import carpet.fakes.CommandDispatcherInterface; -import carpet.fakes.EntityInterface; -import carpet.fakes.InventoryBearerInterface; -import carpet.fakes.ItemEntityInterface; -import carpet.fakes.LivingEntityInterface; -import carpet.fakes.MinecraftServerInterface; -import carpet.fakes.MobEntityInterface; -import carpet.fakes.RandomStateVisitorAccessor; -import carpet.fakes.AbstractContainerMenuInterface; -import carpet.fakes.ServerPlayerInterface; -import carpet.fakes.ServerPlayerInteractionManagerInterface; -import carpet.fakes.ServerWorldInterface; -import carpet.fakes.SpawnHelperInnerInterface; +import carpet.fakes.*; import carpet.mixins.Objective_scarpetMixin; import carpet.mixins.PoiRecord_scarpetMixin; import carpet.mixins.Scoreboard_scarpetMixin; @@ -46,7 +30,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayerGameMode; import net.minecraft.server.level.Ticket; import net.minecraft.tags.TagKey; -import net.minecraft.util.SortedArraySet; import net.minecraft.world.Container; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -56,10 +39,10 @@ import net.minecraft.world.entity.ai.goal.GoalSelector; import net.minecraft.world.entity.ai.village.poi.PoiRecord; import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.food.FoodData; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.DataSlot; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.GameRules; import net.minecraft.world.level.NaturalSpawner; import net.minecraft.world.level.PotentialCalculator; import net.minecraft.world.level.biome.Biome; @@ -207,11 +190,6 @@ public class Vanilla return ((ServerPlayerInterface) player).isInvalidEntityObject(); } - public static String ServerPlayer_getLanguage(ServerPlayer player) - { - return player.clientInformation().language(); - } - public static GoalSelector Mob_getAI(Mob mob, boolean target) { return ((MobEntityInterface) mob).getAI(target); @@ -322,11 +300,6 @@ public class Vanilla return CommandHelper.canUseCommand(player, CarpetSettings.commandScript); } - public static int MinecraftServer_getFillLimit(MinecraftServer server) - { - return server.getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT); - } - public static int PoiRecord_getFreeTickets(PoiRecord record) { return ((PoiRecord_scarpetMixin) record).getFreeTickets(); @@ -337,6 +310,14 @@ public class Vanilla ((PoiRecord_scarpetMixin) record).callAcquireTicket(); } + public static double FoodData_getExhaustion(FoodData foodData) { + return ((FoodDataInterface)foodData).getCMExhaustionLevel(); + } + + public static void FoodData_setExhaustion(FoodData foodData, float exhaustion) { + ((FoodDataInterface)foodData).setExhaustion(exhaustion); + } + public record BlockPredicatePayload(BlockState state, TagKey tagKey, Map properties, CompoundTag tag) { public static BlockPredicatePayload of(Predicate blockPredicate) { diff --git a/src/main/java/carpet/script/external/VanillaClient.java b/src/main/java/carpet/script/external/VanillaClient.java deleted file mode 100644 index 86a0086c..00000000 --- a/src/main/java/carpet/script/external/VanillaClient.java +++ /dev/null @@ -1,5 +0,0 @@ -package carpet.script.external; - -public class VanillaClient -{ -} diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 07c4d371..f6188f45 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -1,6 +1,5 @@ package carpet.script.value; -import carpet.fakes.FoodDataInterface; import carpet.script.external.Vanilla; import carpet.script.utils.Tracer; import carpet.script.CarpetContext; @@ -27,11 +26,9 @@ import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.StringTag; import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket; -import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket; import net.minecraft.network.protocol.game.ClientboundSetHeldSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; @@ -53,8 +50,6 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.PathfinderMob; import net.minecraft.world.entity.Pose; -import net.minecraft.world.entity.PositionMoveRotation; -import net.minecraft.world.entity.Relative; import net.minecraft.world.entity.ai.Brain; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeMap; @@ -84,7 +79,6 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; -import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -553,11 +547,11 @@ public class EntityValue extends Value put("swimming", (e, a) -> e.isSwimming() ? Value.TRUE : Value.FALSE); put("swinging", (e, a) -> e instanceof LivingEntity le ? BooleanValue.of(le.swinging) : Value.NULL); put("air", (e, a) -> new NumericValue(e.getAirSupply())); - put("language", (e, a) -> !(e instanceof ServerPlayer p) ? NULL : StringValue.of(Vanilla.ServerPlayer_getLanguage(p))); + put("language", (e, a) -> !(e instanceof ServerPlayer p) ? NULL : StringValue.of(p.clientInformation().language())); put("persistence", (e, a) -> e instanceof Mob mob ? BooleanValue.of(mob.isPersistenceRequired()) : Value.NULL); put("hunger", (e, a) -> e instanceof Player player ? new NumericValue(player.getFoodData().getFoodLevel()) : Value.NULL); put("saturation", (e, a) -> e instanceof Player player ? new NumericValue(player.getFoodData().getSaturationLevel()) : Value.NULL); - put("exhaustion", (e, a) -> e instanceof Player player ? new NumericValue(((FoodDataInterface)player.getFoodData()).getCMExhaustionLevel()) : Value.NULL); + put("exhaustion", (e, a) -> e instanceof Player player ? new NumericValue(Vanilla.FoodData_getExhaustion(player.getFoodData())) : Value.NULL); put("absorption", (e, a) -> e instanceof Player player ? new NumericValue(player.getAbsorptionAmount()) : Value.NULL); put("xp", (e, a) -> e instanceof Player player ? new NumericValue(player.totalExperience) : Value.NULL); put("xp_level", (e, a) -> e instanceof Player player ? new NumericValue(player.experienceLevel) : Value.NULL); @@ -1611,7 +1605,10 @@ public class EntityValue extends Value put("exhaustion", (e, v) -> { if (e instanceof Player p) { - ((FoodDataInterface)p.getFoodData()).setExhaustion(NumericValue.asNumber(v).getFloat()); + Vanilla.FoodData_setExhaustion( + p.getFoodData(), + NumericValue.asNumber(v, "exhaustion").getFloat() + ); } });