Java Code Examples for net.minecraft.entity.Entity#startRiding()
The following examples show how to use
net.minecraft.entity.Entity#startRiding() .
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: EventsCommon.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@SubscribeEvent(priority = EventPriority.HIGHEST) public void onEntityJoinWorldEvent(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); World world = entity.world; BlockPos posAt = new BlockPos(entity); Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(world, posAt); if (!event.getWorld().isRemote && physicsObject.isPresent() && !(entity instanceof EntityFallingBlock)) { if (entity instanceof EntityArmorStand || entity instanceof EntityPig || entity instanceof EntityBoat) { EntityMountable entityMountable = new EntityMountable(world, entity.getPositionVector(), CoordinateSpaceType.SUBSPACE_COORDINATES, posAt); world.spawnEntity(entityMountable); entity.startRiding(entityMountable); } physicsObject.get() .getShipTransformationManager() .getCurrentTickTransform().transform(entity, TransformType.SUBSPACE_TO_GLOBAL); // TODO: This should work but it doesn't because of sponge. Instead we have to rely on MixinChunk.preAddEntity() to fix this // event.setCanceled(true); // event.getWorld().spawnEntity(entity); } }
Example 2
Source File: EntityUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Note: This does NOT spawn any of the entities in the world! * @param nbt * @param world * @return */ @Nullable public static Entity createEntityAndPassengersFromNBT(NBTTagCompound nbt, World world) { Entity entity = createEntityFromNBTSingle(nbt, world); if (entity == null) { return null; } else { if (nbt.hasKey("Passengers", Constants.NBT.TAG_LIST)) { NBTTagList taglist = nbt.getTagList("Passengers", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < taglist.tagCount(); ++i) { Entity passenger = createEntityAndPassengersFromNBT(taglist.getCompoundTagAt(i), world); if (passenger != null) { passenger.startRiding(entity, true); } } } return entity; } }
Example 3
Source File: VSWorldEventListener.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public void onEntityAdded(Entity entity) { if (entity instanceof PhysicsWrapperEntity) { ValkyrienSkiesMod.VS_PHYSICS_MANAGER.onShipLoad((PhysicsWrapperEntity) entity); } else { // This is really only here because Sponge doesn't call the entity join event for some reason :/ // So I basically just copied the event code here as well. World world = worldObj; BlockPos posAt = new BlockPos(entity); Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(world, posAt); if (!worldObj.isRemote && physicsObject.isPresent() && !(entity instanceof EntityFallingBlock)) { if (entity instanceof EntityArmorStand || entity instanceof EntityPig || entity instanceof EntityBoat) { EntityMountable entityMountable = new EntityMountable(world, entity.getPositionVector(), CoordinateSpaceType.SUBSPACE_COORDINATES, posAt); world.spawnEntity(entityMountable); entity.startRiding(entityMountable); } world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4) .removeEntity(entity); physicsObject.get() .getShipTransformationManager() .getCurrentTickTransform().transform(entity, TransformType.SUBSPACE_TO_GLOBAL); world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4) .addEntity(entity); } } }
Example 4
Source File: ValkyrienUtils.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
public static void fixEntityToShip(Entity toFix, Vector posInLocal, PhysicsObject mountingShip) { World world = mountingShip.world(); EntityMountable entityMountable = new EntityMountable(world, posInLocal.toVec3d(), CoordinateSpaceType.SUBSPACE_COORDINATES, mountingShip.getReferenceBlockPos()); world.spawnEntity(entityMountable); toFix.startRiding(entityMountable); }
Example 5
Source File: EntityElevatorCapsule.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void useNetworkData(EntityPlayer player, Side side, byte id, NBTTagCompound nbt) { if(id == PACKET_WRITE_DST_INFO && world.isRemote) { if(nbt.hasKey("dimid")) { dstTilePos = new DimensionBlockPosition(nbt.getInteger("dimid"), new HashedBlockPosition(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z"))); } else dstTilePos = null; } else if(id == PACKET_WRITE_SRC_INFO && world.isRemote) { if(nbt.hasKey("dimid")) { srcTilePos = new DimensionBlockPosition(nbt.getInteger("dimid"), new HashedBlockPosition(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z"))); } else srcTilePos = null; } else if(id == PACKET_RECIEVE_NBT) { PacketHandler.sendToPlayersTrackingEntity(new PacketEntity(this, PACKET_WRITE_DST_INFO), this); } else if(id == PACKET_LAUNCH_EVENT && world.isRemote) { List<EntityPlayer> list = world.getEntitiesWithinAABB(EntityPlayer.class, getEntityBoundingBox()); for(Entity ent : list) { if(this.getRidingEntity() == null) ent.startRiding(this); } MinecraftForge.EVENT_BUS.post(new RocketEvent.RocketLaunchEvent(this)); } else if(id == PACKET_DEORBIT && world.isRemote) { MinecraftForge.EVENT_BUS.post(new RocketEvent.RocketDeOrbitingEvent(this)); } }
Example 6
Source File: ItemEnderPearlReusable.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (world.isRemote) { return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } // Damage 1: "Elite version" of the pearl, makes the thrower fly with it. Idea by xisumavoid in episode Hermitcraft III 303 :) EntityEnderPearlReusable pearl = new EntityEnderPearlReusable(world, player, stack.getMetadata() == 1); float velocity = stack.getMetadata() == 1 ? 2.5f : 1.9f; pearl.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, velocity, 0.8f); world.spawnEntity(pearl); if (stack.getMetadata() == 1) { Entity bottomEntity = player.getLowestRidingEntity(); // Dismount the previous pearl if we are already riding one // (by selecting the entity riding that pearl to be the one mounted to the new pearl) if (bottomEntity instanceof EntityEnderPearlReusable) { bottomEntity = bottomEntity.getPassengers().get(0); } bottomEntity.startRiding(pearl); } stack.shrink(1); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERPEARL_THROW, SoundCategory.MASTER, 0.5f, 0.4f / (itemRand.nextFloat() * 0.4f + 0.8f)); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); }
Example 7
Source File: ItemMobHarness.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
private boolean mountTarget(ItemStack stack, World world, EntityPlayer player, Entity targetEntity) { if (stack.getTagCompound() == null || targetEntity == null) { return false; } NBTTagCompound nbt = stack.getTagCompound(); byte mode = nbt.getByte("Mode"); UUID storedUUID = new UUID(nbt.getLong("TargetUUIDMost"), nbt.getLong("TargetUUIDLeast")); Entity storedEntity = null; double r = 64.0d; // The harness was clicked twice on the same entity, mount that entity on top of the player if (storedUUID.equals(targetEntity.getUniqueID())) { EntityUtils.unmountFirstRider(player); targetEntity.startRiding(player, true); this.clearData(stack); return true; } // The harness was clicked on two separate entities, mount the stored/first one on top of the currently targeted one else { // Mode 1: mount non-player entities to each other or to the player if (mode == 1) { List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, new AxisAlignedBB(player.posX - r, player.posY - r, player.posZ - r, player.posX + r, player.posY + r, player.posZ + r)); storedEntity = EntityUtils.findEntityByUUID(entities, storedUUID); } // Mode 2: mount a player else if (mode == 2) { storedEntity = world.getPlayerEntityByUUID(storedUUID); } // Matching (stored) entity found if (storedEntity != null && storedEntity.dimension == player.dimension) { // Don't allow mounting the entity into the same stack, or nasty infinite loops will happen >_> if (EntityUtils.doesEntityStackContainEntity(storedEntity, targetEntity) == false) { //EntityUtils.unmountFirstRider(targetEntity); storedEntity.startRiding(targetEntity, true); this.clearData(stack); return true; } } else if (storedEntity == null && world.isRemote == false) { player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.mobharness.targetnotfoundoroutofrange"), true); } } return false; }