use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class BlockStatePropertiesGenerator method computeUsedProperties.
private Map<PropertyType, Map<Property<?>, Set<ResourceLocation>>> computeUsedProperties() {
// get all block state properties
final Map<PropertyType, Map<Property<?>, Set<ResourceLocation>>> propertyUsages = new HashMap<>();
for (final Block block : Registry.BLOCK) {
for (final Property<?> property : block.defaultBlockState().getProperties()) {
final var type = PropertyType.ofProperty(property);
if (type == null) {
Logger.warn("Unknown property type for state property {} in block {}", property, Registry.BLOCK.getKey(block));
}
propertyUsages.computeIfAbsent(type, $ -> new IdentityHashMap<>()).computeIfAbsent(property, $ -> new HashSet<>()).add(Registry.BLOCK.getKey(block));
}
}
return propertyUsages;
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeEntityArchetype method apply.
@Override
public Optional<org.spongepowered.api.entity.Entity> apply(final ServerLocation location) {
if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
return Optional.empty();
}
final org.spongepowered.api.world.server.ServerWorld spongeWorld = location.world();
final ServerLevel level = (ServerLevel) spongeWorld;
final ResourceLocation key = net.minecraft.world.entity.EntityType.getKey((net.minecraft.world.entity.EntityType<?>) this.type);
if (key == null) {
return Optional.empty();
}
final CompoundTag compound = this.compound.copy();
compound.putString(Constants.Entity.ENTITY_TYPE_ID, key.toString());
final ListTag pos = new ListTag();
pos.add(DoubleTag.valueOf(location.x()));
pos.add(DoubleTag.valueOf(location.y()));
pos.add(DoubleTag.valueOf(location.z()));
compound.put(Constants.Entity.ENTITY_POSITION, pos);
compound.remove(Constants.Entity.ENTITY_UUID);
final boolean requiresInitialSpawn;
if (compound.contains(Constants.Sponge.EntityArchetype.REQUIRES_EXTRA_INITIAL_SPAWN)) {
requiresInitialSpawn = compound.getBoolean(Constants.Sponge.EntityArchetype.REQUIRES_EXTRA_INITIAL_SPAWN);
compound.remove(Constants.Sponge.EntityArchetype.REQUIRES_EXTRA_INITIAL_SPAWN);
} else {
requiresInitialSpawn = true;
}
@Nullable final Entity entity = net.minecraft.world.entity.EntityType.loadEntityRecursive(compound, level, e -> {
e.moveTo(location.x(), location.y(), location.z());
if (requiresInitialSpawn && e instanceof Mob) {
((Mob) e).finalizeSpawn(level, level.getCurrentDifficultyAt(e.blockPosition()), MobSpawnType.COMMAND, null, compound);
}
return e;
});
if (entity == null) {
return Optional.empty();
}
if (level.tryAddFreshEntityWithPassengers(entity)) {
return Optional.of((org.spongepowered.api.entity.Entity) entity);
}
return Optional.empty();
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeResourceKeyBuilder method build.
@Override
public ResourceKey build() throws IllegalStateException {
checkState(this.namespace != null, "Namespace cannot be empty");
checkState(this.value != null, "Value cannot be empty");
try {
final ResourceLocation resourceLocation = new ResourceLocation(this.namespace, this.value);
return (ResourceKey) (Object) resourceLocation;
} catch (ResourceLocationException e) {
throw new IllegalStateException(e);
}
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeFluidStateBuilder method readFluid.
private Fluid readFluid(final StringReader reader) throws CommandSyntaxException {
final int cursor = reader.getCursor();
final ResourceLocation fluidKey = ResourceLocation.read(reader);
return Registry.FLUID.getOptional(fluidKey).orElseThrow(() -> {
reader.setCursor(cursor);
return BlockStateParser.ERROR_UNKNOWN_BLOCK.createWithContext(reader, fluidKey.toString());
});
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeStonecuttingRecipeSerializer method fromJson.
@SuppressWarnings("unchecked")
@Override
public R fromJson(ResourceLocation recipeId, JsonObject json) {
final String group = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
final Ingredient ingredient = IngredientUtil.spongeDeserialize(json.get(Constants.Recipe.STONECUTTING_INGREDIENT));
final Function<Container, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
if (spongeStack != null) {
return (R) new SpongeStonecuttingRecipe(recipeId, group, ingredient, spongeStack, resultFunction);
}
final String type = GsonHelper.getAsString(json, Constants.Recipe.RESULT);
final int count = GsonHelper.getAsInt(json, Constants.Recipe.COUNT);
final ItemStack itemstack = new ItemStack(Registry.ITEM.get(new ResourceLocation(type)), count);
return (R) new SpongeStonecuttingRecipe(recipeId, group, ingredient, itemstack, resultFunction);
}
Aggregations