net.minecraft.util.registry.Registry Java Examples
The following examples show how to use
net.minecraft.util.registry.Registry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FluidRecipeSerializer.java From the-hallow with MIT License | 6 votes |
/** * Attempts to extract a {@link Item} from the given JsonObject. * Assumes we're inside the top level of a result block: * * "result": { * "item": "minecraft:cobblestone", * "count": 2 * } * * If the Item does not exist in {@link Registry#ITEM}, an exception is thrown and {@link Items#AIR} is returned. * * @param itemJson JsonObject to extract Item from * @return Item extracted from Json */ private Item getItem(JsonObject itemJson) { Item result; if(itemJson.get(ITEM_KEY).isJsonPrimitive()) { JsonPrimitive itemPrimitive = itemJson.getAsJsonPrimitive(ITEM_KEY); if(itemPrimitive.isString()) { Identifier itemIdentifier = new Identifier(itemPrimitive.getAsString()); Optional<Item> opt = Registry.ITEM.getOrEmpty(itemIdentifier); if(opt.isPresent()) { result = opt.get(); } else { throw new IllegalArgumentException("Item registry does not contain " + itemIdentifier.toString() + "!" + "\n" + prettyPrintJson(itemJson)); } } else { throw new IllegalArgumentException("Expected JsonPrimitive to be a String, got " + itemPrimitive.getAsString() + "\n" + prettyPrintJson(itemJson)); } } else { throw new InvalidJsonException("\"" + ITEM_KEY + "\" needs to be a String JsonPrimitive, found " + itemJson.getClass() + "!\n" + prettyPrintJson(itemJson)); } return result; }
Example #2
Source File: CarpetEventServer.java From fabric-carpet with MIT License | 6 votes |
@Override public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, DimensionType fromDim, DimensionType dimTo) { // eligibility already checked in mixin Value fromValue = ListValue.fromTriple(from.x, from.y, from.z); Value toValue = (to == null)?Value.NULL:ListValue.fromTriple(to.x, to.y, to.z); Value fromDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(fromDim))); Value toDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(dimTo))); handler.call( () -> Arrays.asList( ((c, t) -> new EntityValue(player)), ((c, t) -> fromValue), ((c, t) -> fromDimStr), ((c, t) -> toValue), ((c, t) -> toDimStr) ), player::getCommandSource); }
Example #3
Source File: Protocol_1_12_2.java From multiconnect with MIT License | 6 votes |
private static void setParticleType(AreaEffectCloudEntity entity, ParticleType<?> type) { IAreaEffectCloudEntity iaece = (IAreaEffectCloudEntity) entity; if (type.getParametersFactory() == ItemStackParticleEffect.PARAMETERS_FACTORY) { Item item = Registry.ITEM.get(iaece.multiconnect_getParam1()); int meta = iaece.multiconnect_getParam2(); ItemStack stack = Items_1_12_2.oldItemStackToNew(new ItemStack(item), meta); entity.setParticleType(createParticle(type, buf -> buf.writeItemStack(stack))); } else if (type.getParametersFactory() == BlockStateParticleEffect.PARAMETERS_FACTORY) { entity.setParticleType(createParticle(type, buf -> buf.writeVarInt(iaece.multiconnect_getParam1()))); } else if (type.getParametersFactory() == DustParticleEffect.PARAMETERS_FACTORY) { entity.setParticleType(createParticle(type, buf -> { buf.writeFloat(1); buf.writeFloat(0); buf.writeFloat(0); buf.writeFloat(1); })); } else { entity.setParticleType(createParticle(type, buf -> {})); } }
Example #4
Source File: PlaySoundCommand.java From multiconnect with MIT License | 6 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { for (String category : new String[] {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}) { dispatcher.register(literal("playsound") .then(argument("sound", identifier()) .suggests((ctx, builder) -> CommandSource.suggestIdentifiers(Registry.SOUND_EVENT.getIds(), builder)) .then(literal(category) .then(argument("player", players()) .executes(ctx -> 0) .then(argument("pos", vec3()) .executes(ctx -> 0) .then(argument("volume", floatArg(0)) .executes(ctx -> 0) .then(argument("pitch", doubleArg(0, 2)) .executes(ctx -> 0) .then(argument("minVolume", doubleArg(0, 1)) .executes(ctx -> 0))))))))); } }
Example #5
Source File: ItemListSetting.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
@Override public void fromJson(JsonElement json) { try { WsonArray wson = JsonUtils.getAsArray(json); itemNames.clear(); wson.getAllStrings().parallelStream() .map(s -> Registry.ITEM.get(new Identifier(s))) .filter(Objects::nonNull) .map(i -> Registry.ITEM.getId(i).toString()).distinct().sorted() .forEachOrdered(s -> itemNames.add(s)); }catch(JsonException e) { e.printStackTrace(); resetToDefaults(); } }
Example #6
Source File: BlockListSetting.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
@Override public void fromJson(JsonElement json) { try { WsonArray wson = JsonUtils.getAsArray(json); blockNames.clear(); wson.getAllStrings().parallelStream() .map(s -> Registry.BLOCK.get(new Identifier(s))) .filter(Objects::nonNull).map(BlockUtils::getName).distinct() .sorted().forEachOrdered(s -> blockNames.add(s)); }catch(JsonException e) { e.printStackTrace(); resetToDefaults(); } }
Example #7
Source File: EnchantCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void enchant(ItemStack stack) { for(Enchantment enchantment : Registry.ENCHANTMENT) { if(enchantment == Enchantments.SILK_TOUCH) continue; if(enchantment.isCursed()) continue; if(enchantment == Enchantments.QUICK_CHARGE) { stack.addEnchantment(enchantment, 5); continue; } stack.addEnchantment(enchantment, 127); } }
Example #8
Source File: ItemGeneratorHack.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
@Override public void onUpdate() { int stacks = speed.getValueI(); for(int i = 9; i < 9 + stacks; i++) { Item item = Registry.ITEM.getRandom(random); ItemStack stack = new ItemStack(item, stackSize.getValueI()); CreativeInventoryActionC2SPacket packet = new CreativeInventoryActionC2SPacket(i, stack); MC.player.networkHandler.sendPacket(packet); } for(int i = 9; i < 9 + stacks; i++) IMC.getInteractionManager().windowClick_THROW(i); }
Example #9
Source File: MixinPotionItems.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
@Override public String getCreatorModId(ItemStack itemStack) { final Item item = itemStack.getItem(); Identifier defaultId = Registry.ITEM.getDefaultId(); Identifier id = Registry.ITEM.getId(item); if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) { return null; } else { final String namespace = id.getNamespace(); if ("minecraft".equals(namespace)) { final Potion potion = PotionUtil.getPotion(itemStack); defaultId = Registry.POTION.getDefaultId(); id = Registry.POTION.getId(potion); if (defaultId.equals(id) && potion != Registry.POTION.get(defaultId)) { return namespace; } return id.getNamespace(); } return namespace; } }
Example #10
Source File: ServerCrasherHack.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
@Override public void onEnable() { if(!MC.player.abilities.creativeMode) { ChatUtils.error("Creative mode only."); setEnabled(false); return; } Item item = Registry.ITEM.get(new Identifier("creeper_spawn_egg")); ItemStack stack = new ItemStack(item, 1); stack.setTag(createNBT()); placeStackInHotbar(stack); setEnabled(false); }
Example #11
Source File: StandardWrenchItem.java From Galacticraft-Rewoven with MIT License | 6 votes |
private void use(PlayerEntity player, BlockState state, WorldAccess iWorld, BlockPos pos, ItemStack stack) { Block block = state.getBlock(); if (block instanceof Rotatable) { StateManager<Block, BlockState> manager = block.getStateManager(); Collection<Property<?>> collection = manager.getProperties(); String string_1 = Registry.BLOCK.getId(block).toString(); if (!collection.isEmpty()) { CompoundTag compoundTag_1 = stack.getOrCreateSubTag("wrenchProp"); String string_2 = compoundTag_1.getString(string_1); Property<?> property = manager.getProperty(string_2); if (property == null) { property = collection.iterator().next(); } if (property.getName().equals("facing")) { BlockState blockState_2 = cycle(state, property, player.isSneaking()); iWorld.setBlockState(pos, blockState_2, 18); stack.damage(2, player, (playerEntity) -> playerEntity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); } } } }
Example #12
Source File: MixinEnchantedBookItem.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
@Override public String getCreatorModId(ItemStack itemStack) { final Item item = itemStack.getItem(); final Identifier defaultId = Registry.ITEM.getDefaultId(); final Identifier id = Registry.ITEM.getId(item); if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) { return null; } else { final String namespace = id.getNamespace(); if ("minecraft".equals(namespace)) { final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack); if (enchantments.size() == 1) { final Identifier enchantmentId = Identifier.tryParse(enchantments.getCompound(0).getString("id")); if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) { return enchantmentId.getNamespace(); } } } return namespace; } }
Example #13
Source File: MoonBiomeLayers.java From Galacticraft-Rewoven with MIT License | 6 votes |
public static boolean areSimilar(int id1, int id2) { if (id1 == id2) { return true; } else { Biome biome = Registry.BIOME.get(id1); Biome biome2 = Registry.BIOME.get(id2); if (biome != null && biome2 != null) { if (biome != Biomes.WOODED_BADLANDS_PLATEAU && biome != Biomes.BADLANDS_PLATEAU) { if (biome.getCategory() != Biome.Category.NONE && biome2.getCategory() != Biome.Category.NONE && biome.getCategory() == biome2.getCategory()) { return true; } else { return biome == biome2; } } else { return biome2 == Biomes.WOODED_BADLANDS_PLATEAU || biome2 == Biomes.BADLANDS_PLATEAU; } } else { return false; } } }
Example #14
Source File: MixinParticleManager.java From multiconnect with MIT License | 5 votes |
@Override public <T extends ParticleEffect> void multiconnect_registerSpriteAwareFactory(ParticleType<T> type, Function<SpriteProvider, ParticleFactory<T>> spriteAwareFactory) { // https://stackoverflow.com/questions/26775676/explicit-use-of-lambdametafactory SpriteProvider spriteProvider; try { spriteProvider = (SpriteProvider) SSP_CTOR.newInstance((ParticleManager) (Object) this); } catch (Throwable e) { throw new AssertionError(e); } Identifier id = Registry.PARTICLE_TYPE.getId(type); spriteAwareFactories.put(id, spriteProvider); customFactories.put(id, spriteAwareFactory.apply(spriteProvider)); }
Example #15
Source File: PatchworkBiomes.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void onInitialize() { Registry.BIOME.forEach(PatchworkBiomes::addRivers); RegistryEntryAddedCallback.event(Registry.BIOME).register((rawid, id, biome) -> { addRivers(biome); updateFailedBiomes(); }); ServerStartCallback.EVENT.register(server -> updateFailedBiomes()); }
Example #16
Source File: CarpetEventServer.java From fabric-carpet with MIT License | 5 votes |
@Override public void onPlayerStatistic(ServerPlayerEntity player, Stat<?> stat, int amount) { Identifier id = getStatId(stat); if (skippedStats.contains(id)) return; handler.call( () -> Arrays.asList( ((c, t) -> new EntityValue(player)), ((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STAT_TYPE.getId(stat.getType())))), ((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(id))), ((c, t) -> new NumericValue(amount)) ), player::getCommandSource); }
Example #17
Source File: CarpetProfiler.java From fabric-carpet with MIT License | 5 votes |
private static String getTEntityString(World world, BlockEntity be) { return String.format("%s.%s%s", world.getDimension().getType().toString().replaceFirst("minecraft:", ""), Registry.BLOCK_ENTITY_TYPE.getId(be.getType()).toString().replaceFirst("minecraft:", ""), world.isClient ? " (Client)" : ""); }
Example #18
Source File: EditItemListScreen.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public void tick() { itemNameField.tick(); itemToAdd = Registry.ITEM.get(getItemIDFromField()); addButton.active = itemToAdd != null; removeButton.active = listGui.selected >= 0 && listGui.selected < listGui.list.size(); }
Example #19
Source File: ParticleArgumentType_1_12_2.java From multiconnect with MIT License | 5 votes |
@Override public ParticleType<?> parse(StringReader reader) throws CommandSyntaxException { int start = reader.getCursor(); Identifier id = Identifier.fromCommandInput(reader); if (!Registry.PARTICLE_TYPE.containsId(id)) { reader.setCursor(start); throw ParticleArgumentType.UNKNOWN_PARTICLE_EXCEPTION.createWithContext(reader, id); } return Registry.PARTICLE_TYPE.get(id); }
Example #20
Source File: BlockStateArgumentType_1_12_2.java From multiconnect with MIT License | 5 votes |
@Override public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { int spaceIndex = builder.getRemaining().indexOf(' '); if (spaceIndex == -1) { CommandSource.suggestIdentifiers(Registry.BLOCK.getIds().stream().filter(id -> isValidBlock(Registry.BLOCK.get(id))), builder); return builder.buildFuture(); } Identifier blockId = Identifier.tryParse(builder.getInput().substring(builder.getStart(), builder.getStart() + spaceIndex)); String propertiesStr = builder.getInput().substring(builder.getStart() + spaceIndex + 1); int commaIndex = propertiesStr.lastIndexOf(','); int equalsIndex = propertiesStr.lastIndexOf('='); builder = builder.createOffset(builder.getStart() + spaceIndex + commaIndex + 2); if (commaIndex == -1 && equalsIndex == -1) { CommandSource.suggestMatching(new String[] {"default"}, builder); if (test) CommandSource.suggestMatching(new String[] {"*"}, builder); } if (blockId == null || !BlockStateReverseFlattening.OLD_PROPERTIES.containsKey(blockId)) return builder.buildFuture(); if (equalsIndex <= commaIndex) { CommandSource.suggestMatching(BlockStateReverseFlattening.OLD_PROPERTIES.get(blockId).stream().map(str -> str + "="), builder); } else { String property = builder.getInput().substring(builder.getStart(), builder.getStart() + equalsIndex - commaIndex - 1); List<String> values = BlockStateReverseFlattening.OLD_PROPERTY_VALUES.get(Pair.of(blockId, property)); builder = builder.createOffset(builder.getStart() + equalsIndex - commaIndex); CommandSource.suggestMatching(values, builder); } return builder.buildFuture(); }
Example #21
Source File: MobAI.java From fabric-carpet with MIT License | 5 votes |
public static List<String> availbleTypes() { Set<EntityType> types = new HashSet<>(); for (TrackingType type: TrackingType.values()) { types.addAll(type.types); } return types.stream().map(t -> Registry.ENTITY_TYPE.getId(t).getPath()).collect(Collectors.toList()); }
Example #22
Source File: AbstractProtocol.java From multiconnect with MIT License | 5 votes |
@SuppressWarnings("unchecked") protected <T> void postMutateRegistry(Registry<T> registry) { if (!(registry instanceof SimpleRegistry)) return; if (registry instanceof DefaultedRegistry) return; ISimpleRegistry<T> iregistry = (ISimpleRegistry<T>) registry; DefaultRegistry<T> defaultRegistry = (DefaultRegistry<T>) DefaultRegistry.DEFAULT_REGISTRIES.get(registry); if (defaultRegistry == null) return; for (Map.Entry<Identifier, T> entry : defaultRegistry.defaultEntriesById.entrySet()) { if (registry.getId(entry.getValue()) == null) { RegistryKey<T> key = RegistryKey.of(iregistry.getRegistryKey(), entry.getKey()); iregistry.register(entry.getValue(), iregistry.getNextId(), key, false); } } }
Example #23
Source File: CmdEnchant.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public void enchant(ItemStack item, Enchantment e, int level) { if (item.getTag() == null) item.setTag(new CompoundNBT()); if (!item.getTag().contains("Enchantments", 9)) { item.getTag().put("Enchantments", new ListNBT()); } ListNBT listnbt = item.getTag().getList("Enchantments", 10); CompoundNBT compoundnbt = new CompoundNBT(); compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getKey(e))); compoundnbt.putInt("lvl", level); listnbt.add(compoundnbt); }
Example #24
Source File: Protocol_1_14_4.java From multiconnect with MIT License | 5 votes |
@Override public void mutateRegistries(RegistryMutator mutator) { super.mutateRegistries(mutator); mutator.mutate(Protocols.V1_14_4, Registry.BLOCK, this::mutateBlockRegistry); mutator.mutate(Protocols.V1_14_4, Registry.ITEM, this::mutateItemRegistry); mutator.mutate(Protocols.V1_14_4, Registry.ENTITY_TYPE, this::mutateEntityTypeRegistry); mutator.mutate(Protocols.V1_14_4, Registry.SOUND_EVENT, this::mutateSoundEventRegistry); mutator.mutate(Protocols.V1_14_4, Registry.BLOCK_ENTITY_TYPE, this::mutateBlockEntityTypeRegistry); mutator.mutate(Protocols.V1_14_4, Registry.PARTICLE_TYPE, this::mutateParticleTypeRegistry); }
Example #25
Source File: RecipeManager_scarpetMixin.java From fabric-carpet with MIT License | 5 votes |
@Override public List<Recipe<?>> getAllMatching(RecipeType type, Identifier output) { Map<Identifier, Recipe<?>> typeRecipes = recipes.get(type); if (typeRecipes.containsKey(output)) return Collections.singletonList(typeRecipes.get(output)); return Lists.newArrayList(typeRecipes.values().stream().filter( r -> Registry.ITEM.getId(r.getOutput().getItem()).equals(output)).collect(Collectors.toList())); }
Example #26
Source File: ForgeRegistry.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void register(V value) { Objects.requireNonNull(value, "value must not be null"); Identifier identifier = value.getRegistryName(); Optional<V> potentialOldValue = vanilla.getOrEmpty(identifier); potentialOldValue.ifPresent( oldValue -> { if (oldValue == value) { LOGGER.warn(REGISTRIES, "Registry {}: The object {} has been registered twice for the same name {}.", this.superType.getSimpleName(), value, identifier); return; } else { throw new IllegalArgumentException(String.format("The name %s has been registered twice, for %s and %s.", identifier, oldValue, value)); } } ); Identifier oldIdentifier = vanilla.getId(value); if (oldIdentifier != getDefaultKey()) { throw new IllegalArgumentException(String.format("The object %s{%x} has been registered twice, using the names %s and %s.", value, System.identityHashCode(value), oldIdentifier, identifier)); } Registry.register(vanilla, identifier, value); }
Example #27
Source File: BiomeDictionary.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
/** * Ensure that at least one type has been added to the given {@link Biome}. */ private static void ensureHasTypes(Biome biome) { if (!hasAnyType(biome)) { makeBestGuess(biome); LOGGER.warn("No types have been added to Biome {}, types have been assigned on a best-effort guess: {}", Registry.BIOME.getId(biome), getTypes(biome)); } }
Example #28
Source File: CmdEnchant.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public void enchant(ItemStack item, Enchantment e, int level) { if (item.getTag() == null) item.setTag(new CompoundTag()); if (!item.getTag().contains("Enchantments", 9)) { item.getTag().put("Enchantments", new ListTag()); } ListTag listnbt = item.getTag().getList("Enchantments", 10); CompoundTag compoundnbt = new CompoundTag(); compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getId(e))); compoundnbt.putInt("lvl", level); listnbt.add(compoundnbt); }
Example #29
Source File: Xray.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@Override public void onEnable() { visibleBlocks.clear(); for (String s: BleachFileMang.readFileLines("xrayblocks.txt")) { setVisible(Registry.BLOCK.get(new Identifier(s))); } mc.worldRenderer.reload(); super.onEnable(); }
Example #30
Source File: MixinFluidRenderer.java From Sandbox with GNU Lesser General Public License v3.0 | 5 votes |
@Inject(at = @At("RETURN"), method = "onResourceReload") public void reload(CallbackInfo info) { SpriteAtlasTexture spriteAtlasTexture_1 = (SpriteAtlasTexture) MinecraftClient.getInstance().getTextureManager().getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); spriteMap.clear(); Registry.FLUID.forEach(fluid -> { if (fluid instanceof FluidWrapper) { Sprite[] sprites = new Sprite[2]; sprites[0] = spriteAtlasTexture_1.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(false))); sprites[1] = spriteAtlasTexture_1.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(true))); spriteMap.put(((FluidWrapper) fluid).fluid, sprites); } }); }