Java Code Examples for net.minecraftforge.common.DimensionManager#getWorld()

The following examples show how to use net.minecraftforge.common.DimensionManager#getWorld() . 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: SpaceObjectManager.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
	if(DimensionManager.getWorld(Configuration.spaceDimId) == null)
		return;
	
	long worldTime = DimensionManager.getWorld(Configuration.spaceDimId).getTotalWorldTime();
	//Assuming server
	//If no dim undergoing transition then nextTransitionTick = -1
	if((nextStationTransitionTick != -1 && worldTime >= nextStationTransitionTick && spaceStationOrbitMap.get(WARPDIMID) != null) || (nextStationTransitionTick == -1 && spaceStationOrbitMap.get(WARPDIMID) != null && !spaceStationOrbitMap.get(WARPDIMID).isEmpty())) {
		long newNextTransitionTick = -1;
		for(ISpaceObject obj : spaceStationOrbitMap.get(WARPDIMID)) {
			if(obj.getTransitionTime() <= worldTime) {
				moveStationToBody(obj, obj.getDestOrbitingBody());
				spaceStationOrbitMap.get(WARPDIMID).remove(obj);
			}
			else if(newNextTransitionTick == -1 || obj.getTransitionTime() < newNextTransitionTick)
				newNextTransitionTick = obj.getTransitionTime();
		}

		nextStationTransitionTick = newNextTransitionTick;
	}

}
 
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: CraftServer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public File getWorldContainer() {
    // Cauldron start - return the proper container
    if (DimensionManager.getWorld(0) != null) {
        return ((SaveHandler) DimensionManager.getWorld(0).getSaveHandler()).getWorldDirectory();
    }
    // Cauldron end
    if (this.getServer().anvilFile != null) {
        return this.getServer().anvilFile;
    }

    if (container == null) {
        container = new File(configuration.getString("settings.world-container", "."));
    }

    return container;
}
 
Example 5
Source File: TicketMap.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Override
public ForgeChunkManager.Ticket get(Object key) {
    if (key instanceof Integer) {
        if (super.get(key) == null) {
            World world = DimensionManager.getWorld((Integer) key);
            if (world == null) {
                return null;
            }

            ForgeChunkManager.Ticket ticket = ForgeChunkManager.requestTicket(MyTown.instance, world, ForgeChunkManager.Type.NORMAL);
            ticket.getModData().setString("townName", town.getName());
            ticket.getModData().setTag("chunkCoords", new NBTTagList());
            put((Integer) key, ticket);
            return ticket;
        } else {
            return super.get(key);
        }
    }
    return null;
}
 
Example 6
Source File: TileSpaceLaser.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * Checks to see if the situation for firing the laser exists... and changes the state accordingly
 */
public void checkCanRun() {
	//Laser requires lense, redstone power, not be jammed, and be in orbit and energy to function
	if(world.isBlockIndirectlyGettingPowered(getPos()) == 0 || !isAllowedToRun()) {
		if(laserSat.isAlive()) {
			laserSat.deactivateLaser();
		}

		setRunning(false);
	} else if(!laserSat.isAlive() && !finished && !laserSat.getJammed() && world.isBlockIndirectlyGettingPowered(getPos()) > 0 && canMachineSeeEarth()) {

		//Laser will be on at this point
		int orbitDimId = ((WorldProviderSpace)this.world.provider).getDimensionProperties(getPos()).getParentPlanet();
		if(orbitDimId == SpaceObjectManager.WARPDIMID)
			return;
		WorldServer orbitWorld = DimensionManager.getWorld(orbitDimId);

		if(orbitWorld == null) {
			DimensionManager.initDimension(orbitDimId);
			orbitWorld = DimensionManager.getWorld(orbitDimId);
			if(orbitWorld == null)
				return;
		}


		if(ticket == null) {
			ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL);
			if(ticket != null)
				ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0)));
		}

		setRunning(laserSat.activateLaser(orbitWorld, laserX, laserZ));
	}

	if(!this.world.isRemote)
		PacketHandler.sendToNearby(new PacketMachine(this, (byte)12), 128, pos, this.world.provider.getDimension());
}
 
Example 7
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 8
Source File: PacketTerminalFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	type = in.readByte();
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	fluidID = in.readInt();
	amount = in.readInt();
}
 
Example 9
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public World getImpWorld() {
    if (nmsWorld != null || getWorldName() == null) {
        return nmsWorld;
    }
    String[] split = getWorldName().split(";");
    int id = Integer.parseInt(split[split.length - 1]);
    return nmsWorld = DimensionManager.getWorld(id);
}
 
Example 10
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public World getImpWorld() {
    if (nmsWorld != null || getWorldName() == null) {
        return nmsWorld;
    }
    String[] split = getWorldName().split(";");
    int id = Integer.parseInt(split[split.length - 1]);
    nmsWorld = DimensionManager.getWorld(id);
    return nmsWorld;
}
 
Example 11
Source File: ActivationRange.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * These entities are excluded from Activation range checks.
 *
 * @param entity
 * @param world
 * @return boolean If it should always tick.
 */
public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config)
{
    // Cauldron start - another fix for Proxy Worlds
    if (config == null && DimensionManager.getWorld(0) != null)
    {
        config = DimensionManager.getWorld(0).spigotConfig;
    }
    else
    {
        return true;
    }
    // Cauldron end

    if ( ( entity.activationType == 3 && config.miscActivationRange == 0 )
            || ( entity.activationType == 2 && config.animalActivationRange == 0 )
            || ( entity.activationType == 1 && config.monsterActivationRange == 0 )
            || (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) // Cauldron
            || entity instanceof EntityThrowable
            || entity instanceof EntityDragon
            || entity instanceof EntityDragonPart
            || entity instanceof EntityWither
            || entity instanceof EntityFireball
            || entity instanceof EntityWeatherEffect
            || entity instanceof EntityTNTPrimed
            || entity instanceof EntityFallingBlock // PaperSpigot - Always tick falling blocks
            || entity instanceof EntityEnderCrystal
            || entity instanceof EntityFireworkRocket
            || entity instanceof EntityVillager
            // Cauldron start - force ticks for entities with superclass of Entity and not a creature/monster
            || (entity.getClass().getSuperclass() == Entity.class && !entity.isCreatureType(EnumCreatureType.creature, false)
            && !entity.isCreatureType(EnumCreatureType.ambient, false) && !entity.isCreatureType(EnumCreatureType.monster, false)
            && !entity.isCreatureType(EnumCreatureType.waterCreature, false)))
    {
        return true;
    }

    return false;
}
 
Example 12
Source File: SurgeryRemovePacket.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public void run()
{
	World world = DimensionManager.getWorld(dimensionId);
	TileEntity te = world.getTileEntity(pos);
	if (te instanceof TileEntitySurgery)
	{
		TileEntitySurgery surgery = (TileEntitySurgery) te;
	
		surgery.discardSlots[slotNumber] = isNull;
		
		if (isNull)
		{
			surgery.disableDependants(surgery.slotsPlayer.getStackInSlot(slotNumber),
					EnumSlot.values()[slotNumber / 10], slotNumber % LibConstants.WARE_PER_SLOT);
		}
		else
		{
			surgery.enableDependsOn(surgery.slotsPlayer.getStackInSlot(slotNumber),
					EnumSlot.values()[slotNumber / 10], slotNumber % LibConstants.WARE_PER_SLOT);
		}
		surgery.updateEssential(EnumSlot.values()[slotNumber / LibConstants.WARE_PER_SLOT]);
		surgery.updateEssence();

	}
	
	
}
 
Example 13
Source File: PacketBusFluidImport.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
	action = in.readInt();
}
 
Example 14
Source File: EntityWirelessTracker.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public void copyToDimension(int dimension)
{
    World otherWorld = DimensionManager.getWorld(dimension);
    EntityWirelessTracker copy = new EntityWirelessTracker(otherWorld, freq);
    copy.attached = true;
    copy.attachedPlayerName = attachedPlayerName;
    copy.attachedX = attachedX;
    copy.attachedY = attachedY;
    copy.attachedZ = attachedZ;
    copy.attachedYaw = attachedYaw;
    
    copy.setPosition(attachedEntity.posX, attachedEntity.posY, attachedEntity.posZ);//make sure we spawn in the right chunk :D
    
    otherWorld.spawnEntityInWorld(copy);
}
 
Example 15
Source File: MCPos.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public World getWorld(){
    return DimensionManager.getWorld(dimID);
}
 
Example 16
Source File: AbstractMessageHandler.java    From Minecoprocessors with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
private static World getWorldServer(final int dimension) {
  return DimensionManager.getWorld(dimension);
}
 
Example 17
Source File: TileRequest.java    From HoloInventory with MIT License 4 votes vote down vote up
@Override
public ResponseMessage onMessage(TileRequest message, MessageContext ctx)
{
    World world = DimensionManager.getWorld(message.dim);
    if (world == null) return null;
    TileEntity te = world.getTileEntity(message.pos);
    if (te == null) return null;

    if (Helper.banned.contains(te.getClass().getCanonicalName())) return null;
    if (te instanceof ILockableContainer && !ctx.getServerHandler().player.canOpen(((ILockableContainer) te).getLockCode())) return null;

    if (te instanceof TileEntityEnderChest)
    {
        return new PlainInventory(message.pos, ctx.getServerHandler().player.getInventoryEnderChest());
    }
    else if (te instanceof BlockJukebox.TileEntityJukebox)
    {
        InventoryBasic ib = new InventoryBasic("minecraft:jukebox", false, 1);
        ib.setInventorySlotContents(0, ((BlockJukebox.TileEntityJukebox) te).getRecord());
        return new PlainInventory(message.pos, ib).setName(Blocks.JUKEBOX.getUnlocalizedName());
    }
    else if (te instanceof TileEntityChest)
    {
        Block b = world.getBlockState(message.pos).getBlock();
        if (b instanceof BlockChest)
        {
            IInventory i = ((BlockChest) b).getLockableContainer(world, message.pos);
            if (i != null) return new PlainInventory(message.pos, i);
            return null;
        }
        return new PlainInventory(message.pos, ((TileEntityChest) te));
    }
    else if (te instanceof IInventory)
    {
        return new PlainInventory(message.pos, (IInventory) te);
    }
    else if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
    {
        IItemHandler iih = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (iih == null)
        {
            HoloInventory.getLogger().warn("Error: Block at {} (Class: {} Te: {} Block: {}) returned null after indicating the capability is available.", message.pos, te.getClass().getName(), te, te.getBlockType());
            return null;
        }
        if (te instanceof INamedItemHandler) {
        	INamedItemHandler namedHandler = (INamedItemHandler) te;
        	return new PlainInventory(message.pos, namedHandler.getItemHandlerName(), iih);
        }
        return new PlainInventory(message.pos, te.getBlockType().getUnlocalizedName(), iih);
    }

    return null;
}
 
Example 18
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 4 votes vote down vote up
public static World getWorld(int dim, boolean create) {
    if (create)
        return MinecraftServer.getServer().worldServerForDimension(dim);
    return DimensionManager.getWorld(dim);
}
 
Example 19
Source File: CommonProxy.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public long getWorldTimeUniversal(int id) {
	if(DimensionManager.getWorld(id) != null)
		return DimensionManager.getWorld(id).getTotalWorldTime();
	return 0;
}
 
Example 20
Source File: CoreCommand.java    From CodeChickenCore with MIT License 4 votes vote down vote up
public WorldServer getWorld(int dimension) {
    return DimensionManager.getWorld(dimension);
}