Java Code Examples for net.minecraft.entity.Entity#getEntityWorld()

The following examples show how to use net.minecraft.entity.Entity#getEntityWorld() . 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: Nyan.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
	final Entity entity = event.getEntity();
	final World world = entity.getEntityWorld();

	if(world.isRemote) {
		return;
	}

	final MinecraftServer server = world.getMinecraftServer();
	final NBTTagCompound data = entity.getEntityData();

	if(data.hasUniqueId(NYANED_ENTITY_UUID_KEY)) {
		final Entity nyanedEntity =
				server.getEntityFromUuid(data.getUniqueId(NYANED_ENTITY_UUID_KEY));

		if(nyanedEntity == null || nyanedEntity.isDead) {
			world.removeEntity(entity);
			return;
		}
	}

	if(data.getBoolean(HAS_NYAN_ENTITY_KEY)) {
		updateNyanEntity(server, (WorldServer) world, entity, data);
	} else if(!data.hasKey(HAS_NYAN_ENTITY_KEY)) {
		if(entity instanceof EntityPlayer || random.nextInt(10) == 0) {
			data.setBoolean(HAS_NYAN_ENTITY_KEY, true);
			updateNyanEntity(server, (WorldServer) world, entity, data);
		} else {
			data.setBoolean(HAS_NYAN_ENTITY_KEY, false);
		}
	}
}
 
Example 2
Source File: EntityEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onTravelToDimensionEvent(EntityTravelToDimensionEvent event)
{
    // Prevent recursion from this same event being fired from the teleport method
    if (TeleportEntity.isTeleportInProgress())
    {
        return;
    }

    Entity entity = event.getEntity();

    if (entity instanceof EntityPlayer)
    {
        // If the player is holding a Portal Scaler, then try to use that and cancel the regular
        // teleport if the Portal Scaler teleportation succeeds
        ItemStack stack = EntityUtils.getHeldItemOfType((EntityPlayer) entity, EnderUtilitiesItems.PORTAL_SCALER);

        if (stack.isEmpty() == false && EntityUtils.isEntityCollidingWithBlockSpace(entity.getEntityWorld(), entity, Blocks.PORTAL))
        {
            World worldSource = entity.getEntityWorld();
            World worldDestination = entity.getServer().getWorld(event.getDimension());
            boolean validSource = WorldUtils.isNetherDimension(worldSource) || WorldUtils.isOverworldDimension(worldSource);
            boolean validDestination = worldDestination != null && (WorldUtils.isNetherDimension(worldDestination) || WorldUtils.isOverworldDimension(worldDestination));

            // Check that the player is traveling between the overworld and the nether
            if (validSource && validDestination)
            {
                if (((ItemPortalScaler) stack.getItem()).usePortalWithPortalScaler(stack, entity.getEntityWorld(), (EntityPlayer) entity))
                {
                    event.setCanceled(true);
                }
            }
        }
    }
}
 
Example 3
Source File: Helper.java    From ForgeHax with MIT License 4 votes vote down vote up
public static World getWorld(Entity entity) {
  return entity.getEntityWorld();
}
 
Example 4
Source File: DefaultMiscCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void dataChanged(Entity entity) {
	if (entity instanceof EntityPlayer && !entity.getEntityWorld().isRemote)
		PacketHandler.NETWORK.sendTo(new PacketUpdateMiscCapToClient(serializeNBT()), (EntityPlayerMP) entity);
}
 
Example 5
Source File: BaubleManaCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void dataChanged(Entity entity) {
	if ((entity != null) && entity instanceof EntityPlayer && !entity.getEntityWorld().isRemote)
		PacketHandler.NETWORK.sendTo(new PacketUpdateManaCap(serializeNBT()), (EntityPlayerMP) entity);
}
 
Example 6
Source File: CustomManaCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void dataChanged(Entity entity) {
	if ((entity != null) && entity instanceof EntityPlayer && !entity.getEntityWorld().isRemote)
		PacketHandler.NETWORK.sendTo(new PacketUpdateManaCap(serializeNBT()), (EntityPlayerMP) entity);
}
 
Example 7
Source File: DefaultManaCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void dataChanged(Entity entity) {
	if (entity instanceof EntityPlayer && !entity.getEntityWorld().isRemote)
		PacketHandler.NETWORK.sendTo(new PacketUpdateManaCap(serializeNBT()), (EntityPlayerMP) entity);
}
 
Example 8
Source File: TeleportEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean teleportEntityRandomly(Entity entity, double maxDist)
{
    World world = entity.getEntityWorld();

    if (canTeleportEntity(entity) == false || world.isRemote)
    {
        return false;
    }

    double deltaYaw = 0.0d;
    double deltaPitch = 0.0d;
    double x = 0.0d;
    double y = 0.0d;
    double z = 0.0d;
    maxDist = maxDist - (world.rand.nextFloat() * maxDist / 2.0d);

    // Try to find a free spot (non-colliding with blocks)
    for (int i = 0; i < 20; i++)
    {
        deltaYaw = world.rand.nextFloat() * 2d * Math.PI;
        //deltaPitch = ((90.0d - (Math.random() * 180.0d)) / 180.0d) * Math.PI; // free range on the y-direction
        deltaPitch = world.rand.nextFloat() * 0.5d * Math.PI; // only from the same level upwards
        x = entity.posX;
        y = entity.posY;
        z = entity.posZ;
        x += Math.cos(deltaPitch) * Math.cos(deltaYaw) * maxDist;
        z += Math.cos(deltaPitch) * Math.sin(deltaYaw) * maxDist;
        y += Math.sin(deltaPitch) * maxDist;

        if (entity.getEntityBoundingBox() != null && world.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty())
        {
            // Sound and particles on the original location
            addTeleportSoundsAndParticles(world, entity.posX, entity.posY, entity.posZ);

            entity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);

            // Sound and particles on the new, destination location.
            addTeleportSoundsAndParticles(world, x, y, z);
            return true;
        }
    }

    return false;
}
 
Example 9
Source File: TeleportEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static Entity teleportEntity(Entity entity, double x, double y, double z, int dimDst, boolean forceRecreate)
{
    if (entity == null || entity.isEntityAlive() == false || canTeleportEntity(entity) == false || entity.getEntityWorld().isRemote)
    {
        return null;
    }

    // Post the event and check if the teleport should be allowed
    if (entity instanceof EntityLivingBase)
    {
        EnderTeleportEvent event = new EnderTeleportEvent((EntityLivingBase) entity, x, y, z, 0.0f);

        if (MinecraftForge.EVENT_BUS.post(event))
        {
            return null;
        }
    }

    // Sound and particles on the original location
    addTeleportSoundsAndParticles(entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ);

    if (entity instanceof EntityLiving)
    {
        ((EntityLiving) entity).setMoveForward(0.0f);
        ((EntityLiving) entity).getNavigator().clearPath();
    }

    if (entity.getEntityWorld().provider.getDimension() != dimDst)
    {
        entity = teleportEntityToDimension(entity, x, y, z, dimDst);
    }
    else
    {
        entity = teleportEntityInsideSameDimension(entity, x, y, z);
    }

    if (entity != null)
    {
        // Final position
        addTeleportSoundsAndParticles(entity.getEntityWorld(), x, y, z);
    }

    return entity;
}
 
Example 10
Source File: TeleportEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static Entity teleportEntityToDimension(Entity entity, double x, double y, double z, int dimDst)
{
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer worldDst = server.getWorld(dimDst);

    teleportInProgress = true;

    if (worldDst == null || ForgeHooks.onTravelToDimension(entity, dimDst) == false)
    {
        teleportInProgress = false;
        return null;
    }

    teleportInProgress = false;

    // Load the chunk first
    int chunkX = (int) Math.floor(x / 16D);
    int chunkZ = (int) Math.floor(z / 16D);
    ChunkLoading.getInstance().loadChunkForcedWithModTicket(dimDst, chunkX, chunkZ, 10);

    if (entity instanceof EntityPlayerMP)
    {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        World worldOld = player.getEntityWorld();
        DummyTeleporter teleporter = new DummyTeleporter(worldDst);

        player.setLocationAndAngles(x, y, z, player.rotationYaw, player.rotationPitch);
        server.getPlayerList().transferPlayerToDimension(player, dimDst, teleporter);

        // Teleporting FROM The End, remove the boss bar that would otherwise get stuck on
        if (worldOld.provider instanceof WorldProviderEnd)
        {
            removeDragonBossBarHack(player, (WorldProviderEnd) worldOld.provider);
        }

        player.setPositionAndUpdate(x, y, z);
        worldDst.updateEntityWithOptionalForce(player, false);
        player.addExperienceLevel(0);
        player.setPlayerHealthUpdated();
        // TODO update food level?
    }
    else
    {
        WorldServer worldSrc = (WorldServer) entity.getEntityWorld();

        // FIXME ugly special case to prevent the chest minecart etc from duping items
        if (entity instanceof EntityMinecartContainer)
        {
            ((EntityMinecartContainer) entity).setDropItemsWhenDead(false);
        }

        Entity entityNew = EntityList.newEntity(entity.getClass(), worldDst);

        if (entityNew != null)
        {
            EntityUtils.copyDataFromOld(entityNew, entity);
            entityNew.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);

            boolean flag = entityNew.forceSpawn;
            entityNew.forceSpawn = true;
            worldDst.spawnEntity(entityNew);
            entityNew.forceSpawn = flag;

            worldDst.updateEntityWithOptionalForce(entityNew, false);
            entity.isDead = true;

            worldSrc.removeEntity(entity);
            worldSrc.updateEntityWithOptionalForce(entity, false);

            worldSrc.resetUpdateEntityTick();
            worldDst.resetUpdateEntityTick();
        }

        entity = entityNew;
    }

    return entity;
}
 
Example 11
Source File: GuiEntityRender.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
public void draw(int mouseX, int mouseY, float partialTicks) {
	int w = getWidth();
	int h = getHeight();
	
	enableBlendAlphaStuffs();
	setRenderColorARGB(_colorBackground); drawRect(1, 1, w - 2, h - 2);
	setRenderColorARGB(_colorBorder);     drawOutline(0, 0, w, h);
	disableBlendAlphaStuffs();
	
	Entity entity = getEntity();
	if (entity == null) return;
	
	AxisAlignedBB bbox = entity.getRenderBoundingBox();
	float entityWidth  = (float)(bbox.maxX - bbox.minX);
	float entityHeight = (float)(bbox.maxY - bbox.minY);
	float scale = Math.min((w - RESERVED_SPACE) / entityWidth,
	                       (h - RESERVED_SPACE) / entityHeight) * _zoom;
	float yaw   = _yawDefault + _yaw;
	float pitch = _pitchDefault + _pitch;
	
	getContext().pushScissor(this, 1, 1, w - 2, h - 2);
	
	if (entity.getEntityWorld() == null)
		entity.setWorld(DummyWorld.INSTANCE);
	if (getMC().player == null) {
		World world = entity.getEntityWorld();
		if (!(world instanceof DummyWorld)) return;
		getMC().player = ((DummyWorld)world).player;
		getMC().player.setWorld(world);
	}
	
	setRenderColorARGB(Color.WHITE);
	GlStateManager.enableDepth();
	// From GuiInventory.drawEntityOnScreen
	GlStateManager.enableColorMaterial();
	GlStateManager.pushMatrix();
	GlStateManager.translate(w * _centerX, h * _centerY, 100.0F);
	GlStateManager.scale(-scale, scale, scale);
	GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
	GlStateManager.rotate(pitch, 1.0F, 0.0F, 0.0F);
	GlStateManager.translate(0.0F, -(entityHeight / 2), 0.0F);
	GlStateManager.rotate(yaw, 0.0F, 1.0F, 0.0F);
	
	RenderHelper.enableStandardItemLighting();
	
	RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
	rendermanager.setPlayerViewY(180.0F);
	rendermanager.setRenderShadow(false);
	rendermanager.renderEntity(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false);
	rendermanager.setRenderShadow(true);
	
	GlStateManager.popMatrix();
	RenderHelper.disableStandardItemLighting();
	GlStateManager.disableRescaleNormal();
	GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
	GlStateManager.disableTexture2D();
	GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
	
	GlStateManager.disableDepth();
	if (getMC().player instanceof DummyPlayerSP)
		getMC().player = null;
	getContext().popScissor();
}