update to 24w33a

This commit is contained in:
gnembon committed 2024-08-18 19:10:40 +02:00
1 parent 9940feb7d3
commit d11586fdaf
58 files changed
+379 -875

No files matched your search

@@ -1051,11 +1051,11 @@ public class CarpetEventServer
public static final Event EXPLOSION_OUTCOME = new Event("explosion_outcome", 8, true)
{
@Override
public void onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, double x, double y, double z, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
public boolean onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, Vec3 center, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
{
handler.call(
() -> Arrays.asList(
ListValue.fromTriple(x, y, z),
ValueConversions.of(center),
NumericValue.of(power),
EntityValue.of(e),
EntityValue.of(attacker != null ? attacker.get() : Event.getExplosionCausingEntity(e)),
@@ -1067,6 +1067,7 @@ public class CarpetEventServer
ListValue.wrap(affectedEntities.stream().map(EntityValue::of))
), () -> world.getServer().createCommandSourceStack().withLevel(world)
);
return false;
}
};
@@ -1074,11 +1075,11 @@ public class CarpetEventServer
public static final Event EXPLOSION = new Event("explosion", 6, true)
{
@Override
public void onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, double x, double y, double z, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
public boolean onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, Vec3 center, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
{
handler.call(
return handler.call(
() -> Arrays.asList(
ListValue.fromTriple(x, y, z),
ValueConversions.of(center),
NumericValue.of(power),
EntityValue.of(e),
EntityValue.of(attacker != null ? attacker.get() : Event.getExplosionCausingEntity(e)),
@@ -1306,8 +1307,9 @@ public class CarpetEventServer
{
}
public void onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, double x, double y, double z, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
public boolean onExplosion(ServerLevel world, Entity e, Supplier<LivingEntity> attacker, Vec3 center, float power, boolean createFire, List<BlockPos> affectedBlocks, List<Entity> affectedEntities, Explosion.BlockInteraction type)
{
return false;
}
public void onWorldEvent(ServerLevel world, BlockPos pos)
@@ -33,9 +33,9 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@@ -142,7 +142,7 @@ public class Entities
Vec3 vec3d = position.vec;
ServerLevel serverWorld = cc.level();
Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, e -> {
Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, EntitySpawnReason.COMMAND, e -> {
e.moveTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot());
return e;
});
@@ -150,9 +150,9 @@ public class Entities
{
return Value.NULL;
}
if (!hasTag && entity instanceof final Mob mob)
if (!hasTag && entity instanceof Mob mob)
{
mob.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null);
mob.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, null);
}
if (!serverWorld.tryAddFreshEntityWithPassengers(entity))
{
@@ -21,7 +21,6 @@ import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -44,6 +43,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.PlacementInfo;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe;
@@ -83,12 +83,12 @@ public class Inventories
Registry<Item> blocks = cc.registry(Registries.ITEM);
if (lv.isEmpty())
{
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of));
return ListValue.wrap(blocks.getTags().map(ValueConversions::of));
}
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
if (lv.size() == 1)
{
return ListValue.wrap(blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())));
return ListValue.wrap(blocks.getTags().filter(e -> e.stream().anyMatch(h -> (h.value() == item))).map(ValueConversions::of));
}
String tag = lv.get(1).getString();
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
@@ -124,22 +124,20 @@ public class Inventories
{
ItemStack result = recipe.getResultItem(regs);
List<Value> ingredientValue = new ArrayList<>();
recipe.getIngredients().forEach(ingredient -> {
// I am flattening ingredient lists per slot.
// consider recipe_data('wooden_sword','crafting') and ('iron_nugget', 'blasting') and notice difference
// in depths of lists.
List<Collection<ItemStack>> stacks = Vanilla.Ingredient_getRecipeStacks(ingredient);
if (stacks.isEmpty())
recipe.placementInfo().slotInfo().forEach(ingredient -> {
if (ingredient.isEmpty())
{
ingredientValue.add(Value.NULL);
return;
}
else
{
List<Value> alternatives = new ArrayList<>();
stacks.forEach(col -> col.stream().map(is -> ValueConversions.of(is, regs)).forEach(alternatives::add));
ingredientValue.add(ListValue.wrap(alternatives));
}
PlacementInfo.SlotInfo value = ingredient.get();
int position = value.placerOutputPosition();
List<Value> alternatives = new ArrayList<>();
value.possibleItems().stream().map(is -> ValueConversions.of(is, regs)).forEach(alternatives::add);
ingredientValue.add(ListValue.wrap(alternatives));
});
Value recipeSpec;
if (recipe instanceof ShapedRecipe shapedRecipe)
{
@@ -39,6 +39,7 @@ import net.minecraft.core.HolderSet;
import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
@@ -50,6 +51,7 @@ import net.minecraft.server.level.Ticket;
import net.minecraft.server.level.TicketType;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.ServerExplosion;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.status.ChunkStatus;
@@ -695,7 +697,7 @@ public class WorldAccess
expression.addContextFunction("update", -1, (c, t, lv) ->
booleanStateTest(c, "update", lv, (s, p) ->
{
((CarpetContext) c).level().neighborChanged(p, s.getBlock(), p);
((CarpetContext) c).level().neighborChanged(p, s.getBlock(), null);
return true;
}));
@@ -1071,10 +1073,9 @@ public class WorldAccess
}
}
LivingEntity theAttacker = attacker;
float thePowah = powah;
// copy of ServerWorld.createExplosion #TRACK#
Explosion explosion = new Explosion(cc.level(), source, null, null, pos.x, pos.y, pos.z, powah, createFire, mode, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE)
ServerExplosion explosion = new ServerExplosion(cc.level(), source, null, null, pos, powah, createFire, mode)
{
@Override
@Nullable
@@ -1085,16 +1086,11 @@ public class WorldAccess
}
};
explosion.explode();
explosion.finalizeExplosion(false);
if (mode == Explosion.BlockInteraction.KEEP)
{
explosion.clearToBlow();
}
Explosion.BlockInteraction finalMode = mode;
ParticleOptions explosionParticle = explosion.isSmall() ? ParticleTypes.EXPLOSION : ParticleTypes.EXPLOSION_EMITTER;
cc.level().players().forEach(spe -> {
if (spe.distanceToSqr(pos) < 4096.0D)
{
spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe), finalMode, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE));
spe.connection.send(new ClientboundExplodePacket(pos, Optional.ofNullable(explosion.getHitPlayers().get(spe)), explosionParticle, SoundEvents.GENERIC_EXPLODE));
}
});
return Value.TRUE;
@@ -1239,13 +1235,13 @@ public class WorldAccess
Registry<Block> blocks = cc.registry(Registries.BLOCK);
if (lv.isEmpty())
{
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of));
return ListValue.wrap(blocks.getTags().map(ValueConversions::of));
}
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
if (blockLocator.offset == lv.size())
{
Block target = blockLocator.block.getBlockState().getBlock();
return ListValue.wrap(blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == target))).map(e -> ValueConversions.of(e.getFirst())));
return ListValue.wrap(blocks.getTags().filter(e -> e.stream().anyMatch(h -> (h.value() == target))).map(ValueConversions::of));
}
String tag = lv.get(blockLocator.offset).getString();
Optional<HolderSet.Named<Block>> tagSet = blocks.getTag(TagKey.create(Registries.BLOCK, InputValidator.identifierOf(tag)));
-6
View File
@@ -7,7 +7,6 @@ import carpet.fakes.BlockStateArgumentInterface;
import carpet.fakes.ChunkTicketManagerInterface;
import carpet.fakes.CommandDispatcherInterface;
import carpet.fakes.EntityInterface;
import carpet.fakes.IngredientInterface;
import carpet.fakes.InventoryBearerInterface;
import carpet.fakes.ItemEntityInterface;
import carpet.fakes.LivingEntityInterface;
@@ -108,11 +107,6 @@ public class Vanilla
return Map.of(); //return ((ThreadedAnvilChunkStorageInterface) chunkMap).regenerateChunkRegion(requestedChunks);
}
public static List<Collection<ItemStack>> Ingredient_getRecipeStacks(Ingredient ingredient)
{
return ((IngredientInterface) (Object) ingredient).getRecipeStacks();
}
public static List<Recipe<?>> RecipeManager_getAllMatching(RecipeManager recipeManager, RecipeType<?> type, ResourceLocation output, RegistryAccess registryAccess)
{
return ((RecipeManagerInterface) recipeManager).getAllMatching(type, output, registryAccess);
@@ -1,13 +1,5 @@
package carpet.script.external;
import carpet.mixins.ShulkerBoxAccessMixin;
import net.minecraft.client.model.ShulkerModel;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
public class VanillaClient
{
public static ShulkerModel<?> ShulkerBoxRenderer_model(BlockEntityRenderer<ShulkerBoxBlockEntity> shulkerBoxRenderer) {
return ((ShulkerBoxAccessMixin)shulkerBoxRenderer).getModel();
}
}
@@ -23,7 +23,7 @@ public class BiomeInfo
{
public static final Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<>()
{{
put("tags", (w, b) -> ListValue.wrap(w.registryAccess().registryOrThrow(Registries.BIOME).getTags().filter(p -> p.getSecond().stream().anyMatch(h -> h.value() == b)).map(p -> p.getFirst().location()).map(ValueConversions::of)));
put("tags", (w, b) -> ListValue.wrap(w.registryAccess().registryOrThrow(Registries.BIOME).getTags().filter(p -> p.stream().anyMatch(h -> h.value() == b)).map(ValueConversions::of)));
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor
@@ -31,7 +31,7 @@ public class BiomeInfo
put("water_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getWaterColor()));
put("water_fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getWaterFogColor()));
put("humidity", (w, b) -> NumericValue.of(Vanilla.Biome_getClimateSettings(b).downfall()));
put("precipitation", (w, b) -> StringValue.of(b.getPrecipitationAt(new BlockPos(0, w.getSeaLevel(), 0)).name().toLowerCase(Locale.ROOT)));
put("precipitation", (w, b) -> StringValue.of(b.getPrecipitationAt(new BlockPos(0, w.getSeaLevel(), 0), w.getSeaLevel()).name().toLowerCase(Locale.ROOT)));
put("features", (w, b) -> {
Registry<ConfiguredFeature<?, ?>> registry = w.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE);
return ListValue.wrap(
@@ -304,8 +304,7 @@ public class FeatureGenerator
return spawnCustomStructure(
new JigsawStructure(new Structure.StructureSettings(
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
new JigsawStructure(new Structure.StructureSettings(l.registryAccess().lookup(Registries.BIOME).orElseThrow().getOrThrow(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
@@ -334,7 +333,7 @@ public class FeatureGenerator
return spawnCustomStructure(
new JigsawStructure(new Structure.StructureSettings(
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
l.registryAccess().lookup(Registries.BIOME).orElseThrow().getOrThrow(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
@@ -363,7 +362,7 @@ public class FeatureGenerator
return spawnCustomStructure(
new JigsawStructure(new Structure.StructureSettings(
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
l.registryAccess().lookup(Registries.BIOME).orElseThrow().getOrThrow(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
@@ -392,7 +391,7 @@ public class FeatureGenerator
return spawnCustomStructure(
new JigsawStructure(new Structure.StructureSettings(
l.registryAccess().registryOrThrow(Registries.BIOME).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
l.registryAccess().lookup(Registries.BIOME).orElseThrow().getOrThrow(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
@@ -2,7 +2,6 @@ package carpet.script.utils;
import carpet.script.CarpetScriptServer;
import carpet.script.external.Carpet;
import carpet.script.external.VanillaClient;
import carpet.script.utils.shapes.ShapeDirection;
import com.mojang.blaze3d.systems.RenderSystem;
@@ -12,7 +11,6 @@ import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat.Mode;
import com.mojang.math.Axis;
@@ -26,34 +24,27 @@ import java.util.function.BiFunction;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.model.ShulkerModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.Mth;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
@@ -160,7 +151,6 @@ public class ShapesRenderer
Matrix4fStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.pushMatrix();
matrixStack.mul(matrices.last().pose());
RenderSystem.applyModelViewMatrix();
// lines
RenderSystem.lineWidth(0.5F);
@@ -180,7 +170,6 @@ public class ShapesRenderer
});
RenderSystem.lineWidth(1.0F);
matrixStack.popMatrix();
RenderSystem.applyModelViewMatrix();
}
if (!labels.isEmpty())
@@ -439,15 +428,8 @@ public class ShapesRenderer
}
}
}
if (BlockEntity instanceof ShulkerBoxBlockEntity sbBlockEntity)
if (BlockEntity != null)
{
sbrender(sbBlockEntity, partialTick,
matrices, immediate, light, OverlayTexture.NO_OVERLAY);
}
else
{
if (BlockEntity != null)
{
BlockEntityRenderer<BlockEntity> blockEntityRenderer = client.getBlockEntityRenderDispatcher().getRenderer(BlockEntity);
if (blockEntityRenderer != null)
{
@@ -455,7 +437,6 @@ public class ShapesRenderer
matrices, immediate, light, OverlayTexture.NO_OVERLAY);
}
}
}
}
else
@@ -480,44 +461,6 @@ public class ShapesRenderer
{
return true;
}
// copy and modifiy a bit from net.minecraft.client.renderer.blockentity.ShulkerBoxRenderer.render
public void sbrender(ShulkerBoxBlockEntity shulkerBoxBlockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j)
{
Direction direction = Direction.UP;
if (shulkerBoxBlockEntity.hasLevel())
{
BlockState blockState = shulkerBoxBlockEntity.getBlockState();
if (blockState.getBlock() instanceof ShulkerBoxBlock)
{
direction = blockState.getValue(ShulkerBoxBlock.FACING);
}
}
DyeColor dyeColor = shulkerBoxBlockEntity.getColor();
Material material;
if (dyeColor == null)
{
material = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
}
else
{
material = Sheets.SHULKER_TEXTURE_LOCATION.get(dyeColor.getId());
}
poseStack.pushPose();
poseStack.translate(0.5, 0.5, 0.5);
poseStack.scale(0.9995F, 0.9995F, 0.9995F);
poseStack.mulPose(direction.getRotation());
poseStack.scale(1.0F, -1.0F, -1.0F);
poseStack.translate(0.0, -1.0, 0.0);
ShulkerModel<?> model = VanillaClient.ShulkerBoxRenderer_model(client.getBlockEntityRenderDispatcher().getRenderer(shulkerBoxBlockEntity));
ModelPart modelPart = model.getLid();
modelPart.setPos(0.0F, 24.0F - shulkerBoxBlockEntity.getProgress(f) * 0.5F * 16.0F, 0.0F);
modelPart.yRot = 270.0F * shulkerBoxBlockEntity.getProgress(f) * (float) (Math.PI / 180.0);
VertexConsumer vertexConsumer = material.buffer(multiBufferSource, RenderType::entityCutoutNoCull);
model.renderToBuffer(poseStack, vertexConsumer, i, j, 0xffffffff);
poseStack.popPose();
}
}
@@ -165,7 +165,7 @@ public class SystemInfo
put("world_gamerules", c -> {
Map<Value, Value> rules = new HashMap<>();
GameRules gameRules = c.level().getGameRules();
GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor()
gameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor()
{
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type)
@@ -25,8 +25,8 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
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;
@@ -457,7 +457,7 @@ public class EntityValue extends Value
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new)));
put("entity_tags", (e, a) -> {
EntityType<?> type = e.getType();
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getTags().filter(entry -> entry.getSecond().stream().anyMatch(h -> h.value() == type)).map(entry -> ValueConversions.of(entry.getFirst())));
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registries.ENTITY_TYPE).getTags().filter(entry -> entry.stream().anyMatch(h -> h.value() == type)).map(entry -> ValueConversions.of(entry)));
});
// deprecated
put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
@@ -1019,7 +1019,7 @@ public class EntityValue extends Value
if (e instanceof ServerPlayer player)
{
int slot = NumericValue.asNumber(v).getInt();
player.connection.send(new ClientboundSetCarriedItemPacket(slot));
player.connection.send(new ClientboundSetHeldSlotPacket(slot));
}
});
@@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.Vec3i;
@@ -189,6 +190,11 @@ public class ValueConversions
return of(tagKey.location());
}
public static Value of(HolderSet.Named<?> tagKey)
{
return of(tagKey.key().location());
}
public static Value of(@Nullable ResourceLocation id)
{
if (id == null) // should be Value.NULL