use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.
the class ClientContainerRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
register("minecraft", "chest", inventory -> {
final int rows = inventory.getInventoryProperty(InventoryCapacity.class).map(capacity -> (int) Math.ceil(capacity.getValue().doubleValue() / 9.0)).orElse(1);
return new ChestClientContainer(rows);
});
register("minecraft", "furnace", inventory -> new FurnaceClientContainer());
register("minecraft", "dispenser", inventory -> new DispenserClientContainer());
register("minecraft", "crafting_table", inventory -> new CraftingTableClientContainer());
register("minecraft", "brewing_stand", inventory -> new BrewingStandClientContainer());
register("minecraft", "hopper", inventory -> new HopperClientContainer());
register("minecraft", "beacon", inventory -> new BeaconClientContainer());
register("minecraft", "enchanting_table", inventory -> new EnchantmentTableClientContainer());
register("minecraft", "anvil", inventory -> new AnvilClientContainer());
register("minecraft", "villager", inventory -> new TradingClientContainer());
register("minecraft", "horse", inventory -> {
int capacity = inventory.capacity();
capacity -= 2;
capacity = (int) Math.ceil((float) capacity / 3);
int entityId = -1;
if (inventory instanceof CarriedInventory) {
final Carrier carrier = ((CarriedInventory<Carrier>) inventory).getCarrier().orElse(null);
if (carrier instanceof Entity) {
final LanternEntity entity = (LanternEntity) carrier;
entityId = entity.getWorld().getEntityProtocolManager().getProtocolId(entity);
}
}
if (entityId == -1) {
throw new IllegalStateException("Invalid carrier entity to create a container.");
}
// TODO: Dummy entity support?
return new EntityEquipmentClientContainer(capacity, entityId);
});
register("minecraft", "shulker_box", inventory -> new ShulkerBoxClientContainer());
}
use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.
the class EntityProtocol method spawnWithEquipment.
protected void spawnWithEquipment(EntityProtocolUpdateContext context) {
if (hasEquipment() && this.entity instanceof Carrier) {
final Inventory inventory = ((Carrier) this.entity).getInventory();
for (int i = 0; i < Holder.EQUIPMENT_TYPES.length; i++) {
final ItemStack itemStack = inventory.query(Holder.EQUIPMENT_QUERIES[i]).first().peek().orElse(null);
final int slotIndex = i;
if (itemStack != null) {
context.sendToAllExceptSelf(() -> new MessagePlayOutEntityEquipment(getRootEntityId(), slotIndex, itemStack));
}
}
}
}
Aggregations