net.minecraft.util.registry.Registry源码实例Demo

类net.minecraft.util.registry.Registry源码实例Demo

下面列出了net.minecraft.util.registry.Registry 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Galacticraft-Rewoven   文件: MoonBiomeLayers.java
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;
        }
    }
}
 
源代码2 项目: fabric-carpet   文件: CarpetEventServer.java
@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);
}
 
源代码3 项目: patchwork-api   文件: MixinPotionItems.java
@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;
	}
}
 
源代码4 项目: Galacticraft-Rewoven   文件: StandardWrenchItem.java
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));
            }
        }
    }
}
 
源代码5 项目: the-hallow   文件: FluidRecipeSerializer.java
/**
 * 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;
}
 
源代码6 项目: patchwork-api   文件: MixinEnchantedBookItem.java
@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;
	}
}
 
源代码7 项目: Wurst7   文件: ItemGeneratorHack.java
@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);
}
 
源代码8 项目: Wurst7   文件: ServerCrasherHack.java
@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);
}
 
源代码9 项目: Wurst7   文件: EnchantCmd.java
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);
	}
}
 
源代码10 项目: Wurst7   文件: BlockListSetting.java
@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();
	}
}
 
源代码11 项目: Wurst7   文件: ItemListSetting.java
@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();
	}
}
 
源代码12 项目: multiconnect   文件: Protocol_1_12_2.java
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 -> {}));
    }
}
 
源代码13 项目: multiconnect   文件: PlaySoundCommand.java
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)))))))));
    }
}
 
源代码14 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
@Override
public Collection<Identifier> getValues() {
    if (VALUES.isEmpty()) {
        for (Fluid f : Registry.FLUID) {
            VALUES.add(Registry.FLUID.getId(f));
        }
        VALUES.add(new Identifier("empty"));
    }
    return VALUES;
}
 
源代码15 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
@Override
default boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
    if (state.get(FLUID).equals(new Identifier("empty"))) {
        if (!world.isClient()) {
            world.setBlockState(pos, state.with(FLUID, Registry.FLUID.getId(fluidState.getFluid()))
                    .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1)), 3);
            world.getFluidTickScheduler().schedule(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world));
        }
        return true;
    } else {
        return false;
    }
}
 
源代码16 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
@Override
default Fluid tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) {
    if (!state.get(FLUID).equals(new Identifier("empty"))) {
        world.setBlockState(pos, state.with(FLUID, new Identifier("empty")), 3);
        if (Registry.FLUID.get(state.get(FLUID)).getDefaultState().isStill()) {
            return Registry.FLUID.get(state.get(FLUID));
        }
    }
    return Fluids.EMPTY;
}
 
源代码17 项目: Galacticraft-Rewoven   文件: GratingBlock.java
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
    FluidState fluidState = context.getWorld().getFluidState(context.getBlockPos());
    BlockState blockState = this.getDefaultState().with(GRATING_STATE, GratingState.LOWER)
            .with(FLUID, Registry.FLUID.getId(fluidState.getFluid()))
            .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1));
    BlockPos blockPos = context.getBlockPos();
    Direction direction = context.getPlayerFacing();

    return direction != Direction.DOWN && (direction == Direction.UP || context.getBlockPos().getY() - (double) blockPos.getY() <= 0.5D) ? blockState : blockState.with(GRATING_STATE, GratingState.UPPER);
}
 
源代码18 项目: Galacticraft-Rewoven   文件: Walkway.java
@Override
public FluidState getFluidState(BlockState state) {
    FluidState state1 = Registry.FLUID.get(state.get(FLUID)).getDefaultState();
    if (state1.getEntries().containsKey(FlowableFluid.LEVEL)) {
        state1 = state1.with(FlowableFluid.LEVEL, state.get(FlowableFluid.LEVEL));
    }
    return state1;
}
 
源代码19 项目: patchwork-api   文件: ForgeRegistries.java
@SuppressWarnings("unchecked")
private static <T> IForgeRegistry wrap(String name, Class superClazz) {
	Identifier identifier = new Identifier("minecraft", name);
	Registry registry = Registry.REGISTRIES.get(identifier);

	ForgeRegistry wrapped = new ForgeRegistry(identifier, registry, superClazz);

	RegistryClassMapping.register(wrapped);
	RegistryManager.ACTIVE.addRegistry(identifier, wrapped);
	RegistryEventDispatcher.register(wrapped);

	return wrapped;
}
 
源代码20 项目: Galacticraft-Rewoven   文件: GalacticraftRecipes.java
private static <T extends Recipe<?>> RecipeType<T> registerType(String id) {
    return Registry.register(Registry.RECIPE_TYPE, new Identifier(Constants.MOD_ID, id), new RecipeType<T>() {
        public String toString() {
            return id;
        }
    });
}
 
static ItemStack getStack(JsonObject json) {
    String itemId = JsonHelper.getString(json, "item");
    Item ingredientItem = Registry.ITEM.getOrEmpty(new Identifier(itemId)).orElseThrow(() -> new JsonSyntaxException("Unknown item '" + itemId + "'"));
    if (json.has("data")) {
        throw new JsonParseException("Disallowed data tag found");
    } else {
        int count = JsonHelper.getInt(json, "count", 1);
        return new ItemStack(ingredientItem, count);
    }
}
 
@Override
public T read(Identifier id, JsonObject json) {
    String group = JsonHelper.getString(json, "group", "");
    Ingredient inputIngredient;
    if (JsonHelper.hasArray(json, "ingredient")) {
        inputIngredient = Ingredient.fromJson(JsonHelper.getArray(json, "ingredient"));
    } else {
        inputIngredient = Ingredient.fromJson(JsonHelper.getObject(json, "ingredient"));
    }

    String result = JsonHelper.getString(json, "result");
    int count = JsonHelper.getInt(json, "count");
    ItemStack outputItem = new ItemStack(Registry.ITEM.get(new Identifier(result)), count);
    return this.recipeFactory.create(id, group, inputIngredient, outputItem);
}
 
源代码23 项目: fabric-carpet   文件: CarpetProfiler.java
private static String getEntityString(World world, Entity e)
{
    return String.format("%s.%s%s",
            world.getDimension().getType().toString().replaceFirst("minecraft:", ""),
            Registry.ENTITY_TYPE.getId(e.getType()).toString().replaceFirst("minecraft:", ""),
            world.isClient ? " (Client)" : "");
}
 
源代码24 项目: Galacticraft-Rewoven   文件: ItemStackMixin.java
@SuppressWarnings("RedundantSuppression")
@Inject(method = "getName", at = @At("RETURN"), cancellable = true)
private void getName(CallbackInfoReturnable<Text> returnable) {
    Identifier id = Registry.ITEM.getId(getItem());
    //noinspection ConstantConditions,PointlessBooleanExpression
    if (false && id.getNamespace().equals(Constants.MOD_ID)) {
        Text returnVal = returnable.getReturnValue();
        if (returnVal.getStyle().getColor() == null) {
            returnable.setReturnValue(returnVal.shallowCopy().setStyle(returnVal.getStyle().withColor(Formatting.BLUE)));
        }
    }
}
 
源代码25 项目: the-hallow   文件: InfusionAltarBlockEntity.java
@Override
public CompoundTag toTag(CompoundTag entityTag) {
	super.toTag(entityTag);
	if (!storedStack.isEmpty()) {
		entityTag.putString("stored_item", Registry.ITEM.getId(storedStack.getItem()).toString());
	}
	return entityTag;
}
 
源代码26 项目: the-hallow   文件: InfusionPillarBlockEntity.java
@Override
public CompoundTag toTag(CompoundTag entityTag) {
	super.toTag(entityTag);
	if (!storedStack.isEmpty()) {
		entityTag.putString("stored_item", Registry.ITEM.getId(storedStack.getItem()).toString());
	}
	return entityTag;
}
 
源代码27 项目: the-hallow   文件: InfusionPillarBlockEntity.java
@Override
public void fromTag(CompoundTag entityTag) {
	super.fromTag(entityTag);
	if (entityTag.contains("stored_item")) {
		this.storedStack = new ItemStack(Registry.ITEM.getOrEmpty(new Identifier(entityTag.getString("stored_item"))).get());
	}
}
 
源代码28 项目: bleachhack-1.14   文件: Xray.java
@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();
}
 
源代码29 项目: patchwork-api   文件: BiomeDictionary.java
/**
 * 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));
	}
}
 
源代码30 项目: fabric-carpet   文件: RecipeManager_scarpetMixin.java
@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()));
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法