use of net.minecraft.server.v1_11_R1.Container in project Panilla by ds58.
the class InventoryCleaner method clean.
@Override
public void clean(IPanillaPlayer player) {
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
Container container = craftPlayer.getHandle().activeContainer;
int containerSlotsSize = 0;
if (is_1_12_2) {
containerSlotsSize = container.slots.size();
} else {
try {
Field slotsField = Container.class.getField("c");
List<Slot> slots = (List<Slot>) slotsField.get(container);
containerSlotsSize = slots.size();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
for (int slot = 0; slot < containerSlotsSize; slot++) {
ItemStack itemStack = container.getSlot(slot).getItem();
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NBTTagCompound nmsTag = itemStack.getTag();
INbtTagCompound tag = new NbtTagCompound(nmsTag);
String itemName = itemStack.getItem().getName();
if (nmsTag == null || itemName == null) {
continue;
}
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.failsThreshold(failedNbt)) {
container.getSlot(slot).getItem().setTag(null);
} else if (FailedNbt.fails(failedNbt)) {
nmsTag.remove(failedNbt.key);
container.getSlot(slot).getItem().setTag(nmsTag);
}
}
}
use of net.minecraft.server.v1_11_R1.Container in project Panilla by ds58.
the class InventoryCleaner method clean.
@Override
public void clean(IPanillaPlayer player) {
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
Container container = craftPlayer.getHandle().activeContainer;
for (int slot = 0; slot < container.c.size(); slot++) {
ItemStack itemStack = container.getSlot(slot).getItem();
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NBTTagCompound nmsTag = itemStack.getTag();
INbtTagCompound tag = new NbtTagCompound(nmsTag);
String itemName = itemStack.getItem().getName();
if (nmsTag == null || itemName == null) {
continue;
}
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.failsThreshold(failedNbt)) {
container.getSlot(slot).getItem().setTag(null);
} else if (FailedNbt.fails(failedNbt)) {
nmsTag.remove(failedNbt.key);
container.getSlot(slot).getItem().setTag(nmsTag);
}
}
}
use of net.minecraft.server.v1_11_R1.Container in project neo4j-ogm by neo4j.
the class HierarchyRelsTest method relationshipsToSubclassesShouldBeClearedAsWell.
// GH-806
@Test
public void relationshipsToSubclassesShouldBeClearedAsWell() {
inheritanceImpl(s -> new Element(s), Container::setElement);
inheritanceImpl(s -> new ConcreteElement(s), Container::setElement);
inheritanceImpl(s -> new VeryConcreteElementA(s), Container::setElement);
inheritanceImpl(s -> new EvenMoreConcreteElement(s), Container::setElement);
inheritanceImpl(s -> new IElementImpl1(s), Container::setElement2);
inheritanceImpl(s -> new IElementImpl1A(s), Container::setElement2);
}
use of net.minecraft.server.v1_11_R1.Container in project neo4j-ogm by neo4j.
the class HierarchyRelsTest method inheritanceImpl.
<T> void inheritanceImpl(Function<String, T> portProvider, BiConsumer<Container, Set<T>> elementConsumer) {
session.query("MATCH (n) DETACH DELETE n", Collections.emptyMap());
session.clear();
// Setup initial relationships in one tx
Container card = new Container("container");
T port1 = portProvider.apply("e1");
T port2 = portProvider.apply("e2");
elementConsumer.accept(card, new HashSet<>(Arrays.asList(port1, port2)));
card.setElementsOfAnotherRelationship(Collections.singleton(new ConcreteElement("oe")));
session.save(card);
session.clear();
// Verify state
String verificationQuery = "match (c:Container) <- [:RELATES_TO|RELATES_TO_TOO|RELATES_TO_AS_WELL] - (p) " + "where any (label in labels(p) where label in $expectedLabels) return c.name as c, p.name as p";
Set<String> expectedLabels = new HashSet<>(Arrays.asList(ConcreteElement.class.getSimpleName(), port1.getClass().getSimpleName()));
Map<String, Object> parameters = Collections.singletonMap("expectedLabels", expectedLabels);
Result r;
r = session.query(verificationQuery, parameters);
assertThat(r.queryResults()).hasSize(3);
assertThat(r.queryResults()).extracting(m -> m.get("p")).containsExactlyInAnyOrder("e1", "e2", "oe");
// Reload in cleared session for fresh tx
card = session.load(Container.class, card.getId());
T port3 = portProvider.apply("e3");
// Replace associations
elementConsumer.accept(card, new HashSet<>(Arrays.asList(port3)));
session.save(card);
session.clear();
r = session.query(verificationQuery, parameters);
assertThat(r.queryResults()).hasSize(2);
assertThat(r.queryResults()).extracting(m -> m.get("p")).containsExactlyInAnyOrder("e3", "oe");
}
use of net.minecraft.server.v1_11_R1.Container in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method gh813.
@Test
public void gh813() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results;
results = sessionFactory.openSession().query("RETURN 'containerName' AS name, [i IN RANGE(0,3) | {a:{id: i, name:'a'+i}, b:{id: i, name:'b'+i}, c:{id: i, name:'c'+i}}] AS rows", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
Container container = entityMapper.map(Container.class, results.iterator().next());
assertContainer(container, 4);
results = sessionFactory.openSession().query("WITH {a: {id: 0, name: 'a0'}, b: {id:0, name:'b0'}, c: {id:0, name: 'c0'}} AS i RETURN 'containerName' as name, collect(i) as rows", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
container = entityMapper.map(Container.class, results.iterator().next());
assertContainer(container, 1);
}
Aggregations