Java Code Examples for net.minecraft.world.World.getMinecraftServer()

The following are Jave code examples for showing how to use getMinecraftServer() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Backmemed   File: ItemMonsterPlacer.java   Source Code and License Vote up 6 votes
/**
 * Applies the data in the EntityTag tag of the given ItemStack to the given Entity.
 */
public static void applyItemEntityDataToEntity(World entityWorld, @Nullable EntityPlayer player, ItemStack stack, @Nullable Entity targetEntity)
{
    MinecraftServer minecraftserver = entityWorld.getMinecraftServer();

    if (minecraftserver != null && targetEntity != null)
    {
        NBTTagCompound nbttagcompound = stack.getTagCompound();

        if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
        {
            if (!entityWorld.isRemote && targetEntity.ignoreItemEntityData() && (player == null || !minecraftserver.getPlayerList().canSendCommands(player.getGameProfile())))
            {
                return;
            }

            NBTTagCompound nbttagcompound1 = targetEntity.writeToNBT(new NBTTagCompound());
            UUID uuid = targetEntity.getUniqueID();
            nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
            targetEntity.setUniqueId(uuid);
            targetEntity.readFromNBT(nbttagcompound1);
        }
    }
}
 
Example 2
Project: CustomWorldGen   File: ItemMonsterPlacer.java   Source Code and License Vote up 6 votes
/**
 * Applies the data in the EntityTag tag of the given ItemStack to the given Entity.
 */
public static void applyItemEntityDataToEntity(World entityWorld, @Nullable EntityPlayer player, ItemStack stack, @Nullable Entity targetEntity)
{
    MinecraftServer minecraftserver = entityWorld.getMinecraftServer();

    if (minecraftserver != null && targetEntity != null)
    {
        NBTTagCompound nbttagcompound = stack.getTagCompound();

        if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
        {
            if (!entityWorld.isRemote && targetEntity.ignoreItemEntityData() && (player == null || !minecraftserver.getPlayerList().canSendCommands(player.getGameProfile())))
            {
                return;
            }

            NBTTagCompound nbttagcompound1 = targetEntity.writeToNBT(new NBTTagCompound());
            UUID uuid = targetEntity.getUniqueID();
            nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
            targetEntity.setUniqueId(uuid);
            targetEntity.readFromNBT(nbttagcompound1);
        }
    }
}
 
Example 3
Project: MeeCreeps   File: ActionOptions.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public EntityPlayer getPlayer() {
    if (playerId == null) {
        return null;
    }
    World world = DimensionManager.getWorld(0);
    MinecraftServer server = world.getMinecraftServer();
    return server.getPlayerList().getPlayerByUUID(playerId);
}
 
Example 4
Project: Backmemed   File: WorldGenFossils.java   Source Code and License Vote up 5 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    Random random = worldIn.getChunkFromBlockCoords(position).getRandomWithSeed(987234911L);
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();
    Rotation[] arotation = Rotation.values();
    Rotation rotation = arotation[random.nextInt(arotation.length)];
    int i = random.nextInt(FOSSILS.length);
    TemplateManager templatemanager = worldIn.getSaveHandler().getStructureTemplateManager();
    Template template = templatemanager.getTemplate(minecraftserver, FOSSILS[i]);
    Template template1 = templatemanager.getTemplate(minecraftserver, FOSSILS_COAL[i]);
    ChunkPos chunkpos = new ChunkPos(position);
    StructureBoundingBox structureboundingbox = new StructureBoundingBox(chunkpos.getXStart(), 0, chunkpos.getZStart(), chunkpos.getXEnd(), 256, chunkpos.getZEnd());
    PlacementSettings placementsettings = (new PlacementSettings()).setRotation(rotation).setBoundingBox(structureboundingbox).setRandom(random);
    BlockPos blockpos = template.transformedSize(rotation);
    int j = random.nextInt(16 - blockpos.getX());
    int k = random.nextInt(16 - blockpos.getZ());
    int l = 256;

    for (int i1 = 0; i1 < blockpos.getX(); ++i1)
    {
        for (int j1 = 0; j1 < blockpos.getX(); ++j1)
        {
            l = Math.min(l, worldIn.getHeight(position.getX() + i1 + j, position.getZ() + j1 + k));
        }
    }

    int k1 = Math.max(l - 15 - random.nextInt(10), 10);
    BlockPos blockpos1 = template.getZeroPositionWithTransform(position.add(j, k1, k), Mirror.NONE, rotation);
    placementsettings.setIntegrity(0.9F);
    template.addBlocksToWorld(worldIn, blockpos1, placementsettings, 20);
    placementsettings.setIntegrity(0.1F);
    template1.addBlocksToWorld(worldIn, blockpos1, placementsettings, 20);
    return true;
}
 
Example 5
Project: CustomWorldGen   File: WorldGenFossils.java   Source Code and License Vote up 5 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    Random random = worldIn.getChunkFromChunkCoords(position.getX(), position.getZ()).getRandomWithSeed(987234911L);
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();
    Rotation[] arotation = Rotation.values();
    Rotation rotation = arotation[random.nextInt(arotation.length)];
    int i = random.nextInt(FOSSILS.length);
    TemplateManager templatemanager = worldIn.getSaveHandler().getStructureTemplateManager();
    Template template = templatemanager.getTemplate(minecraftserver, FOSSILS[i]);
    Template template1 = templatemanager.getTemplate(minecraftserver, FOSSILS_COAL[i]);
    ChunkPos chunkpos = new ChunkPos(position);
    StructureBoundingBox structureboundingbox = new StructureBoundingBox(chunkpos.getXStart(), 0, chunkpos.getZStart(), chunkpos.getXEnd(), 256, chunkpos.getZEnd());
    PlacementSettings placementsettings = (new PlacementSettings()).setRotation(rotation).setBoundingBox(structureboundingbox).setRandom(random);
    BlockPos blockpos = template.transformedSize(rotation);
    int j = random.nextInt(16 - blockpos.getX());
    int k = random.nextInt(16 - blockpos.getZ());
    int l = 256;

    for (int i1 = 0; i1 < blockpos.getX(); ++i1)
    {
        for (int j1 = 0; j1 < blockpos.getX(); ++j1)
        {
            l = Math.min(l, worldIn.getHeightmapHeight(position.getX() + i1 + j, position.getZ() + j1 + k));
        }
    }

    int k1 = Math.max(l - 15 - random.nextInt(10), 10);
    BlockPos blockpos1 = template.getZeroPositionWithTransform(position.add(j, k1, k), Mirror.NONE, rotation);
    placementsettings.setIntegrity(0.9F);
    template.addBlocksToWorld(worldIn, blockpos1, placementsettings, 4);
    placementsettings.setIntegrity(0.1F);
    template1.addBlocksToWorld(worldIn, blockpos1, placementsettings, 4);
    return true;
}
 
Example 6
Project: Backmemed   File: ComponentScatteredFeaturePieces.java   Source Code and License Vote up 4 votes
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
    if (!this.offsetToAverageGroundLevel(worldIn, structureBoundingBoxIn, -1))
    {
        return false;
    }
    else
    {
        StructureBoundingBox structureboundingbox = this.getBoundingBox();
        BlockPos blockpos = new BlockPos(structureboundingbox.minX, structureboundingbox.minY, structureboundingbox.minZ);
        Rotation[] arotation = Rotation.values();
        MinecraftServer minecraftserver = worldIn.getMinecraftServer();
        TemplateManager templatemanager = worldIn.getSaveHandler().getStructureTemplateManager();
        PlacementSettings placementsettings = (new PlacementSettings()).setRotation(arotation[randomIn.nextInt(arotation.length)]).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(structureboundingbox);
        Template template = templatemanager.getTemplate(minecraftserver, IGLOO_TOP_ID);
        template.addBlocksToWorldChunk(worldIn, blockpos, placementsettings);

        if (randomIn.nextDouble() < 0.5D)
        {
            Template template1 = templatemanager.getTemplate(minecraftserver, IGLOO_MIDDLE_ID);
            Template template2 = templatemanager.getTemplate(minecraftserver, IGLOO_BOTTOM_ID);
            int i = randomIn.nextInt(8) + 4;

            for (int j = 0; j < i; ++j)
            {
                BlockPos blockpos1 = template.calculateConnectedPos(placementsettings, new BlockPos(3, -1 - j * 3, 5), placementsettings, new BlockPos(1, 2, 1));
                template1.addBlocksToWorldChunk(worldIn, blockpos.add(blockpos1), placementsettings);
            }

            BlockPos blockpos4 = blockpos.add(template.calculateConnectedPos(placementsettings, new BlockPos(3, -1 - i * 3, 5), placementsettings, new BlockPos(3, 5, 7)));
            template2.addBlocksToWorldChunk(worldIn, blockpos4, placementsettings);
            Map<BlockPos, String> map = template2.getDataBlocks(blockpos4, placementsettings);

            for (Entry<BlockPos, String> entry : map.entrySet())
            {
                if ("chest".equals(entry.getValue()))
                {
                    BlockPos blockpos2 = (BlockPos)entry.getKey();
                    worldIn.setBlockState(blockpos2, Blocks.AIR.getDefaultState(), 3);
                    TileEntity tileentity = worldIn.getTileEntity(blockpos2.down());

                    if (tileentity instanceof TileEntityChest)
                    {
                        ((TileEntityChest)tileentity).setLootTable(LootTableList.CHESTS_IGLOO_CHEST, randomIn.nextLong());
                    }
                }
            }
        }
        else
        {
            BlockPos blockpos3 = Template.transformedBlockPos(placementsettings, new BlockPos(3, 0, 5));
            worldIn.setBlockState(blockpos.add(blockpos3), Blocks.SNOW.getDefaultState(), 3);
        }

        return true;
    }
}
 
Example 7
Project: Backmemed   File: ItemBlock.java   Source Code and License Vote up 4 votes
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();

    if (minecraftserver == null)
    {
        return false;
    }
    else
    {
        NBTTagCompound nbttagcompound = stackIn.getSubCompound("BlockEntityTag");

        if (nbttagcompound != null)
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity != null)
            {
                if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
                {
                    return false;
                }

                NBTTagCompound nbttagcompound1 = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound2 = nbttagcompound1.copy();
                nbttagcompound1.merge(nbttagcompound);
                nbttagcompound1.setInteger("x", pos.getX());
                nbttagcompound1.setInteger("y", pos.getY());
                nbttagcompound1.setInteger("z", pos.getZ());

                if (!nbttagcompound1.equals(nbttagcompound2))
                {
                    tileentity.readFromNBT(nbttagcompound1);
                    tileentity.markDirty();
                    return true;
                }
            }
        }

        return false;
    }
}
 
Example 8
Project: CustomWorldGen   File: ComponentScatteredFeaturePieces.java   Source Code and License Vote up 4 votes
/**
 * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes
 * Mineshafts at the end, it adds Fences...
 */
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
    if (!this.offsetToAverageGroundLevel(worldIn, structureBoundingBoxIn, -1))
    {
        return false;
    }
    else
    {
        StructureBoundingBox structureboundingbox = this.getBoundingBox();
        BlockPos blockpos = new BlockPos(structureboundingbox.minX, structureboundingbox.minY, structureboundingbox.minZ);
        Rotation[] arotation = Rotation.values();
        MinecraftServer minecraftserver = worldIn.getMinecraftServer();
        TemplateManager templatemanager = worldIn.getSaveHandler().getStructureTemplateManager();
        PlacementSettings placementsettings = (new PlacementSettings()).setRotation(arotation[randomIn.nextInt(arotation.length)]).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(structureboundingbox);
        Template template = templatemanager.getTemplate(minecraftserver, IGLOO_TOP_ID);
        template.addBlocksToWorldChunk(worldIn, blockpos, placementsettings);

        if (randomIn.nextDouble() < 0.5D)
        {
            Template template1 = templatemanager.getTemplate(minecraftserver, IGLOO_MIDDLE_ID);
            Template template2 = templatemanager.getTemplate(minecraftserver, IGLOO_BOTTOM_ID);
            int i = randomIn.nextInt(8) + 4;

            for (int j = 0; j < i; ++j)
            {
                BlockPos blockpos1 = template.calculateConnectedPos(placementsettings, new BlockPos(3, -1 - j * 3, 5), placementsettings, new BlockPos(1, 2, 1));
                template1.addBlocksToWorldChunk(worldIn, blockpos.add(blockpos1), placementsettings);
            }

            BlockPos blockpos4 = blockpos.add(template.calculateConnectedPos(placementsettings, new BlockPos(3, -1 - i * 3, 5), placementsettings, new BlockPos(3, 5, 7)));
            template2.addBlocksToWorldChunk(worldIn, blockpos4, placementsettings);
            Map<BlockPos, String> map = template2.getDataBlocks(blockpos4, placementsettings);

            for (Entry<BlockPos, String> entry : map.entrySet())
            {
                if ("chest".equals(entry.getValue()))
                {
                    BlockPos blockpos2 = (BlockPos)entry.getKey();
                    worldIn.setBlockState(blockpos2, Blocks.AIR.getDefaultState(), 3);
                    TileEntity tileentity = worldIn.getTileEntity(blockpos2.down());

                    if (tileentity instanceof TileEntityChest)
                    {
                        ((TileEntityChest)tileentity).setLootTable(LootTableList.CHESTS_IGLOO_CHEST, randomIn.nextLong());
                    }
                }
            }
        }
        else
        {
            BlockPos blockpos3 = Template.transformedBlockPos(placementsettings, new BlockPos(3, 0, 5));
            worldIn.setBlockState(blockpos.add(blockpos3), Blocks.SNOW.getDefaultState(), 3);
        }

        return true;
    }
}
 
Example 9
Project: CustomWorldGen   File: ItemBlock.java   Source Code and License Vote up 4 votes
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();

    if (minecraftserver == null)
    {
        return false;
    }
    else
    {
        if (stackIn.hasTagCompound() && stackIn.getTagCompound().hasKey("BlockEntityTag", 10))
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity != null)
            {
                if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
                {
                    return false;
                }

                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2 = (NBTTagCompound)stackIn.getTagCompound().getTag("BlockEntityTag");
                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", pos.getX());
                nbttagcompound.setInteger("y", pos.getY());
                nbttagcompound.setInteger("z", pos.getZ());

                if (!nbttagcompound.equals(nbttagcompound1))
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    return true;
                }
            }
        }

        return false;
    }
}