net.minecraft.world.gen.structure.template.PlacementSettings Java Examples

The following examples show how to use net.minecraft.world.gen.structure.template.PlacementSettings. 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: WorldGenAbandonedBase.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
    if (ConfigHolder.abandonedBaseRarity == 0 ||
        world.getWorldType() == WorldType.FLAT ||
        world.provider.getDimensionType() != DimensionType.OVERWORLD ||
        !world.getWorldInfo().isMapFeaturesEnabled()) {
        return; //do not generate in flat worlds, or in non-surface worlds
    }
    BlockPos randomPos = new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8);

    if (random.nextInt(ConfigHolder.abandonedBaseRarity) == 0) {
        int variantNumber = random.nextInt(3);
        Rotation rotation = Rotation.values()[random.nextInt(Rotation.values().length)];
        ResourceLocation templateId = new ResourceLocation(GTValues.MODID, "abandoned_base/abandoned_base_1_" + variantNumber);
        Template template = TemplateManager.getBuiltinTemplate(world, templateId);
        BlockPos originPos = template.getZeroPositionWithTransform(randomPos, Mirror.NONE, rotation);
        originPos = TemplateManager.calculateAverageGroundLevel(world, originPos, template.getSize());
        template.addBlocksToWorld(world, originPos, new PlacementSettings().setRotation(rotation));
    }
}
 
Example #2
Source File: StructureLoader.java    From YUNoMakeGoodMap with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(World world, BlockPos pos)
{
    PlacementSettings settings = new PlacementSettings();
    Template temp = null;
    String suffix = world.provider.getDimensionType().getSuffix();
    String opts = world.getWorldInfo().getGeneratorOptions() + suffix;

    if (!Strings.isNullOrEmpty(opts))
        temp = StructureUtil.loadTemplate(new ResourceLocation(opts), (WorldServer)world, true);
    if (temp == null)
        temp = StructureUtil.loadTemplate(new ResourceLocation("/config/", this.fileName + suffix), (WorldServer)world, !Strings.isNullOrEmpty(suffix));
    if (temp == null)
        return; //If we're not in the overworld, and we don't have a template...

    BlockPos spawn = StructureUtil.findSpawn(temp, settings);
    if (spawn != null)
    {
        pos = pos.subtract(spawn);
        world.setSpawnPoint(pos);
    }

    temp.addBlocksToWorld(world, pos, settings, 0); //Push to world, with no neighbor notifications!
    world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
}
 
Example #3
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private PlacementSettings getPasteModePlacement(ItemStack stack, EntityPlayer player)
{
    EnumFacing facing = this.getTemplateFacing(stack);
    EnumFacing areaFacing = this.getAreaFacing(stack, Mode.PASTE);

    if (areaFacing == null)
    {
        areaFacing = facing;
    }

    Rotation rotation = PositionUtils.getRotation(facing, areaFacing);
    PlacementSettings placement = new PlacementSettings();
    boolean ignoreEntities = player.capabilities.isCreativeMode == false ||
            WandOption.AFFECT_ENTITIES.isEnabled(stack, Mode.PASTE) == false;
    placement.setMirror(this.getMirror(stack));
    placement.setRotation(rotation);
    placement.setIgnoreEntities(ignoreEntities);

    return placement;
}
 
Example #4
Source File: NewSpawnPlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length != 2)
        throw new WrongUsageException(getUsage(sender));

    EntityPlayer player = getPlayer(server, sender, args[1]);

    if (player != null)
    {
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer) sender.getEntityWorld();

        int platformNumber = SpawnPlatformSavedData.get(world).addAndGetPlatformNumber();
        BlockPos pos = getPositionOfPlatform(world, platformNumber);

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[0]), world, true);
        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        spawn = spawn == null ? pos : spawn.add(pos);

        sender.sendMessage(new TextComponentString("Building \"" + args[0] + "\" at " + pos.toString()));
        temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
        world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!

        if (player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) player).setPositionAndUpdate(spawn.getX() + 0.5, spawn.getY() + 1.6, spawn.getZ() + 0.5);
        }

        player.setSpawnChunk(spawn, true, world.provider.getDimension());
    }
    else
    {
        throw new WrongUsageException(getUsage(sender));
    }
}
 
Example #5
Source File: StructureUtil.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
public static BlockPos findSpawn(Template temp, PlacementSettings settings)
{
    for (Entry<BlockPos, String> e : temp.getDataBlocks(new BlockPos(0,0,0), settings).entrySet())
    {
        if ("SPAWN_POINT".equals(e.getValue()))
            return e.getKey();
    }
    return null;
}
 
Example #6
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private TemplateEnderUtilities getTemplate(World world, EntityPlayer player, ItemStack stack, PlacementSettings placement)
{
    TemplateManagerEU templateManager = this.getTemplateManager();
    ResourceLocation rl = this.getTemplateResource(stack, player);
    TemplateEnderUtilities template = templateManager.getTemplate(rl);
    template.setPlacementSettings(placement);

    return template;
}
 
Example #7
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void moveAreaImmediate(ItemStack stack, World world, EntityPlayer player, BlockPos posSrc1, BlockPos posSrc2, BlockPos posDst1,
        Mirror mirror, Rotation rotation)
{
    PlacementSettings placement = new PlacementSettings();
    placement.setMirror(mirror);
    placement.setRotation(rotation);
    placement.setIgnoreEntities(false);
    placement.setReplacedBlock(Blocks.BARRIER); // meh

    ReplaceMode replace = WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.MOVE_DST) ? ReplaceMode.EVERYTHING : ReplaceMode.NOTHING;
    TemplateEnderUtilities template = new TemplateEnderUtilities(placement, replace);
    template.takeBlocksFromWorld(world, posSrc1, posSrc2.subtract(posSrc1), true, false);
    this.deleteArea(stack, world, player, posSrc1, posSrc2, true);
    template.addBlocksToWorld(world, posDst1);
}
 
Example #8
Source File: SchematicPlacement.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PlacementSettings getPlacementSettings()
{
    PlacementSettings placement = new PlacementSettings();

    placement.setMirror(this.mirror);
    placement.setRotation(this.rotation);
    placement.setIgnoreEntities(this.ignoreEntities);
    placement.setReplacedBlock(Blocks.STRUCTURE_VOID);

    return placement;
}
 
Example #9
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult stackArea(ItemStack stack, World world, EntityPlayer player, BlockPosEU pos1EU, BlockPosEU pos2EU)
{
    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnableStackMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    if (pos1EU == null || pos2EU == null)
    {
        return EnumActionResult.FAIL;
    }

    int dim = world.provider.getDimension();
    BlockPos pos1 = pos1EU.toBlockPos();
    BlockPos pos2 = pos2EU.toBlockPos();
    BlockPos endPosRelative = pos2.subtract(pos1);
    Area3D area = Area3D.getAreaFromNBT(this.getAreaTag(stack));

    if (pos1EU.getDimension() != dim || pos2EU.getDimension() != dim ||
        this.isStackedAreaWithinLimits(pos1, pos2, endPosRelative, area, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolargeortoofar"), true);
        return EnumActionResult.FAIL;
    }

    boolean takeEntities = player.capabilities.isCreativeMode && WandOption.AFFECT_ENTITIES.isEnabled(stack);
    PlacementSettings placement = new PlacementSettings();
    placement.setIgnoreEntities(takeEntities == false);
    ReplaceMode replaceMode = WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.STACK) ? ReplaceMode.WITH_NON_AIR : ReplaceMode.NOTHING;
    TemplateEnderUtilities template = new TemplateEnderUtilities(placement, replaceMode);
    template.takeBlocksFromWorld(world, pos1, pos2.subtract(pos1), takeEntities, false);

    if (player.capabilities.isCreativeMode)
    {
        this.stackAreaImmediate(world, pos1, endPosRelative, area, template);
    }
    else
    {
        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskStackArea task = new TaskStackArea(world, wandUUID, pos1, endPosRelative, template, area, Configs.buildersWandBlocksPerTick);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);
    }

    return EnumActionResult.SUCCESS;
}
 
Example #10
Source File: TaskStackArea.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(World world, EntityPlayer player)
{
    ItemStack stack = EntityUtils.getHeldItemOfType(player, EnderUtilitiesItems.BUILDERS_WAND);

    if (stack.isEmpty() == false && this.wandUUID.equals(NBTUtils.getUUIDFromItemStack(stack, ItemBuildersWand.WRAPPER_TAG_NAME, false)))
    {
        ItemBuildersWand wand = (ItemBuildersWand) stack.getItem();
        PlacementSettings placement = this.template.getPlacementSettings();

        for (int placedThisTick = 0 ; placedThisTick < this.blocksPerTick && this.listIndex < this.templateNumBlocks; )
        {
            TemplateBlockInfo blockInfo = this.template.getBlockList().get(this.listIndex);
            IBlockState state = blockInfo.blockState.withMirror(placement.getMirror()).withRotation(placement.getRotation());
            BlockPos pos = TemplateEnderUtilities.transformedBlockPos(placement, blockInfo.pos).add(this.currentStartPos);

            if (wand.placeBlockToPosition(stack, world, player, pos, EnumFacing.UP, state, 2, true, true))
            {
                this.placedCount += 1;
                this.failCount = 0;
                placedThisTick += 1;
            }

            this.listIndex += 1;

            // Finished looping through the block positions
            if (this.listIndex >= this.templateNumBlocks)
            {
                this.listIndex = 0;

                // Finished iterating through all the stacked areas
                if (this.incrementArea() == false)
                {
                    world.playSound(null, player.getPosition(), SoundEvents.BLOCK_NOTE_PLING, SoundCategory.BLOCKS, 0.6f, 1.0f);
                    return true;
                }
            }
        }
    }
    else
    {
        this.failCount += 1;
    }

    // Bail out after 10 seconds of failing to execute, or after all blocks have been placed
    if (this.failCount > 200)
    {
        world.playSound(null, player.getPosition(), SoundEvents.BLOCK_NOTE_BASEDRUM, SoundCategory.BLOCKS, 0.6f, 1.0f);
        return true;
    }

    return false;
}
 
Example #11
Source File: TaskTemplatePlaceBlocks.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(World world, EntityPlayer player)
{
    ItemStack stack = EntityUtils.getHeldItemOfType(player, EnderUtilitiesItems.BUILDERS_WAND);

    if (stack.isEmpty() == false && this.wandUUID.equals(NBTUtils.getUUIDFromItemStack(stack, ItemBuildersWand.WRAPPER_TAG_NAME, false)))
    {
        ItemBuildersWand wand = (ItemBuildersWand) stack.getItem();
        PlacementSettings placement = this.template.getPlacementSettings();

        for (int i = 0; i < this.blocksPerTick && this.listIndex < this.template.getBlockList().size();)
        {
            TemplateBlockInfo blockInfo = this.template.getBlockList().get(this.listIndex);
            IBlockState state = blockInfo.blockState.withMirror(placement.getMirror()).withRotation(placement.getRotation());
            BlockPos pos = TemplateEnderUtilities.transformedBlockPos(placement, blockInfo.pos).add(this.posStart);

            if (wand.placeBlockToPosition(stack, world, player, pos, EnumFacing.UP, state, 2, true, true))
            {
                this.placedCount += 1;
                this.failCount = 0;
                i += 1;
            }

            this.listIndex += 1;
        }
    }
    else
    {
        this.failCount += 1;
    }

    // Bail out after 10 seconds of failing to execute, or after all blocks have been placed
    if (this.failCount > 200)
    {
        world.playSound(null, player.getPosition(), SoundEvents.BLOCK_NOTE_PLING, SoundCategory.BLOCKS, 0.6f, 1.0f);

        return true;
    }

    // Finished looping through the block positions
    if (this.listIndex >= this.template.getBlockList().size())
    {
        //this.template.notifyBlocks(world, this.posStart);
        this.template.addEntitiesToWorld(world, this.posStart);

        world.playSound(null, player.getPosition(), SoundEvents.BLOCK_NOTE_PLING, SoundCategory.BLOCKS, 0.6f, 1.0f);

        return true;
    }

    return false;
}
 
Example #12
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TemplateEnderUtilities(PlacementSettings placement, ReplaceMode replaceMode)
{
    this.placement = placement;
    this.replaceMode = replaceMode;
}
 
Example #13
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPlacementSettings(PlacementSettings placement)
{
    this.placement = placement;
}
 
Example #14
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PlacementSettings getPlacementSettings()
{
    return this.placement;
}
 
Example #15
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static BlockPos transformedBlockPos(PlacementSettings placement, BlockPos pos)
{
    return PositionUtils.getTransformedBlockPos(pos, placement.getMirror(), placement.getRotation());
}
 
Example #16
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult pasteAreaIntoWorld(ItemStack stack, World world, EntityPlayer player, BlockPosEU posStartIn)
{
    if (posStartIn == null)
    {
        return EnumActionResult.FAIL;
    }

    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnablePasteMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    if (posStartIn.isWithinDistance(player, 160) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoofar"), true);
        return EnumActionResult.FAIL;
    }

    TemplateMetadata templateMeta = this.getTemplateMetadata(stack, player);

    if (this.isAreaWithinSizeLimit(templateMeta.getRelativeEndPosition(), stack, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolarge", this.getMaxAreaDimension(stack, player)), true);
        return EnumActionResult.FAIL;
    }

    PlacementSettings placement = this.getPasteModePlacement(stack, player);
    TemplateEnderUtilities template = this.getTemplate(world, player, stack, placement);

    if (player.capabilities.isCreativeMode)
    {
        template.setReplaceMode(WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.PASTE) ? ReplaceMode.EVERYTHING : ReplaceMode.NOTHING);
        template.addBlocksToWorld(world, posStartIn.toBlockPos());
    }
    else
    {
        template.setReplaceMode(WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.PASTE) ? ReplaceMode.WITH_NON_AIR : ReplaceMode.NOTHING);

        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskTemplatePlaceBlocks task = new TaskTemplatePlaceBlocks(template, posStartIn.toBlockPos(), world.provider.getDimension(),
                player.getUniqueID(), wandUUID, Configs.buildersWandBlocksPerTick);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);
    }

    return EnumActionResult.SUCCESS;
}
 
Example #17
Source File: PlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}
 
Example #18
Source File: TofuCastlePiece.java    From TofuCraftReload with MIT License 4 votes vote down vote up
private void loadTemplate(TemplateManager manager) {
    Template template = manager.getTemplate(null, new ResourceLocation(TofuMain.MODID, "tofucastle/" + this.templateName));
    PlacementSettings placementsettings = (new PlacementSettings()).setIgnoreEntities(true).setRotation(this.rotation).setMirror(this.mirror);
    this.setup(template, this.templatePosition, placementsettings);
}