Package net.minecraft.entity.item

Examples of net.minecraft.entity.item.EntityMinecart


    public void breakLinkB(EntityMinecart cart) {
        resetTrain(cart);
        UUID link = getLinkB(cart);
        cart.getEntityData().setLong(LINK_B_HIGH, 0);
        cart.getEntityData().setLong(LINK_B_LOW, 0);
        EntityMinecart other = getCartFromUUID(link);
        if (other != null)
            breakLink(other, cart);
        if (cart instanceof ILinkableCart)
            ((ILinkableCart) cart).onLinkBroken(other);
View Full Code Here


        if (Game.isNotHost(thePlayer.worldObj))
            return;

        if (stack != null && stack.getItem() instanceof ItemMagnifyingGlass)
            if (entity instanceof EntityMinecart) {
                EntityMinecart cart = (EntityMinecart) entity;
                ChatPlugin.sendLocalizedChat(thePlayer, "railcraft.gui.mag.glass.placedby", Railcraft.getProxy().getItemDisplayName(cart.getCartItem()), PlayerPlugin.getUsername(thePlayer.worldObj, CartTools.getCartOwner(cart)));
                event.setCanceled(true);
            }
    }
View Full Code Here

    public void onEntityCollision(EntityMinecart cart, Entity other) {
        if (Game.isNotHost(cart.worldObj) || other == cart.riddenByEntity || other.isDead || cart.isDead)
            return;

        ILinkageManager lm = LinkageManager.instance();
        EntityMinecart link = lm.getLinkedCartA(cart);
        if (link != null && (link == other || other == link.riddenByEntity))
            return;
        link = lm.getLinkedCartB(cart);
        if (link != null && (link == other || other == link.riddenByEntity))
            return;

        boolean isLiving = other instanceof EntityLivingBase;
        boolean isPlayer = other instanceof EntityPlayer;

        if (isLiving && !isPlayer && cart.canBeRidden() && !(other instanceof EntityIronGolem)
                && cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0.001D
                && cart.riddenByEntity == null && other.ridingEntity == null) {
            int mountPrevention = cart.getEntityData().getInteger("MountPrevention");
            if (mountPrevention <= 0)
                other.mountEntity(cart);
        }

        int i = MathHelper.floor_double(cart.posX);
        int j = MathHelper.floor_double(cart.posY);
        int k = MathHelper.floor_double(cart.posZ);
        Block block = cart.worldObj.getBlock(i, j, k);
        if (isLiving && RailcraftBlocks.getBlockElevator() != null && block == RailcraftBlocks.getBlockElevator())
            return;

//        System.out.println(cart.getClass().getSimpleName() + ": " + cart.entityId + " collided with " + other.getClass().getSimpleName() + ": " + other.entityId);
        Vec2D cartPos = new Vec2D(cart.posX, cart.posZ);
        Vec2D otherPos = new Vec2D(other.posX, other.posZ);

        Vec2D unit = Vec2D.subtract(otherPos, cartPos);
        unit.normalize();

        double distance = cart.getDistanceToEntity(other);
        double depth = distance - OPTIMAL_DISTANCE;

        double forceX = 0;
        double forceZ = 0;

        if (depth < 0) {
            double spring = isPlayer ? COEF_SPRING_PLAYER : COEF_SPRING;
            double penaltyX = spring * depth * unit.getX();
            double penaltyZ = spring * depth * unit.getY();

            forceX += penaltyX;
            forceZ += penaltyZ;

            if (!isPlayer) {
                double impulseX = unit.getX();
                double impulseZ = unit.getY();
                impulseX *= -(1.0 + COEF_RESTITUTION);
                impulseZ *= -(1.0 + COEF_RESTITUTION);

                Vec2D cartVel = new Vec2D(cart.motionX, cart.motionZ);
                Vec2D otherVel = new Vec2D(other.motionX, other.motionZ);

                double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);

                impulseX *= dot;
                impulseZ *= dot;
                impulseX *= 0.5;
                impulseZ *= 0.5;

                forceX -= impulseX;
                forceZ -= impulseZ;
            }
        }

        if (other instanceof EntityMinecart) {
            EntityMinecart otherCart = (EntityMinecart) other;
            if (!cart.isPoweredCart() || otherCart.isPoweredCart())
                if (!RailTools.isCartLockedDown(cart))
                    cart.addVelocity(forceX, 0, forceZ);
            if (!otherCart.isPoweredCart() || cart.isPoweredCart())
                if (!RailTools.isCartLockedDown(otherCart))
                    other.addVelocity(-forceX, 0, -forceZ);
        } else {
//            if(isPlayer) {
//                forceX += Math.abs(cart.motionX - other.motionX) / 2;
View Full Code Here

        cart.setDragAir(EntityMinecart.defaultDragAir);
    }

    @SubscribeEvent
    public void onMinecartUpdate(MinecartUpdateEvent event) {
        EntityMinecart cart = event.minecart;
        NBTTagCompound data = cart.getEntityData();

        int x = (int) event.x;
        int y = (int) event.y;
        int z = (int) event.z;
        Block block = cart.worldObj.getBlock(x, y, z);
        int launched = data.getInteger("Launched");
        if (TrackTools.isRailBlock(block)) {
            cart.fallDistance = 0;
            if (cart.riddenByEntity != null)
                cart.riddenByEntity.fallDistance = 0;
            if (launched > 1)
                land(cart);
        } else if (launched == 1) {
            data.setInteger("Launched", 2);
            cart.setCanUseRail(true);
        } else if (launched > 1 && (cart.onGround || cart.isInsideOfMaterial(Material.circuits)))
            land(cart);

        int mountPrevention = data.getInteger("MountPrevention");
        if (mountPrevention > 0) {
            mountPrevention--;
            data.setInteger("MountPrevention", mountPrevention);
        }

        byte elevator = data.getByte("elevator");
        if (elevator > 0) {
            elevator--;
            data.setByte("elevator", elevator);
        }

        if (data.getBoolean("explode")) {
            cart.getEntityData().setBoolean("explode", false);
            CartUtils.explodeCart(cart);
        }

        if (data.getBoolean("HighSpeed"))
            if (CartUtils.cartVelocityIsLessThan(cart, TrackSpeed.SPEED_CUTOFF))
View Full Code Here

//        }
    }

    @SubscribeEvent
    public void onMinecartEntityCollision(MinecartCollisionEvent event) {
        EntityMinecart cart = event.minecart;
        Entity other = event.collider;
        if (other == cart.riddenByEntity)
            return;

        testHighSpeedCollision(cart, other);
View Full Code Here

        boolean highSpeed = cart.getEntityData().getBoolean("HighSpeed");
        if (highSpeed) {
            ILinkageManager lm = LinkageManager.instance();
            if (other instanceof EntityMinecart && lm.areLinked(cart, (EntityMinecart) other))
                return;
            EntityMinecart link = lm.getLinkedCartA(cart);
            if (link != null && other == link.riddenByEntity)
                return;
            link = lm.getLinkedCartB(cart);
            if (link != null && other == link.riddenByEntity)
                return;
View Full Code Here

        cart.getEntityData().setBoolean("explode", true);
    }

    @SubscribeEvent
    public void onMinecartInteract(MinecartInteractEvent event) {
        EntityMinecart cart = event.minecart;
        EntityPlayer player = event.player;

        if (!CartTools.doesCartHaveOwner(cart))
            CartTools.setCartOwner(cart, player);

        if (!(cart instanceof EntityTunnelBore) && player.getDistanceSqToEntity(cart) > MAX_INTERACT_DIST_SQ) {
            event.setCanceled(true);
            return;
        }
        if (cart.isDead) {
            event.setCanceled(true);
            return;
        }
        if (cart.canBeRidden()) {
            if (cart.riddenByEntity != null && player.ridingEntity != cart) {
                event.setCanceled(true);
                return;
            }
            if (player.ridingEntity != null && player.ridingEntity != cart) {
View Full Code Here

                        facing = ForgeDirection.WEST;
                    }

//          System.out.println("PlayerYaw = " + playerYaw + " Yaw = " + facing + " Meta = " + meta);

                    EntityMinecart bore = new EntityTunnelBore(world, (float) i + 0.5F, (float) j, (float) k + 0.5F, facing);
                    CartTools.setCartOwner(bore, player);
                    world.spawnEntityInWorld(bore);
                }
            }
            itemstack.stackSize--;
View Full Code Here

            return;
        }

        movedItemCart = false;

        EntityMinecart cart = CartTools.getMinecartOnSide(worldObj, xCoord, yCoord, zCoord, 0.1f, getOrientation());

        if (cart != currentCart) {
            setPowered(false);
            currentCart = cart;
            transferedItems.clear();
            cartWasSent();
        }

        if (cart == null) {
            return;
        }

        IInventory cartInv = null;
        if (cart instanceof IInventory) {
            cartInv = (IInventory) cart;
        }

        if (cartInv == null || cartInv.getSizeInventory() <= 0) {
            if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY) || cart.isPoweredCart()) {
                setPowered(true);
            }
            return;
        }

        if (isSendCartGateAction()) {
            if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY)) {
                setPowered(true);
            }
            return;
        }

        ItemStack minecartSlot1 = getCartFilters().getStackInSlot(0);
        ItemStack minecartSlot2 = getCartFilters().getStackInSlot(1);
        if (minecartSlot1 != null || minecartSlot2 != null) {
            if (!CartUtils.doesCartMatchFilter(minecartSlot1, cart) && !CartUtils.doesCartMatchFilter(minecartSlot2, cart)) {
                if (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY)) {
                    setPowered(true);
                }
                return;
            }
        }

        if (isPaused())
            return;

        LinkedList<IInventory> chests = new LinkedList<IInventory>(invCache.getAdjecentInventories());
        chests.addFirst(invBuffer);

        checkedItems.clear();

        switch (getMode()) {
            case TRANSFER: {
                boolean hasFilter = false;
                for (ItemStack filter : getItemFilters().getContents()) {
                    if (filter == null) {
                        continue;
                    }
                    if (!checkedItems.add(filter)) {
                        continue;
                    }
                    hasFilter = true;
                    Short numMoved = transferedItems.get(filter);
                    if (numMoved == null) {
                        numMoved = 0;
                    }
                    if (numMoved < InvTools.countItems(getItemFilters(), filter)) {
                        ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
                        if (moved != null) {
                            movedItemCart = true;
                            numMoved++;
                            transferedItems.put(moved, numMoved);
                            break;
                        }
                    }
                }
                if (!hasFilter) {
                    ItemStack moved = InvTools.moveOneItem(chests, cartInv);
                    if (moved != null) {
                        movedItemCart = true;
                        break;
                    }
                }
                break;
            }
            case STOCK: {
                for (ItemStack filter : getItemFilters().getContents()) {
                    if (filter == null) {
                        continue;
                    }
                    if (!checkedItems.add(filter)) {
                        continue;
                    }
                    int stocked = InvTools.countItems(cartInv, filter);
                    if (stocked < InvTools.countItems(getItemFilters(), filter)) {
                        ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
                        if (moved != null) {
                            movedItemCart = true;
                            break;
                        }
                    }
                }
                break;
            }
            case EXCESS: {
                for (ItemStack filter : getItemFilters().getContents()) {
                    if (filter == null) {
                        continue;
                    }
                    if (!checkedItems.add(filter)) {
                        continue;
                    }
                    int stocked = InvTools.countItems(chests, filter);
                    if (stocked > InvTools.countItems(getItemFilters(), filter)) {
                        ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
                        if (moved != null) {
                            movedItemCart = true;
                            break;
                        }
                    }
                }
                if (!movedItemCart) {
                    movedItemCart = InvTools.moveOneItemExcept(chests, cartInv, getItemFilters().getContents()) != null;
                }
                break;
            }
            case ALL: {
                boolean hasFilter = false;
                for (ItemStack filter : getItemFilters().getContents()) {
                    if (filter == null) {
                        continue;
                    }
                    if (!checkedItems.add(filter)) {
                        continue;
                    }
                    hasFilter = true;
                    ItemStack moved = InvTools.moveOneItem(chests, cartInv, filter);
                    if (moved != null) {
                        movedItemCart = true;
                        break;
                    }
                }
                if (!hasFilter) {
                    ItemStack moved = InvTools.moveOneItem(chests, cartInv);
                    if (moved != null) {
                        movedItemCart = true;
                        break;
                    }
                }
                break;
            }
        }

        if (movedItemCart) {
            setPowered(false);
        }

        EnumRedstoneMode state = getRedstoneModeController().getButtonState();
        if (state != EnumRedstoneMode.MANUAL && !isPowered() && (CartTools.cartVelocityIsLessThan(cart, STOP_VELOCITY) || cart.isPoweredCart())) {
            if (!movedItemCart && state != EnumRedstoneMode.COMPLETE) {
                if (state == EnumRedstoneMode.PARTIAL) {
                    if (!InvTools.isInventoryEmpty(cartInv)) {
                        setPowered(true);
                    }
View Full Code Here

            return;

        transferedEnergy = false;
        transferRate = 0;

        EntityMinecart cart = CartTools.getMinecartOnSide(worldObj, xCoord, yCoord, zCoord, 0.1f, direction);

        if (cart != currentCart) {
            setPowered(false);
            currentCart = cart;
            cartWasSent();
View Full Code Here

TOP

Related Classes of net.minecraft.entity.item.EntityMinecart

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.