Java源码示例:net.minecraft.util.registry.Registry
示例1
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
@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
@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
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
/**
* 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
@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
@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
@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
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
@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
@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
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
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
@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
@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
@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
@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
@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
@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
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;
}
});
}
示例21
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);
}
}
示例22
@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
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
@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
@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
@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
@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
@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
/**
* 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
@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()));
}