net.minecraft.entity.item.EntityMinecart Java Examples
The following examples show how to use
net.minecraft.entity.item.EntityMinecart.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityFallingBlockEU.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void dismountRidingEntity() { Entity entity = this.getRidingEntity(); super.dismountRidingEntity(); // Try to find an air block beside the track to dismount to if (entity instanceof EntityMinecart) { BlockPos pos = new BlockPos(this); for (BlockPos posTmp : PositionUtils.getAdjacentPositions(pos, EnumFacing.UP, true)) { if (this.getEntityWorld().isAirBlock(posTmp)) { this.setPosition(posTmp.getX() + 0.5D, this.posY, posTmp.getZ() + 0.5D); break; } } } }
Example #2
Source File: BlockTeleportRail.java From Signals with GNU General Public License v3.0 | 6 votes |
@Override public void onMinecartPass(World world, EntityMinecart cart, BlockPos pos){ super.onMinecartPass(world, cart, pos); if(!world.isRemote) { TileEntityTeleportRail te = (TileEntityTeleportRail)world.getTileEntity(pos); MCPos telDestination = te.getLinkedPosition(); if(telDestination != null) { //We can only teleport if we have a destination to go to. spawnParticle(cart); MCTrain train = RailNetworkManager.getServerInstance().getState().getTrain(cart.getUniqueID()); if(train != null) { //Should always be true if(train.getCarts().size() == train.cartIDs.size()) { //We can only teleport if all carts are loaded. //Check if all carts are on adjacent teleport tracks Set<MCPos> teleportRails = getNeighboringTeleportRails(world, pos); for(MCPos cartPos : train.getPositions()) { if(!teleportRails.contains(cartPos)) { return; //When not all carts are on adjacent teleport tracks, don't teleport. } } teleport(new HashSet<>(train.getCarts()), telDestination); } } } } }
Example #3
Source File: MCTrain.java From Signals with GNU General Public License v3.0 | 6 votes |
@Override public boolean updatePositions(NetworkState<MCPos> state){ super.updatePositions(state); Set<EntityMinecart> carts = getCarts(); if(!carts.isEmpty()) { //Update if any cart is loaded, currently. ImmutableSet.Builder<MCPos> positionBuilder = ImmutableSet.builder(); for(EntityMinecart cart : getCarts()) { MCPos cartPos = new MCPos(cart.world, cart.getPosition().down()); if(railNetworkManager.getNetwork().railObjects.get(cartPos) == null) { cartPos = new MCPos(cart.world, cart.getPosition()); } positionBuilder.add(cartPos); } ImmutableSet<MCPos> positions = positionBuilder.build(); return setPositions(railNetworkManager.getNetwork(), state, positions); } else { return false; } }
Example #4
Source File: RailNetworkManager.java From Signals with GNU General Public License v3.0 | 6 votes |
private void initTrains(){ List<EntityMinecart> carts = new ArrayList<>(); for(World world : DimensionManager.getWorlds()) { for(Entity entity : world.loadedEntityList) { if(entity instanceof EntityMinecart) { carts.add((EntityMinecart)entity); } } } Set<MCTrain> trains = new NetworkObjectProvider().provideTrains(carts); state.setTrains(trains); for(MCTrain train : trains) { NetworkHandler.sendToAll(new PacketAddOrUpdateTrain(train)); } }
Example #5
Source File: IElectricMinecart.java From NEI-Integration with MIT License | 6 votes |
/** * Must be called once per tick while on tracks by the owning object. * Server side only. * <p> * <blockquote><pre> * {@code * public void onEntityUpdate() * { * super.onEntityUpdate(); * if (!world.isRemote) * chargeHandler.tick(); * } * } * </pre></blockquote> */ public void tick() { clock++; removeLosses(); draw = (draw * 49.0 + lastTickDraw) / 50.0; lastTickDraw = 0.0; if (drewFromTrack > 0) drewFromTrack--; else if (type == Type.USER && charge < (capacity / 2.0) && clock % DRAW_INTERVAL == 0) { ILinkageManager lm = CartTools.getLinkageManager(minecart.worldObj); for (EntityMinecart cart : lm.getCartsInTrain(minecart)) { if (cart instanceof IElectricMinecart) { ChargeHandler ch = ((IElectricMinecart) cart).getChargeHandler(); if (ch.getType() != Type.USER && ch.getCharge() > 0) { charge += ch.removeCharge(capacity - charge); break; } } } } }
Example #6
Source File: CartTools.java From NEI-Integration with MIT License | 6 votes |
/** * Spawns a new cart entity using the provided item. * <p/> * The backing item must implement <code>IMinecartItem</code> and/or extend * <code>ItemMinecart</code>. * <p/> * Generally Forge requires all cart items to extend ItemMinecart. * * @param owner The player name that should used as the owner * @param cart An ItemStack containing a cart item, will not be changed by * the function * @param world The World object * @param x x-Coord * @param y y-Coord * @param z z-Coord * @return the cart placed or null if failed * @see IMinecartItem, ItemMinecart */ public static EntityMinecart placeCart(GameProfile owner, ItemStack cart, WorldServer world, int x, int y, int z) { if (cart == null) return null; cart = cart.copy(); if (cart.getItem() instanceof IMinecartItem) { IMinecartItem mi = (IMinecartItem) cart.getItem(); return mi.placeCart(owner, cart, world, x, y, z); } else if (cart.getItem() instanceof ItemMinecart) try { boolean placed = cart.getItem().onItemUse(cart, FakePlayerFactory.get(world, railcraftProfile), world, x, y, z , 0, 0, 0, 0); if (placed) { List<EntityMinecart> carts = getMinecartsAt(world, x, y, z, 0.3f); if (carts.size() > 0) { setCartOwner(carts.get(0), owner); return carts.get(0); } } } catch (Exception e) { return null; } return null; }
Example #7
Source File: CapabilityMinecartDestination.java From Signals with GNU General Public License v3.0 | 6 votes |
public void onCartBroken(EntityMinecart cart){ if(!travelingBetweenDimensions) { if(motorized) { motorized = false; cart.dropItem(ModItems.CART_ENGINE, 1); for(int i = 0; i < fuelInv.getSizeInventory(); i++) { ItemStack fuel = fuelInv.getStackInSlot(i); if(fuel != null) cart.entityDropItem(fuel, 0); } } } if(chunkloading) { ChunkLoadManager.INSTANCE.unmarkAsChunkLoader(cart); if(!travelingBetweenDimensions) { chunkloading = false; if(!SignalsConfig.disableChunkLoaderUpgrades) cart.dropItem(ModItems.CHUNKLOADER_UPGRADE, 1); } } travelingBetweenDimensions = false; }
Example #8
Source File: RailTools.java From NEI-Integration with MIT License | 6 votes |
/** * Checks to see if a cart is being held by a ITrackLockdown. * * @param cart The cart to check * @return True if being held */ public static boolean isCartLockedDown(EntityMinecart cart) { int x = MathHelper.floor_double(cart.posX); int y = MathHelper.floor_double(cart.posY); int z = MathHelper.floor_double(cart.posZ); if (BlockRailBase.func_150049_b_(cart.worldObj, x, y - 1, z)) y--; TileEntity tile = cart.worldObj.getTileEntity(x, y, z); if (tile instanceof ITrackTile) { ITrackInstance track = ((ITrackTile) tile).getTrackInstance(); return track instanceof ITrackLockdown && ((ITrackLockdown) track).isCartLockedDown(cart); } else if (tile instanceof ITrackLockdown) return ((ITrackLockdown) tile).isCartLockedDown(cart); return false; }
Example #9
Source File: GlassesMessage.java From Signals with GNU General Public License v3.0 | 6 votes |
public GlassesMessage(PacketUpdateMessage packet, World world){ associatedRouter = packet.pos; Entity cart = world.getEntityByID(packet.entityId); associatedCart = cart instanceof EntityMinecart ? (EntityMinecart)cart : null; String message = packet.message; message = I18n.format(message); message = message.replaceAll("\\$ROUTER\\$", String.format("(%s, %s, %s)", associatedRouter.getX(), associatedRouter.getY(), associatedRouter.getZ())); if(associatedCart != null) { BlockPos cartPos = associatedCart.getPosition(); message = message.replaceAll("\\$CART\\$", String.format("(%s at (%s, %s, %s)", associatedCart.getName(), cartPos.getX(), cartPos.getY(), cartPos.getZ())); } else { //Log.warn("Cart is null!"); } //Format the args for(int i = 0; i < packet.args.length; i++) { if(packet.args[i].startsWith("signals.")) { packet.args[i] = I18n.format(packet.args[i]); } } localizedMessage = String.format(message, (Object[])packet.args); }
Example #10
Source File: TracersModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private boolean checkFilter(Entity entity) { boolean ret = false; if (this.players.getValue() && entity instanceof EntityPlayer && entity != Minecraft.getMinecraft().player) { ret = true; } if (this.mobs.getValue() && entity instanceof IMob) { ret = true; } if (this.animals.getValue() && entity instanceof IAnimals && !(entity instanceof IMob)) { ret = true; } if (this.vehicles.getValue() && (entity instanceof EntityBoat || entity instanceof EntityMinecart || entity instanceof EntityMinecartContainer)) { ret = true; } if (this.items.getValue() && entity instanceof EntityItem) { ret = true; } return ret; }
Example #11
Source File: VanillaMinecraftMetaProvider.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Override public Object getMeta(EntityMinecart target, Vec3 relativePos) { Map<String, Object> result = Maps.newHashMap(); boolean hasOwner = CartTools.doesCartHaveOwner(target); result.put("hasOwner", hasOwner); if (hasOwner) result.put("owner", CartTools.getCartOwner(target)); return result; }
Example #12
Source File: EntityArmourStand.java From Et-Futurum with The Unlicense | 5 votes |
@Override @SuppressWarnings("unchecked") protected void collideWithNearbyEntities() { List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.2, 0, 0.2)); if (list != null && !list.isEmpty()) for (int i = 0; i < list.size(); i++) { Entity entity = list.get(i); if (entity instanceof EntityMinecart && ((EntityMinecart) entity).getMinecartType() == 0) entity.applyEntityCollision(this); } }
Example #13
Source File: BlockCrate.java From archimedes-ships with MIT License | 5 votes |
@Override public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { if (!(entity instanceof EntityPlayer) && entity instanceof EntityLivingBase || (entity instanceof EntityBoat && !(entity instanceof EntityShip)) || entity instanceof EntityMinecart) { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof TileEntityCrate) { if (((TileEntityCrate) te).canCatchEntity() && ((TileEntityCrate) te).getContainedEntity() == null) { ((TileEntityCrate) te).setContainedEntity(entity); } } } }
Example #14
Source File: ContainerMinecart.java From Signals with GNU General Public License v3.0 | 5 votes |
public ContainerMinecart(InventoryPlayer playerInv, EntityMinecart cart, boolean isMotorized){ super(null); this.cart = cart; this.isMotorized = isMotorized; CapabilityMinecartDestination cap = cart.getCapability(CapabilityMinecartDestination.INSTANCE, null); addSyncedFields(cap); if(isMotorized){ IInventory inv = cap.getFuelInv(); for(int i = 0; i < inv.getSizeInventory(); i++){ addSlotToContainer(new SlotInventoryLimiting(inv, i, 18 * i + 164, 70)); } addPlayerSlots(playerInv, 128, 120); } }
Example #15
Source File: TracersModule.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int getColor(Entity entity) { int ret = -1; if (entity instanceof IAnimals && !(entity instanceof IMob)) { ret = 0xFF00FF44; } if (entity instanceof IMob) { ret = 0xFFFFAA00; } if (entity instanceof EntityBoat || entity instanceof EntityMinecart || entity instanceof EntityMinecartContainer) { ret = 0xFF00FFAA; } if (entity instanceof EntityItem) { ret = 0xFF00FFAA; } if (entity instanceof EntityPlayer) { ret = 0xFFFF4444; if (Seppuku.INSTANCE.getFriendManager().isFriend(entity) != null) { ret = 0xFF9900EE; } } return ret; }
Example #16
Source File: DestinationProviderItems.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public boolean isCartApplicable(TileEntity te, EntityMinecart cart, Pattern destinationRegex){ IItemHandler cap = cart.getCapability(ITEM_HANDLER, null); if(cap != null && destinationRegex.matcher("ITEM").matches()) { IInventory inv = (IInventory)te; for(int cartSlot = 0; cartSlot < cap.getSlots(); cartSlot++) { ItemStack cartStack = cap.getStackInSlot(cartSlot); if(!cartStack.isEmpty()) { if(isStackApplicable(cartStack, inv)) return true; } } } return false; }
Example #17
Source File: BlockTeleportRail.java From Signals with GNU General Public License v3.0 | 5 votes |
private void spawnParticle(EntityMinecart cart){ Random rand = cart.world.rand; float maxSpeed = 1; float f = (rand.nextFloat() - 0.5F) * maxSpeed; float f1 = (rand.nextFloat() - 0.5F) * maxSpeed; float f2 = (rand.nextFloat() - 0.5F) * maxSpeed; NetworkHandler.sendToAllAround(new PacketSpawnParticle(EnumParticleTypes.PORTAL, cart.posX, cart.posY, cart.posZ, f, f1, f2), cart.world); }
Example #18
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
/** * @param world * @param i * @param j * @param k * @param sensitivity Controls the size of the search box, ranges from * (-inf, 0.49]. * @return */ public static List<EntityMinecart> getMinecartsAt(World world, int i, int j, int k, float sensitivity) { sensitivity = Math.min(sensitivity, 0.49f); List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i + sensitivity, j + sensitivity, k + sensitivity, i + 1 - sensitivity, j + 1 - sensitivity, k + 1 - sensitivity)); List<EntityMinecart> carts = new ArrayList<EntityMinecart>(); for (Object o : entities) { EntityMinecart cart = (EntityMinecart) o; if (!cart.isDead) carts.add((EntityMinecart) o); } return carts; }
Example #19
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
public static <T extends EntityMinecart> T getMinecartOnSide(World world, int i, int j, int k, float sensitivity, ForgeDirection side, Class<T> type, boolean subclass) { for (EntityMinecart cart : getMinecartsOnSide(world, i, j, k, sensitivity, side)) { if (type == null || (subclass && type.isInstance(cart)) || cart.getClass() == type) return (T) cart; } return null; }
Example #20
Source File: MCTrain.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public RailRoute<MCPos> pathfind(MCPos start, EnumHeading dir){ RailRoute<MCPos> path = null; for(EntityMinecart cart : getCarts()) { path = pathfind(cart, start, dir); if(path != null) break; } return path; }
Example #21
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
public static List<EntityMinecart> getMinecartsIn(World world, int i1, int j1, int k1, int i2, int j2, int k2) { List entities = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox(i1, j1, k1, i2, j2, k2)); List<EntityMinecart> carts = new ArrayList<EntityMinecart>(); for (Object o : entities) { EntityMinecart cart = (EntityMinecart) o; if (!cart.isDead) carts.add((EntityMinecart) o); } return carts; }
Example #22
Source File: MCNetworkState.java From Signals with GNU General Public License v3.0 | 5 votes |
public void onMinecartJoinedWorld(EntityMinecart cart){ MCTrain train = getTrain(cart.getUniqueID()); //Override any previous records, automatically resolving dimension changes of entities, where the entity in the next dimension //is added, before the entity in the previous dimension is noticed to be removed. EntityMinecart oldCart = trackingMinecarts.put(cart.getUniqueID(), cart); if(oldCart != null && train != null) train.onCartRemoved(oldCart); if(train == null) { //If the added cart does not belong to a train yet addTrain(ImmutableSet.of(cart.getUniqueID())); } else { train.onCartAdded(cart); } }
Example #23
Source File: SignalsConfig.java From Signals with GNU General Public License v3.0 | 5 votes |
public static boolean isBlacklisted(EntityMinecart cart, String[] config){ if(config.length == 0) return false; EntityEntry entry = EntityRegistry.getEntry(cart.getClass()); ResourceLocation cartID = ForgeRegistries.ENTITIES.getKey(entry); for(String blacklist : config) { if(cartID.equals(new ResourceLocation(blacklist))) { return true; } } return false; }
Example #24
Source File: MCNetworkState.java From Signals with GNU General Public License v3.0 | 5 votes |
public void onChunkUnload(Chunk chunk){ for(ClassInheritanceMultiMap<Entity> entities : chunk.getEntityLists()) { for(EntityMinecart cart : entities.getByClass(EntityMinecart.class)) { removeCart(cart); } } }
Example #25
Source File: MCNetworkState.java From Signals with GNU General Public License v3.0 | 5 votes |
private void removeDeadMinecarts(){ Iterator<EntityMinecart> iterator = trackingMinecarts.values().iterator(); while(iterator.hasNext()) { EntityMinecart cart = iterator.next(); if(cart.isDead) { iterator.remove(); onCartKilled(cart); } } }
Example #26
Source File: MCNetworkState.java From Signals with GNU General Public License v3.0 | 5 votes |
private void addToGroup(List<List<EntityMinecart>> cartGroups, EntityMinecart cart){ for(List<EntityMinecart> group : cartGroups) { if(RailManager.getInstance().areLinked(cart, group.get(0))) { group.add(cart); return; } } List<EntityMinecart> newGroup = new ArrayList<>(); newGroup.add(cart); cartGroups.add(newGroup); }
Example #27
Source File: MCNetworkState.java From Signals with GNU General Public License v3.0 | 5 votes |
private MCTrain getMatchingTrain(List<MCTrain> trains, EntityMinecart cart){ for(MCTrain train : trains) { if(!train.getCarts().isEmpty() && RailManager.getInstance().areLinked(train.getCarts().iterator().next(), cart)) { return train; } } return null; }
Example #28
Source File: TileEntityCartHopper.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void update(){ if(!getWorld().isRemote) { if(firstTick) { firstTick = false; updateCartAbove(); } if(managingCartId != null) { List<EntityMinecart> carts = getWorld().getEntities(EntityMinecart.class, input -> input.getPersistentID().equals(managingCartId)); managingCart = carts.isEmpty() ? null : carts.get(0); managingCartId = null; } updateManagingCart(new AxisAlignedBB(extract ? getPos().up() : getPos().down())); boolean shouldPush; if(managingCart != null) { if(isDisabled()) { shouldPush = true; } else { shouldPush = tryTransfer(extract); } } else { shouldPush = false; } if(shouldPush && !pushedLastTick) pushCart(); boolean notifyNeighbors = shouldPush != pushedLastTick; pushedLastTick = shouldPush; if(notifyNeighbors) { getWorld().notifyNeighborsOfStateChange(getPos(), getBlockType(), true); } int comparatorInputOverride = getComparatorInputOverride(); if(lastComparatorInputOverride != comparatorInputOverride) { world.updateComparatorOutputLevel(pos, ModBlocks.CART_HOPPER); lastComparatorInputOverride = comparatorInputOverride; } } }
Example #29
Source File: PneumaticCraftUtils.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
private static boolean isEntityValidForName(String filter, Entity entity) throws IllegalArgumentException{ if(filter.equals("")) { return true; } else if(filter.startsWith("@")) {//entity type selection filter = filter.substring(1); //cut off the '@'. Class typeClass = null; if(filter.equals("mob")) { typeClass = EntityMob.class; } else if(filter.equals("animal")) { typeClass = EntityAnimal.class; } else if(filter.equals("living")) { typeClass = EntityLivingBase.class; } else if(filter.equals("player")) { typeClass = EntityPlayer.class; } else if(filter.equals("item")) { typeClass = EntityItem.class; } else if(filter.equals("minecart")) { typeClass = EntityMinecart.class; } else if(filter.equals("drone")) { typeClass = EntityDrone.class; } if(typeClass != null) { return typeClass.isAssignableFrom(entity.getClass()); } else { throw new IllegalArgumentException(filter + " is not a valid entity type."); } } else { try { String regex = filter.toLowerCase().replaceAll(".", "[$0]").replace("[*]", ".*");//Wildcard regex return entity.getCommandSenderName().toLowerCase().matches(regex);//TODO when player, check if entity is tamed by the player (see EntityAIAvoidEntity for example) } catch(PatternSyntaxException e) { return entity.getCommandSenderName().toLowerCase().equals(filter.toLowerCase()); } } }
Example #30
Source File: CartTools.java From NEI-Integration with MIT License | 5 votes |
public static boolean isMinecartAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) { List<EntityMinecart> list = getMinecartsAt(world, i, j, k, sensitivity); if (type == null) return !list.isEmpty(); else for (EntityMinecart cart : list) { if ((subclass && type.isInstance(cart)) || cart.getClass() == type) return true; } return false; }