Java Code Examples for net.minecraft.world.World#getEntityByID()

The following examples show how to use net.minecraft.world.World#getEntityByID() . 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: GlassesMessage.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: CircuitProgrammerPacket.java    From bartworks with MIT License 6 votes vote down vote up
@Override
public void process(IBlockAccess iBlockAccess) {
    World w = DimensionManager.getWorld(this.dimID);
    if (w != null && w.getEntityByID(this.playerID) instanceof EntityPlayer) {
        ItemStack stack = ((EntityPlayer) w.getEntityByID(this.playerID)).getHeldItem();
        if ((stack != null) && (stack.stackSize > 0)) {
            Item item = stack.getItem();
            if (item instanceof Circuit_Programmer) {
                NBTTagCompound nbt = stack.getTagCompound();
                nbt.setBoolean("HasChip", this.hasChip);
                if (this.hasChip)
                    nbt.setByte("ChipConfig", this.chipCfg);
                stack.setTagCompound(nbt);
                ((EntityPlayer) w.getEntityByID(this.playerID)).inventory.setInventorySlotContents(((EntityPlayer) w.getEntityByID(this.playerID)).inventory.currentItem, stack);
            }
        }
    }
}
 
Example 3
Source File: EntityRequest.java    From HoloInventory with MIT License 6 votes vote down vote up
@Override
public ResponseMessage onMessage(EntityRequest message, MessageContext ctx)
{
    World world = DimensionManager.getWorld(message.dim);
    if (world == null) return null;
    Entity entity = world.getEntityByID(message.id);
    if (entity == null) return null;

    if (entity instanceof IInventory) return new PlainInventory(message.id, (IInventory) entity);
    else if (entity instanceof IMerchant) return new MerchantRecipes(message.id, (IMerchant) entity, ctx.getServerHandler().player);
    else if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
    {
        return new PlainInventory(message.id, entity.getName(), entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null));
    }

    return null;
}
 
Example 4
Source File: EntityRpcTarget.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) {
	int worldId = input.readInt();
	int entityId = input.readInt();

	World world = WorldUtils.getWorld(side, worldId);
	entity = world.getEntityByID(entityId);
}
 
Example 5
Source File: SyncMapEntity.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static ISyncMapProvider findOwner(World world, PacketBuffer input) {
	int entityId = input.readInt();
	Entity entity = world.getEntityByID(entityId);
	if (entity instanceof ISyncMapProvider)
		return (ISyncMapProvider)entity;

	Log.warn("Invalid handler info: can't find ISyncHandler entity id %d", entityId);
	return null;
}
 
Example 6
Source File: GuiHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {

	Object tile;
	
	if(y > -1)
		tile = world.getTileEntity(new BlockPos(x, y, z));
	else if(x == -1) {
		ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
		
		//If there is latency or some desync odd things can happen so check for that
		if(stack == null || !(stack.getItem() instanceof IModularInventory)) {
			return null;
		}
		
		tile = player.getHeldItem(EnumHand.MAIN_HAND).getItem();
	}
	else
		tile = world.getEntityByID(x);

	if(ID == guiId.OreMappingSatellite.ordinal()) {
		
		SatelliteBase satellite = DimensionManager.getInstance().getSatellite(y);
		
		if(satellite == null || !(satellite instanceof SatelliteOreMapping) || satellite.getDimensionId() != world.provider.getDimension())
			satellite = null;
		
		return new GuiOreMappingSatellite((SatelliteOreMapping) satellite, player);
	}
	return null;
}
 
Example 7
Source File: SpellRing.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean taxCaster(@Nonnull World world, SpellData data, double multiplier, boolean failSound) {
	if(data.getData(SpellData.DefaultKeys.CASTER) == null) return true;

	Entity caster = world.getEntityByID(data.getData(SpellData.DefaultKeys.CASTER));

	if(caster == null) {
		Wizardry.LOGGER.warn("Caster was null!");
		return true;
	}

	IManaCapability cap = ManaCapabilityProvider.getCap(caster);
	if (cap == null) return false;

	double manaDrain = getManaDrain(data) * multiplier;
	double burnoutFill = getBurnoutFill(data) * multiplier;

	boolean fail = false;

	try (ManaManager.CapManagerBuilder mgr = ManaManager.forObject(cap)) {
		if (mgr.getMana() < manaDrain) fail = true;

		mgr.removeMana(manaDrain);
		mgr.addBurnout(burnoutFill);
	}

	if (fail && failSound) {

		Vec3d origin = data.getOriginWithFallback(world);
		if (origin != null)
			world.playSound(null, new BlockPos(origin), ModSounds.SPELL_FAIL, SoundCategory.NEUTRAL, 1f, 1f);
	}

	return !fail;
}
 
Example 8
Source File: ClientProxy.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){
    TileEntity te = y >= 0 ? world.getTileEntity(new BlockPos(x, y, z)) : null;
    Entity entity = y == -1 ? world.getEntityByID(x) : null;
    switch(EnumGuiId.values()[ID]){
        case STATION_MARKER:
            return new GuiStationMarker((TileEntityStationMarker)te);
        case MINECART_DESTINATION:
            return new GuiMinecart(player.inventory, (EntityMinecart)entity, z == 1);
        case NETWORK_CONTROLLER:
            return new GuiNetworkController();
        case SELECT_DESTINATION_PROVIDER:
            return new GuiSelectDestinationProvider(te);
        case ITEM_HANDLER_DESTINATION:
            return new GuiItemHandlerDestination(te);
        case CART_HOPPER:
            return new GuiCartHopper((TileEntityCartHopper)te);
        case RAIL_LINK:
            return new GuiRailLink((TileEntityRailLink)te);
        case TICKET_DESTINATION:
            ItemStack stack = player.getHeldItemMainhand();
            CapabilityMinecartDestination accessor = stack.getCapability(CapabilityMinecartDestination.INSTANCE, null);
            if(accessor == null) return null;
            ItemTicket.readNBTIntoCap(stack);
            return new GuiTicket(new Container(){
                @Override
                public boolean canInteractWith(EntityPlayer playerIn){
                    return true;
                }
            }, accessor, stack.getDisplayName());
        default:
            throw new IllegalStateException("No Gui for gui id: " + ID);
    }
}
 
Example 9
Source File: CommonProxy.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){
    TileEntity te = y >= 0 ? world.getTileEntity(new BlockPos(x, y, z)) : null;
    Entity entity = y == -1 ? world.getEntityByID(x) : null;
    switch(EnumGuiId.values()[ID]){
        case RAIL_LINK:
        case STATION_MARKER:
        case CART_HOPPER:
            return new ContainerBase<>(te);
        case MINECART_DESTINATION:
            return new ContainerMinecart(player.inventory, (EntityMinecart)entity, z == 1);
        case NETWORK_CONTROLLER:
            return new ContainerNetworkController();
        case SELECT_DESTINATION_PROVIDER:
            return new ContainerSelectDestinationProvider(te);
        case ITEM_HANDLER_DESTINATION:
            return new ContainerItemHandlerDestination(te);
        case TICKET_DESTINATION:
            return new Container(){
                @Override
                public boolean canInteractWith(EntityPlayer playerIn){
                    return true;
                }
            };
        default:
            throw new IllegalStateException("No Container for gui id: " + ID);
    }
}
 
Example 10
Source File: ClientProxy.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    switch (ID) {
        case 0:
            return new GuiGolem(player, (EntityGolemBase) world.getEntityByID(x));
            //return new AdditionalGolemGui(player, (EntityGolemBase)world.getEntityByID(x));
        case 1:
            return new InfusionClawGui(player.inventory, (IInventory) world.getTileEntity(x, y, z));
        case 2:
            return new ArcanePackagerGui(player.inventory, (IInventory) world.getTileEntity(x, y, z));
    }
    return null;
}
 
Example 11
Source File: CommonProxy.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    switch (ID) {
        case 0:
            return new ContainerGolem(player.inventory, ((EntityGolemBase)world.getEntityByID(x)).inventory);
        case 1:
            return new ContainerInfusionClaw(player.inventory, (IInventory) world.getTileEntity(x, y, z));
        case 2:
            return new ContainerArcanePackager(player.inventory, (IInventory) world.getTileEntity(x, y, z));
    }
    return null;
}
 
Example 12
Source File: ArmourStandInteractHandler.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public IMessage onMessage(ArmourStandInteractMessage message, MessageContext ctx) {
	World world = DimensionManager.getWorld(message.dimID);
	EntityArmourStand stand = (EntityArmourStand) world.getEntityByID(message.standID);
	EntityPlayer player = (EntityPlayer) world.getEntityByID(message.playerID);

	stand.interact(player, message.hitPos);
	return null;
}
 
Example 13
Source File: GuiHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {

	Object tile;

	if(y > -1)
		tile = world.getTileEntity(new BlockPos(x, y, z));
	else if(x == -1) {
		ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
		
		//If there is latency or some desync odd things can happen so check for that
		if(stack == null || !(stack.getItem() instanceof IModularInventory)) {
			return null;
		}
		
		tile = player.getHeldItem(EnumHand.MAIN_HAND).getItem();
	}
	else
		tile = world.getEntityByID(x);

	if(ID == guiId.OreMappingSatellite.ordinal()) {
		SatelliteBase satellite = DimensionManager.getInstance().getSatellite(y);
		
		if(satellite == null || !(satellite instanceof SatelliteOreMapping) || satellite.getDimensionId() != world.provider.getDimension())
			satellite = null;
		
		return new ContainerOreMappingSatallite((SatelliteOreMapping) satellite, player.inventory);
	}
	return null;
}
 
Example 14
Source File: MagnetModeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public void trackMagnetItem(int entityID, World world) {
    Entity e = world.getEntityByID(entityID);
    if (e instanceof EntityItem) {
        clientMagnetItems.add(((EntityItem) e));
    }
}
 
Example 15
Source File: DelayedEntityLoadManager.java    From OpenModsLib with MIT License 4 votes vote down vote up
public void registerLoadListener(World world, IEntityLoadListener listener, int entityId) {
	Entity entity = world.getEntityByID(entityId);
	if (entity == null) delayedLoads.put(entityId, listener);
	else listener.onEntityLoaded(entity);
}
 
Example 16
Source File: ClientHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public void addSMPMagneticItem(int i, World world) {
    Entity e = world.getEntityByID(i);
    if (e instanceof EntityItem)
        SMPmagneticItems.add((EntityItem) e);
}
 
Example 17
Source File: SpellData.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public Entity getVictim(World world) {
	return world.getEntityByID(getDataWithFallback(DefaultKeys.ENTITY_HIT, -1));
}
 
Example 18
Source File: SpellData.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public Entity getCaster(World world) {
	return world.getEntityByID(getDataWithFallback(DefaultKeys.CASTER, -1));
}
 
Example 19
Source File: MixinS19PacketEntityHeadLook.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author boomboompower
 * @reason Fix internal NPE from odd packets
 */
@Overwrite
public Entity getEntity(World worldIn) {
    return worldIn != null ? worldIn.getEntityByID(entityId) : null;
}
 
Example 20
Source File: MixinS19PacketEntityStatus.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author boomboompower
 * @reason Fix internal NPE from odd packets
 */
@Overwrite
public Entity getEntity(World worldIn) {
    return worldIn != null ? worldIn.getEntityByID(entityId) : null;
}