Search in sources :

Example 21 with WorldServer

use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.

the class TeleporterUtility method transferEntityToDimension.

/**
	 * Transfers an entity to a different dimension and location, as if it was being teleported by a dimension portal
	 */
private static boolean transferEntityToDimension(Entity entity, double x, double y, double z, float yaw, float pitch, int dimension) {
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(entity.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
    if (dstWorld != null) {
        NBTTagCompound nbttagcompound = entity.writeToNBT(new NBTTagCompound());
        nbttagcompound.removeTag("Dimension");
        srcWorld.removeEntity(entity);
        Entity newEntity = EntityList.newEntity(entity.getClass(), dstWorld);
        newEntity.readFromNBT(nbttagcompound);
        setEntityPosition(newEntity, x, y, z, yaw, pitch);
        dstWorld.spawnEntity(newEntity);
        dstWorld.updateEntityWithOptionalForce(newEntity, false);
        return true;
    } else {
        return false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 22 with WorldServer

use of net.minecraft.world.WorldServer in project VanillaTeleporter by dyeo.

the class BlockTeleporter method onEntityWalk.

@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
    TeleporterNode destinationNode = null;
    IBlockState state = world.getBlockState(pos);
    EnumType type = EnumType.byMetadata(getMetaFromState(state));
    if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
        ITeleportHandler teleportHandler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
        if (!world.isRemote) {
            if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
                teleportHandler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
                teleportHandler.setDimension(entity.dimension);
                if (teleportHandler.getOnTeleporter()) {
                    boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
                    boolean isPassive = (entity instanceof EntityAnimal);
                    if ((isHostile == false || isHostile == ModConfiguration.teleportHostileMobs) && (isPassive == false || isPassive == ModConfiguration.teleportPassiveMobs)) {
                        destinationNode = TeleporterUtility.teleport((EntityLivingBase) entity, pos);
                    }
                }
            }
        }
        if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
            TileEntityTeleporter tEnt = (TileEntityTeleporter) world.getTileEntity(pos);
            if (tEnt != null) {
                tEnt.spawnParticles();
            }
        }
        if (type.isRecall() && entity instanceof EntityPlayerMP && destinationNode != null) {
            WorldServer nextWorld = world.getMinecraftServer().worldServerForDimension(destinationNode.dimension);
            breakBlockRecall(world, nextWorld, pos, destinationNode.pos, state, (EntityPlayerMP) entity);
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) IBlockState(net.minecraft.block.state.IBlockState) TeleporterNode(net.dyeo.teleporter.teleport.TeleporterNode) ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) EntityWolf(net.minecraft.entity.passive.EntityWolf) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 23 with WorldServer

use of net.minecraft.world.WorldServer in project RFToolsDimensions by McJty.

the class DimensionEditorTileEntity method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (injectableItemStack.isEmpty()) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (dimensionItemStack.isEmpty()) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
        int id = dimensionItemStack.getTagCompound().getInteger("id");
        if (dimensionManager.getDimensionInformation(id).isCheater()) {
            ticksCost = 1;
            rfPerTick = 0;
        } else if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            if (DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_CHEATER) {
                ticksCost = 1;
                rfPerTick = 0;
            } else {
                ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
                rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
            }
        }
        ticksLeft = ticksCost;
    } else {
        int rf = getEnergyStored();
        int rfpt = rfPerTick;
        rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
        if (rf >= rfpt) {
            // Enough energy.
            consumeEnergy(rfpt);
            ticksLeft--;
            if (ticksLeft <= 0) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
                NBTTagCompound tagCompound = dimensionItemStack.getTagCompound();
                int id = tagCompound.getInteger("id");
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = RfToolsDimensionManager.getWorldForDimension(getWorld(), id);
                    int y = findGoodReceiverLocation(dimWorld);
                    if (y == -1) {
                        y = dimWorld.getHeight() / 2;
                    }
                    Item item = injectableItemStack.getItem();
                    if (item instanceof ItemBlock) {
                        ItemBlock itemBlock = (ItemBlock) item;
                        IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
                        BlockPos pos = new BlockPos(8, y, 8);
                        dimWorld.setBlockState(pos, state, 2);
                        Block block = dimWorld.getBlockState(pos).getBlock();
                        // @todo @@@@@@@@@@@@@@ check if right?
                        block.onBlockActivated(dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.0F, 0.0F, 0.0F);
                        // block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
                        block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
                        dimWorld.setBlockToAir(pos.up());
                        dimWorld.setBlockToAir(pos.up(2));
                    }
                } else if (isTNT(injectableItemStack)) {
                    safeDeleteDimension(id, dimensionItemStack);
                } else {
                    DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
                    DimensionInformation information = dimensionManager.getDimensionInformation(id);
                    information.injectDimlet(key);
                    dimensionManager.save(getWorld());
                }
                inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
                stopInjecting();
            }
        }
    }
    markDirty();
    setState();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) World(net.minecraft.world.World) ItemBlock(net.minecraft.item.ItemBlock) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) Settings(mcjty.rftoolsdim.config.Settings)

Example 24 with WorldServer

use of net.minecraft.world.WorldServer in project RFToolsDimensions by McJty.

the class RfToolsDimensionManager method touchSpawnChunk.

private void touchSpawnChunk(World world, int id) {
    // Make sure world generation kicks in for at least one chunk so that our matter receiver
    // is generated and registered.
    WorldServer worldServerForDimension = world.getMinecraftServer().getWorld(id);
    ChunkProviderServer providerServer = worldServerForDimension.getChunkProvider();
    if (!providerServer.chunkExists(0, 0)) {
        try {
            providerServer.provideChunk(0, 0);
            providerServer.chunkGenerator.populate(0, 0);
        } catch (Exception e) {
            Logging.logError("Something went wrong during creation of the dimension!");
            e.printStackTrace();
        // We catch this exception to make sure our dimension tab is at least ok.
        }
    }
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) WorldServer(net.minecraft.world.WorldServer)

Example 25 with WorldServer

use of net.minecraft.world.WorldServer in project MorePlanets by SteveKunG.

the class TeleportUtil method teleportEntityInternational.

private static Entity teleportEntityInternational(Entity entity, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch) {
    if (entity.isDead) {
        return null;
    }
    WorldServer sourceWorld = server.getWorld(sourceDim);
    WorldServer targetWorld = server.getWorld(targetDim);
    // Set the entity dead before calling changeDimension. Still need to call changeDimension for things like minecarts which will drop their contents otherwise.
    if (!entity.isDead && entity instanceof EntityMinecart) {
        entity.isDead = true;
        entity.changeDimension(targetDim);
        entity.isDead = false;
    }
    entity.dimension = targetDim;
    sourceWorld.removeEntity(entity);
    entity.isDead = false;
    entity.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
    sourceWorld.updateEntityWithOptionalForce(entity, false);
    Entity newEntity = EntityList.newEntity(entity.getClass(), targetWorld);
    if (newEntity != null) {
        newEntity.copyDataFromOld(entity);
        newEntity.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
        boolean flag = newEntity.forceSpawn;
        newEntity.forceSpawn = true;
        targetWorld.spawnEntity(newEntity);
        newEntity.forceSpawn = flag;
        targetWorld.updateEntityWithOptionalForce(newEntity, false);
    }
    entity.isDead = true;
    sourceWorld.resetUpdateEntityTick();
    targetWorld.resetUpdateEntityTick();
    return newEntity;
}
Also used : Entity(net.minecraft.entity.Entity) WorldServer(net.minecraft.world.WorldServer) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Aggregations

WorldServer (net.minecraft.world.WorldServer)322 BlockPos (net.minecraft.util.math.BlockPos)96 EntityPlayer (net.minecraft.entity.player.EntityPlayer)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)51 ItemStack (net.minecraft.item.ItemStack)48 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)48 TileEntity (net.minecraft.tileentity.TileEntity)42 Entity (net.minecraft.entity.Entity)41 IBlockState (net.minecraft.block.state.IBlockState)39 MinecraftServer (net.minecraft.server.MinecraftServer)35 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)31 World (net.minecraft.world.World)29 Block (net.minecraft.block.Block)26 EntityLivingBase (net.minecraft.entity.EntityLivingBase)23 ArrayList (java.util.ArrayList)20 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 Nullable (javax.annotation.Nullable)17 PotionEffect (net.minecraft.potion.PotionEffect)16 Chunk (net.minecraft.world.chunk.Chunk)16 World (org.spongepowered.api.world.World)13