Package org.terasology.entitySystem.entity

Examples of org.terasology.entitySystem.entity.EntityRef


        }
    }

    @ReceiveEvent(components = ClientComponent.class)
    public void onDisconnect(DisconnectedEvent event, EntityRef entity) {
        EntityRef clientInfo = entity.getComponent(ClientComponent.class).clientInfo;
        for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
            client.send(NotificationMessageEvent.newLeaveEvent(clientInfo));
        }
    }
View Full Code Here


        CoreRegistry.put(ComponentSystemManager.class, componentSystemManager);

        componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
        componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");

        EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
        LocalPlayer localPlayer = CoreRegistry.put(LocalPlayer.class, new LocalPlayer());
        localPlayer.setClientEntity(localPlayerEntity);

        componentSystemManager.initialise();
    }
View Full Code Here

        return item1.stackId.equals(item2.stackId);
    }

    private static boolean validateMove(EntityRef instigator, EntityRef from, int slotFrom, EntityRef to, int slotTo) {
        // Validate the move
        EntityRef itemFrom = InventoryUtils.getItemAt(from, slotFrom);
        EntityRef itemTo = InventoryUtils.getItemAt(to, slotTo);

        if (itemFrom.exists()) {
            BeforeItemRemovedFromInventory removeFrom = new BeforeItemRemovedFromInventory(instigator, itemFrom, slotFrom);
            from.send(removeFrom);
            if (removeFrom.isConsumed()) {
                return false;
            }
        }

        if (itemTo.exists()) {
            BeforeItemRemovedFromInventory removeTo = new BeforeItemRemovedFromInventory(instigator, itemTo, slotTo);
            to.send(removeTo);
            if (removeTo.isConsumed()) {
                return false;
            }
        }

        if (itemTo.exists()) {
            BeforeItemPutInInventory putFrom = new BeforeItemPutInInventory(instigator, itemTo, slotFrom);
            from.send(putFrom);
            if (putFrom.isConsumed()) {
                return false;
            }
View Full Code Here

     * @param to has to provide {@link InventoryComponent} for a successful transfer
     * @param toSlots slots that will be checked if they contain already the same type of item and have space
     * @return true if any amount > 0 got moved to the target
     */
    static boolean moveToExistingStacksInSlots(EntityRef from, int fromSlot, EntityRef to, List<Integer> toSlots) {
        EntityRef fromItem = getItemAt(from, fromSlot);
        ItemComponent fromItemComp = fromItem.getComponent(ItemComponent.class);
        if (fromItemComp == null) {
            return false;
        }

        int newFromStackCount = fromItemComp.stackCount;
        int slotCount = getSlotCount(to);
        for (int toSlot :toSlots) {
            EntityRef toItem = getItemAt(to, toSlot);
            if (isSameItem(toItem, fromItem)) {
                ItemComponent toItemComp = toItem.getComponent(ItemComponent.class);
                if (toItemComp == null) {
                    continue;
                }
                int spaceLeft = toItemComp.maxStackSize - toItemComp.stackCount ;
                if (spaceLeft > 0) {
View Full Code Here

     * @param from has to provide {@link InventoryComponent} for a successful transfer
     * @param toSlots slots that will be checked if they are free
     * @return true if at least 1 item got moved from the specified location.
     */
    static boolean moveToFreeSlots(EntityRef instigator, EntityRef from, int slotFrom, EntityRef to, List<Integer> toSlots) {
        EntityRef fromItem = getItemAt(from, slotFrom);
        ItemComponent fromItemComp = fromItem.getComponent(ItemComponent.class);
        if (fromItemComp == null) {
            return false;
        }

        for (int toSlot :toSlots) {
            EntityRef toItem = getItemAt(to, toSlot);
            if (!toItem.exists()) {
                BeforeItemPutInInventory putTo = new BeforeItemPutInInventory(instigator, fromItem, toSlot);
                to.send(putTo);
                boolean allowed = !putTo.isConsumed();
                if (allowed) {
                    putItemIntoSlot(to, fromItem, toSlot);
View Full Code Here

        return false;
    }


    static boolean moveItemToSlots(EntityRef instigator, EntityRef from, int fromSlot, EntityRef to, List<Integer> toSlots) {
        EntityRef fromItem = InventoryUtils.getItemAt(from, fromSlot);
        BeforeItemRemovedFromInventory removeFrom = new BeforeItemRemovedFromInventory(instigator, fromItem, fromSlot);
        from.send(removeFrom);
        if (removeFrom.isConsumed()) {
            return false;
        }
View Full Code Here

        }

        if (!InventoryUtils.validateMove(instigator, from, slotFrom, to, slotTo)) {
            return false;
        }
        EntityRef itemFrom = getItemAt(from, slotFrom);
        EntityRef itemTo = getItemAt(to, slotTo);

        putItemIntoSlot(from, itemTo, slotFrom);
        putItemIntoSlot(to, itemFrom, slotTo);

        return true;
View Full Code Here

        return true;
    }

    private static boolean checkForStacking(EntityRef from, int slotFrom, EntityRef to, int slotTo) {
        EntityRef itemFrom = getItemAt(from, slotFrom);
        EntityRef itemTo = getItemAt(to, slotTo);

        if (itemFrom.exists() && itemTo.exists() && canStackInto(itemFrom, itemTo )) {
            int fromCount = itemFrom.getComponent(ItemComponent.class).stackCount;
            int toCount = itemTo.getComponent(ItemComponent.class).stackCount;
            adjustStackSize(to, slotTo, fromCount + toCount);
            putItemIntoSlot(from, EntityRef.NULL, slotFrom);

            return true;
        }
View Full Code Here

    static boolean moveItemAmount(EntityRef instigator, EntityRef from, int slotFrom, EntityRef to, int slotTo, int amount) {
        if (!InventoryUtils.validateMoveAmount(instigator, from, slotFrom, to, slotTo, amount)) {
            return false;
        }

        EntityRef itemFrom = getItemAt(from, slotFrom);
        EntityRef itemTo = getItemAt(to, slotTo);

        if (!itemTo.exists()) {
            EntityRef fromCopy = CoreRegistry.get(EntityManager.class).copy(itemFrom);

            ItemComponent copyItem = fromCopy.getComponent(ItemComponent.class);
            copyItem.stackCount = (byte) amount;
            fromCopy.saveComponent(copyItem);

            putItemIntoSlot(to, fromCopy, slotTo);

            ItemComponent fromItem = itemFrom.getComponent(ItemComponent.class);
            if (fromItem.stackCount == amount) {
View Full Code Here

        return true;
    }

    static void putItemIntoSlot(EntityRef entity, EntityRef item, int slot) {
        InventoryComponent inventory = entity.getComponent(InventoryComponent.class);
        EntityRef oldItem = inventory.itemSlots.get(slot);
        inventory.itemSlots.set(slot, item);
        entity.saveComponent(inventory);
        entity.send(new InventorySlotChangedEvent(slot, oldItem, item));
    }
View Full Code Here

TOP

Related Classes of org.terasology.entitySystem.entity.EntityRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.