refactor limit access to built-in registries
This commit is contained in:
1 parent
8dd08d5cb1
commit
bd5dfdbf9f
25 files changed
+243
-176
No files matched your search
@@ -11,6 +11,7 @@ import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.commands.arguments.item.ItemInput;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
@@ -31,6 +32,7 @@ import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
|
||||
import net.minecraft.world.entity.ai.memory.WalkTarget;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
@@ -80,6 +82,7 @@ public class ValueConversions
|
||||
|
||||
public static <T extends Number> Value of(MinMaxBounds<T> range) { return ListValue.of(NumericValue.of(range.getMin()), NumericValue.of(range.getMax()));}
|
||||
|
||||
@Deprecated
|
||||
public static Value of(ItemStack stack)
|
||||
{
|
||||
if (stack == null || stack.isEmpty())
|
||||
@@ -90,6 +93,15 @@ public class ValueConversions
|
||||
NBTSerializableValue.fromStack(stack)
|
||||
);
|
||||
}
|
||||
public static Value of(ItemStack stack, RegistryAccess regs) {
|
||||
if (stack == null || stack.isEmpty())
|
||||
return Value.NULL;
|
||||
return ListValue.of(
|
||||
of(regs.registryOrThrow(Registries.ITEM).getKey(stack.getItem())),
|
||||
new NumericValue(stack.getCount()),
|
||||
NBTSerializableValue.fromStack(stack)
|
||||
);
|
||||
}
|
||||
|
||||
public static Value of(Objective objective)
|
||||
{
|
||||
@@ -318,7 +330,7 @@ public class ValueConversions
|
||||
);
|
||||
}
|
||||
|
||||
public static Value of(StructureStart structure)
|
||||
public static Value of(StructureStart structure, final RegistryAccess regs)
|
||||
{
|
||||
if (structure == null || structure == StructureStart.INVALID_START) return Value.NULL;
|
||||
BoundingBox boundingBox = structure.getBoundingBox();
|
||||
@@ -332,7 +344,7 @@ public class ValueConversions
|
||||
if (box.maxX() >= box.minX() && box.maxY() >= box.minY() && box.maxZ() >= box.minZ())
|
||||
{
|
||||
pieces.add(ListValue.of(
|
||||
new StringValue(NBTSerializableValue.nameFromRegistryId(BuiltInRegistries.STRUCTURE_PIECE.getKey(piece.getType()))),
|
||||
new StringValue(NBTSerializableValue.nameFromRegistryId(regs.registryOrThrow(Registries.STRUCTURE_PIECE).getKey(piece.getType()))),
|
||||
(piece.getOrientation() == null) ? Value.NULL : new StringValue(piece.getOrientation().getName()),
|
||||
ListValue.fromTriple(box.minX(), box.minY(), box.minZ()),
|
||||
ListValue.fromTriple(box.maxX(), box.maxY(), box.maxZ())
|
||||
@@ -406,9 +418,10 @@ public class ValueConversions
|
||||
public static Value ofBlockPredicate(RegistryAccess registryAccess, Predicate<BlockInWorld> blockPredicate)
|
||||
{
|
||||
BlockPredicateInterface predicateData = (BlockPredicateInterface) blockPredicate;
|
||||
final Registry<Block> blocks = registryAccess.registryOrThrow(Registries.BLOCK);
|
||||
return ListValue.of(
|
||||
predicateData.getCMBlockState()==null?Value.NULL:of(BuiltInRegistries.BLOCK.getKey(predicateData.getCMBlockState().getBlock())),
|
||||
predicateData.getCMBlockTagKey()==null?Value.NULL:of(registryAccess.registryOrThrow(Registries.BLOCK).getTag(predicateData.getCMBlockTagKey()).get().key()),
|
||||
predicateData.getCMBlockState()==null?Value.NULL:of(blocks.getKey(predicateData.getCMBlockState().getBlock())),
|
||||
predicateData.getCMBlockTagKey()==null?Value.NULL:of(blocks.getTag(predicateData.getCMBlockTagKey()).get().key()),
|
||||
MapValue.wrap(predicateData.getCMProperties()),
|
||||
predicateData.getCMDataTag() == null?Value.NULL:new NBTSerializableValue(predicateData.getCMDataTag())
|
||||
);
|
||||
@@ -481,7 +494,7 @@ public class ValueConversions
|
||||
if (o instanceof BoundingBox)
|
||||
return of((BoundingBox) o);
|
||||
if (o instanceof ItemStack)
|
||||
return of((ItemStack)o);
|
||||
return of((ItemStack)o, serverWorld.registryAccess());
|
||||
if (o instanceof Boolean)
|
||||
return BooleanValue.of((Boolean) o);
|
||||
if (o instanceof Number)
|
||||
|
||||
Reference in new issue
Block a user