use of net.minecraft.nbt.IntNBT in project Mekanism by mekanism.
the class CCArgumentWrapperTest method testInvalidHintNumber.
@Test
@DisplayName("Test hint mismatch expected type using numbers as actual")
void testInvalidHintNumber() {
IntNBT nbt = IntNBT.valueOf(100);
Object withHint = addInvalidHint(nbt, Constants.NBT.TAG_COMPOUND);
Assertions.assertNotEquals(nbt, CCArgumentWrapperTestHelper.sanitize(nbt.getClass(), withHint));
}
use of net.minecraft.nbt.IntNBT in project minecolonies by ldtteam.
the class StandardRequestFactories method serializeToNBT.
public static <T extends IRequestable> CompoundNBT serializeToNBT(final IFactoryController controller, final IRequest<T> request, final IObjectToNBTConverter<T> typeSerialization) {
final CompoundNBT compound = new CompoundNBT();
final CompoundNBT requesterCompound = controller.serialize(request.getRequester());
final CompoundNBT tokenCompound = controller.serialize(request.getId());
final IntNBT stateCompound = request.getState().serialize();
final CompoundNBT requestedCompound = typeSerialization.apply(controller, request.getRequest());
final ListNBT childrenCompound = new ListNBT();
for (final IToken<?> token : request.getChildren()) {
childrenCompound.add(controller.serialize(token));
}
compound.put(NBT_REQUESTER, requesterCompound);
compound.put(NBT_TOKEN, tokenCompound);
compound.put(NBT_STATE, stateCompound);
compound.put(NBT_REQUESTED, requestedCompound);
if (request.hasResult()) {
compound.put(NBT_RESULT, typeSerialization.apply(controller, request.getResult()));
}
if (request.hasParent()) {
compound.put(NBT_PARENT, controller.serialize(request.getParent()));
}
compound.put(NBT_CHILDREN, childrenCompound);
final ListNBT deliveriesList = new ListNBT();
request.getDeliveries().forEach(itemStack -> deliveriesList.add(itemStack.save(new CompoundNBT())));
compound.put(NBT_DELIVERIES, deliveriesList);
return compound;
}
use of net.minecraft.nbt.IntNBT in project minecolonies by Minecolonies.
the class StandardRequestFactories method serializeToNBT.
public static <T extends IRequestable> CompoundNBT serializeToNBT(final IFactoryController controller, final IRequest<T> request, final IObjectToNBTConverter<T> typeSerialization) {
final CompoundNBT compound = new CompoundNBT();
final CompoundNBT requesterCompound = controller.serialize(request.getRequester());
final CompoundNBT tokenCompound = controller.serialize(request.getId());
final IntNBT stateCompound = request.getState().serialize();
final CompoundNBT requestedCompound = typeSerialization.apply(controller, request.getRequest());
final ListNBT childrenCompound = new ListNBT();
for (final IToken<?> token : request.getChildren()) {
childrenCompound.add(controller.serialize(token));
}
compound.put(NBT_REQUESTER, requesterCompound);
compound.put(NBT_TOKEN, tokenCompound);
compound.put(NBT_STATE, stateCompound);
compound.put(NBT_REQUESTED, requestedCompound);
if (request.hasResult()) {
compound.put(NBT_RESULT, typeSerialization.apply(controller, request.getResult()));
}
if (request.hasParent()) {
compound.put(NBT_PARENT, controller.serialize(request.getParent()));
}
compound.put(NBT_CHILDREN, childrenCompound);
final ListNBT deliveriesList = new ListNBT();
request.getDeliveries().forEach(itemStack -> deliveriesList.add(itemStack.save(new CompoundNBT())));
compound.put(NBT_DELIVERIES, deliveriesList);
return compound;
}
use of net.minecraft.nbt.IntNBT in project minecolonies by Minecolonies.
the class StandardRequestFactories method deserializeFromNBT.
public static <T extends IRequestable, R extends IRequest<T>> R deserializeFromNBT(final IFactoryController controller, final CompoundNBT compound, final INBTToObjectConverter<T> typeDeserialization, final IObjectConstructor<T, R> objectConstructor) {
final IRequester requester = controller.deserialize(compound.getCompound(NBT_REQUESTER));
final IToken<?> token = controller.deserialize(compound.getCompound(NBT_TOKEN));
final RequestState state = RequestState.deserialize((IntNBT) compound.get(NBT_STATE));
final T requested = typeDeserialization.apply(controller, compound.getCompound(NBT_REQUESTED));
final List<IToken<?>> childTokens = new ArrayList<>();
final ListNBT childCompound = compound.getList(NBT_CHILDREN, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < childCompound.size(); i++) {
childTokens.add(controller.deserialize(childCompound.getCompound(i)));
}
@SuppressWarnings(Suppression.LEFT_CURLY_BRACE) final R request = objectConstructor.construct(requested, token, requester, state);
request.addChildren(childTokens);
if (compound.getAllKeys().contains(NBT_PARENT)) {
request.setParent(controller.deserialize(compound.getCompound(NBT_PARENT)));
}
if (compound.getAllKeys().contains(NBT_RESULT)) {
request.setResult(typeDeserialization.apply(controller, compound.getCompound(NBT_RESULT)));
}
if (compound.getAllKeys().contains(NBT_DELIVERIES)) {
final ImmutableList.Builder<ItemStack> stackBuilder = ImmutableList.builder();
final ListNBT deliveriesList = compound.getList(NBT_DELIVERIES, Constants.NBT.TAG_COMPOUND);
NBTUtils.streamCompound(deliveriesList).forEach(itemStackCompound -> stackBuilder.add(ItemStack.of(itemStackCompound)));
request.overrideCurrentDeliveries(stackBuilder.build());
}
return request;
}
use of net.minecraft.nbt.IntNBT in project dynmap by webbukkit.
the class ForgeMapChunkCache method getNBTValue.
private Object getNBTValue(INBT v) {
Object val = null;
switch(v.getId()) {
case // Byte
1:
val = Byte.valueOf(((ByteNBT) v).getByte());
break;
case // Short
2:
val = Short.valueOf(((ShortNBT) v).getShort());
break;
case // Int
3:
val = Integer.valueOf(((IntNBT) v).getInt());
break;
case // Long
4:
val = Long.valueOf(((LongNBT) v).getLong());
break;
case // Float
5:
val = Float.valueOf(((FloatNBT) v).getFloat());
break;
case // Double
6:
val = Double.valueOf(((DoubleNBT) v).getDouble());
break;
case // Byte[]
7:
val = ((ByteArrayNBT) v).getByteArray();
break;
case // String
8:
val = ((StringNBT) v).getString();
break;
case // List
9:
ListNBT tl = (ListNBT) v;
ArrayList<Object> vlist = new ArrayList<Object>();
int type = tl.getTagType();
for (int i = 0; i < tl.size(); i++) {
switch(type) {
case 5:
float fv = tl.getFloat(i);
vlist.add(fv);
break;
case 6:
double dv = tl.getDouble(i);
vlist.add(dv);
break;
case 8:
String sv = tl.getString(i);
vlist.add(sv);
break;
case 10:
CompoundNBT tc = tl.getCompound(i);
vlist.add(getNBTValue(tc));
break;
case 11:
int[] ia = tl.getIntArray(i);
vlist.add(ia);
break;
}
}
val = vlist;
break;
case // Map
10:
CompoundNBT tc = (CompoundNBT) v;
HashMap<String, Object> vmap = new HashMap<String, Object>();
for (Object t : tc.keySet()) {
String st = (String) t;
INBT tg = tc.get(st);
vmap.put(st, getNBTValue(tg));
}
val = vmap;
break;
case // Int[]
11:
val = ((IntArrayNBT) v).getIntArray();
break;
}
return val;
}
Aggregations