com.mojang.serialization.Dynamic Java Examples
The following examples show how to use
com.mojang.serialization.Dynamic.
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: DataFix.java From DataFixerUpper with MIT License | 6 votes |
protected <A, B> TypeRewriteRule writeFixAndRead(final String name, final Type<A> type, final Type<B> newType, final Function<Dynamic<?>, Dynamic<?>> fix) { return fixTypeEverywhere(name, type, newType, ops -> input -> { final Optional<? extends Dynamic<?>> written = type.writeDynamic(ops, input).resultOrPartial(LOGGER::error); if (!written.isPresent()) { throw new RuntimeException("Could not write the object in " + name); } final Optional<? extends Pair<Typed<B>, ?>> read = newType.readTyped(fix.apply(written.get())).resultOrPartial(LOGGER::error); if (!read.isPresent()) { throw new RuntimeException("Could not read the new object in " + name); } return read.get().getFirst().getValue(); }); }
Example #2
Source File: BlockStateReverseFlattening.java From multiconnect with MIT License | 5 votes |
public static String reverseLookupStateBlock(int stateId) { if (stateId < 0 || stateId >= IDS_TO_OLD_STATES.length) return "minecraft:air"; Dynamic<?> val = IDS_TO_OLD_STATES[stateId]; if (val == null) return "minecraft:air"; return val.get("Name").asString(""); }
Example #3
Source File: MixinBlockStateFlattening.java From multiconnect with MIT License | 5 votes |
@Inject(method = "putStates", at = @At("RETURN")) private static void onPutStates(int id, String newState, String[] oldStates, CallbackInfo ci) { Dynamic<?> oldState = BlockStateFlattening.parseState(oldStates.length == 0 ? newState : oldStates[0]); BlockStateReverseFlattening.IDS_TO_OLD_STATES[id] = oldState; for (String old : oldStates) { handleOldState(old); } }
Example #4
Source File: MixinBlockStateFlattening.java From multiconnect with MIT License | 5 votes |
@Unique private static void handleOldState(String old) { Dynamic<?> oldState = BlockStateFlattening.parseState(old); Identifier id = new Identifier(oldState.get("Name").asString("")); Map<String, String> properties = oldState.get("Properties").asMap(k -> k.asString(""), v -> v.asString("")); BlockStateReverseFlattening.OLD_PROPERTIES.computeIfAbsent(id, k -> properties.keySet().stream().sorted().collect(Collectors.toList())); properties.forEach((name, value) -> { List<String> values = BlockStateReverseFlattening.OLD_PROPERTY_VALUES.computeIfAbsent(Pair.of(id, name), k -> new ArrayList<>()); if (!values.contains(value)) values.add(value); }); }
Example #5
Source File: BlockStateReverseFlattening.java From multiconnect with MIT License | 5 votes |
public static Dynamic<?> reverseLookupState(int stateId) { if (stateId < 0 || stateId >= IDS_TO_OLD_STATES.length) return IDS_TO_OLD_STATES[0]; Dynamic<?> ret = IDS_TO_OLD_STATES[stateId]; if (ret == null) return IDS_TO_OLD_STATES[0]; return ret; }
Example #6
Source File: DataFixerUpper.java From DataFixerUpper with MIT License | 5 votes |
@Override public <T> Dynamic<T> update(final DSL.TypeReference type, final Dynamic<T> input, final int version, final int newVersion) { if (version < newVersion) { final Type<?> dataType = getType(type, version); final DataResult<T> read = dataType.readAndWrite(input.getOps(), getType(type, newVersion), getRule(version, newVersion), OPTIMIZATION_RULE, input.getValue()); final T result = read.resultOrPartial(LOGGER::error).orElse(input.getValue()); return new Dynamic<>(input.getOps(), result); } return input; }
Example #7
Source File: DataConverters_1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 4 votes |
public static NBTTagCompound convert(TypeReference type, NBTTagCompound cmp, int sourceVer, int targetVer) { if (sourceVer >= targetVer) { return cmp; } return (NBTTagCompound) INSTANCE.fixer.update(type, new Dynamic<>(OPS_NBT, cmp), sourceVer, targetVer).getValue(); }
Example #8
Source File: DataConverters_1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 4 votes |
private static String fixName(String key, int srcVer, TypeReference type) { return INSTANCE.fixer.update(type, new Dynamic<>(OPS_NBT, NBTTagString.a(key)), srcVer, DATA_VERSION) .getValue().asString(); }
Example #9
Source File: DataConverters_1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 4 votes |
private String fixBlockState(String blockState, int srcVer) { NBTTagCompound stateNBT = stateToNBT(blockState); Dynamic<NBTBase> dynamic = new Dynamic<>(OPS_NBT, stateNBT); NBTTagCompound fixed = (NBTTagCompound) INSTANCE.fixer.update(DataConverterTypes.BLOCK_STATE, dynamic, srcVer, DATA_VERSION).getValue(); return nbtToState(fixed); }
Example #10
Source File: DSL.java From DataFixerUpper with MIT License | 4 votes |
static OpticFinder<Dynamic<?>> remainderFinder() { return Instances.REMAINDER_FINDER; }
Example #11
Source File: DSL.java From DataFixerUpper with MIT License | 4 votes |
static Type<Dynamic<?>> remainderType() { return Instances.EMPTY_PASSTHROUGH; }
Example #12
Source File: Type.java From DataFixerUpper with MIT License | 4 votes |
public <T> DataResult<Pair<Typed<A>, T>> readTyped(final Dynamic<T> input) { return readTyped(input.getOps(), input.getValue()); }
Example #13
Source File: Type.java From DataFixerUpper with MIT License | 4 votes |
public final <T> DataResult<Dynamic<T>> writeDynamic(final DynamicOps<T> ops, final A value) { return write(ops, value).map(result -> new Dynamic<>(ops, result)); }
Example #14
Source File: Type.java From DataFixerUpper with MIT License | 4 votes |
public final <T> DataResult<Pair<A, Dynamic<T>>> read(final Dynamic<T> input) { return codec().decode(input.getOps(), input.getValue()).map(v -> v.mapSecond(t -> new Dynamic<>(input.getOps(), t))); }
Example #15
Source File: EmptyPartPassthrough.java From DataFixerUpper with MIT License | 4 votes |
@Override public Codec<Dynamic<?>> buildCodec() { return Codec.PASSTHROUGH; }
Example #16
Source File: EmptyPartPassthrough.java From DataFixerUpper with MIT License | 4 votes |
@Override public Optional<Dynamic<?>> point(final DynamicOps<?> ops) { return Optional.of(new Dynamic<>(ops)); }
Example #17
Source File: Typed.java From DataFixerUpper with MIT License | 4 votes |
public DataResult<? extends Dynamic<?>> write() { return type.writeDynamic(ops, value); }
Example #18
Source File: DataFixer.java From DataFixerUpper with MIT License | votes |
<T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion);