Search in sources :

Example 1 with StructureAlternateStart

use of com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart in project MC-Prefab by Brian-Wuest.

the class GuiStartHouseChooser method actionPerformed.

/**
 * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
 */
@Override
protected void actionPerformed(GuiButton button) throws IOException {
    if (button == this.btnCancel || button == this.btnVisualize || button == this.btnBuild) {
        this.houseConfiguration.addBed = this.serverConfiguration.addBed && this.btnAddBed.isChecked();
        this.houseConfiguration.addChest = this.serverConfiguration.addChests && this.btnAddChest.isChecked();
        this.houseConfiguration.addChestContents = this.allowItemsInChestAndFurnace ? this.serverConfiguration.addChestContents && this.btnAddChestContents.isChecked() : false;
        this.houseConfiguration.addCraftingTable = this.serverConfiguration.addCraftingTable && this.btnAddCraftingTable.isChecked();
        this.houseConfiguration.addFurnace = this.serverConfiguration.addFurnace && this.btnAddFurnace.isChecked();
        this.houseConfiguration.addFarm = this.serverConfiguration.addFarm && this.btnAddFarm.isChecked();
        this.houseConfiguration.addMineShaft = this.serverConfiguration.addMineshaft && this.btnAddMineShaft.isChecked();
        this.houseConfiguration.addTorches = this.serverConfiguration.addTorches && this.btnAddTorches.isChecked();
        this.houseConfiguration.isCeilingFlat = this.btnIsCeilingFlat.isChecked();
        this.houseConfiguration.ceilingBlock = ModConfiguration.CeilingFloorBlockType.ValueOf(this.btnCeilingBlock.getValueInt());
        this.houseConfiguration.floorBlock = ModConfiguration.CeilingFloorBlockType.ValueOf(this.btnFloorBlock.getValueInt());
        this.houseConfiguration.wallWoodType = ModConfiguration.WallBlockType.ValueOf(this.btnWallWoodType.getValueInt());
        this.houseConfiguration.houseDepth = this.btnHouseDepth.getValueInt();
        this.houseConfiguration.houseWidth = this.btnHouseWidth.getValueInt();
        this.houseConfiguration.houseStyle = this.houseConfiguration.houseStyle;
        this.houseConfiguration.houseFacing = this.mc.player.getHorizontalFacing().getOpposite();
    }
    if (button == this.btnCancel) {
        this.mc.displayGuiScreen(null);
    } else if (button == this.btnBuild) {
        Prefab.network.sendToServer(new StructureTagMessage(houseConfiguration.WriteToNBTTagCompound(), EnumStructureConfiguration.StartHouse));
        this.mc.displayGuiScreen(null);
    } else if (button == this.btnHouseStyle) {
        int id = this.houseConfiguration.houseStyle.getValue() + 1;
        this.houseConfiguration.houseStyle = HouseConfiguration.HouseStyle.ValueOf(id);
        // Skip the loft if it's not enabled.
        if (this.houseConfiguration.houseStyle == HouseStyle.LOFT && !this.serverConfiguration.enableLoftHouse) {
            id = this.houseConfiguration.houseStyle.getValue() + 1;
            this.houseConfiguration.houseStyle = HouseConfiguration.HouseStyle.ValueOf(id);
        }
        this.btnHouseStyle.displayString = this.houseConfiguration.houseStyle.getDisplayName();
        // Set the default glass colors for this style.
        if (this.houseConfiguration.houseStyle == HouseConfiguration.HouseStyle.HOBBIT) {
            this.houseConfiguration.glassColor = EnumDyeColor.GREEN;
            this.btnGlassColor.displayString = GuiLangKeys.translateDye(EnumDyeColor.GREEN);
        } else if (this.houseConfiguration.houseStyle == HouseConfiguration.HouseStyle.LOFT) {
            this.houseConfiguration.glassColor = EnumDyeColor.BLACK;
            this.btnGlassColor.displayString = GuiLangKeys.translateDye(EnumDyeColor.BLACK);
        } else {
            this.houseConfiguration.glassColor = EnumDyeColor.CYAN;
            this.btnGlassColor.displayString = GuiLangKeys.translateDye(EnumDyeColor.CYAN);
        }
        if (this.houseConfiguration.houseStyle == HouseConfiguration.HouseStyle.DESERT || this.houseConfiguration.houseStyle == HouseConfiguration.HouseStyle.SNOWY) {
            this.tabBlockTypes.visible = false;
        } else {
            this.tabBlockTypes.visible = true;
        }
    } else if (button == this.btnGlassColor) {
        this.houseConfiguration.glassColor = EnumDyeColor.byMetadata(this.houseConfiguration.glassColor.getMetadata() + 1);
        this.btnGlassColor.displayString = GuiLangKeys.translateDye(this.houseConfiguration.glassColor);
    } else if (button == this.btnVisualize) {
        StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseConfiguration.houseStyle.getStructureLocation(), StructureAlternateStart.class);
        StructureRenderHandler.setStructure(structure, EnumFacing.NORTH, this.houseConfiguration);
        this.mc.displayGuiScreen(null);
    }
}
Also used : StructureAlternateStart(com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart) StructureTagMessage(com.wuest.prefab.Proxy.Messages.StructureTagMessage)

Example 2 with StructureAlternateStart

use of com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart in project MC-Prefab by Brian-Wuest.

the class HouseConfiguration method ConfigurationSpecificBuildStructure.

/**
 * This is used to actually build the structure as it creates the structure instance and calls build structure.
 * @param player The player which requested the build.
 * @param world The world instance where the build will occur.
 * @param hitBlockPos This hit block position.
 */
@Override
protected void ConfigurationSpecificBuildStructure(EntityPlayer player, World world, BlockPos hitBlockPos) {
    boolean houseBuilt = true;
    if (this.houseStyle == HouseConfiguration.HouseStyle.BASIC) {
        // We hit a block, let's start building!!!!!
        BlockPos startingPosition = hitBlockPos.up();
        // Get the new "North" facing. This is the orientation of
        // the house and all building will be based on this.
        EnumFacing northFace = this.houseFacing;
        // Get the "South" facing of the house to make rotating
        // easier.
        EnumFacing southFace = northFace.getOpposite();
        // Set the "North East" corner.
        /*ItemStartHouse.NorthEastCorner = startingPosition.offset(northFace, (int) Math.floor(configuration.houseDepth / 2) + 1)
					.offset(northFace.rotateY(), (int) Math.floor(configuration.houseWidth / 2) + 1);*/
        HouseConfiguration.NorthEastCorner = startingPosition.offset(southFace).offset(northFace.rotateY());
        // Set the "South East" corner.
        HouseConfiguration.SouthEastCorner = HouseConfiguration.NorthEastCorner.offset(southFace, this.houseDepth + 1);
        // Set the "South West" corner.
        HouseConfiguration.SouthWestCorner = HouseConfiguration.SouthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
        // Set the "North West" corner.
        HouseConfiguration.NorthWestCorner = HouseConfiguration.NorthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
        // Put the starting position in the middle of the house as that's what the rest of the methods expect.
        startingPosition = HouseConfiguration.NorthEastCorner.offset(southFace, (int) Math.floor(this.houseDepth / 2) + 1).offset(northFace.rotateYCCW(), (int) Math.floor(this.houseWidth / 2) + 1);
        BlockPos endBlockPos = startingPosition.offset(northFace.rotateYCCW(), this.houseWidth + 11).offset(southFace, this.houseDepth + 11).offset(EnumFacing.UP, 15);
        // Make sure this structure can be placed here.
        if (!BuildingMethods.CheckBuildSpaceForAllowedBlockReplacement(this, world, startingPosition, endBlockPos, player)) {
            // Send a message to the player saying that the structure could not
            // be built.
            player.sendMessage(new TextComponentTranslation(GuiLangKeys.GUI_STRUCTURE_NOBUILD).setStyle(new Style().setColor(TextFormatting.GREEN)));
            return;
        }
        // Clear the space before the user is teleported. This
        // is in-case they right-click on a space that is only 1
        // block tall.
        BuildingMethods.ClearSpace(world, HouseConfiguration.NorthEastCorner, this.houseWidth, 15, this.houseDepth, northFace);
        // Build the basic structure.
        HouseConfiguration.BuildStructure(world, startingPosition, this, northFace);
        // Build the interior.
        HouseConfiguration.BuildInterior(world, startingPosition, player, this, northFace);
        // Set up the exterior.
        HouseConfiguration.BuildExterior(world, startingPosition, player, this, northFace);
        if (this.addMineShaft && startingPosition.getY() > 15) {
            // Set up the mineshaft.
            HouseConfiguration.PlaceMineShaft(world, startingPosition, this.houseDepth, northFace);
        }
        houseBuilt = true;
    } else {
        // Build the alternate starter house instead.
        StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseStyle.getStructureLocation(), StructureAlternateStart.class);
        houseBuilt = structure.BuildStructure(this, world, hitBlockPos, EnumFacing.NORTH, player);
    }
    // The house was successfully built, remove the item from the inventory.
    if (houseBuilt) {
        EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) player);
        playerConfig.builtStarterHouse = true;
        playerConfig.saveToPlayer(player);
        player.inventory.clearMatchingItems(ModRegistry.StartHouse(), -1, 1, null);
        player.inventoryContainer.detectAndSendChanges();
        // Make sure to send a message to the client to sync up the server player information and the client player information.
        Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), (EntityPlayerMP) player);
    }
}
Also used : StructureAlternateStart(com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart) PlayerEntityTagMessage(com.wuest.prefab.Proxy.Messages.PlayerEntityTagMessage) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayerConfiguration(com.wuest.prefab.Config.EntityPlayerConfiguration) EnumFacing(net.minecraft.util.EnumFacing) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

StructureAlternateStart (com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart)2 EntityPlayerConfiguration (com.wuest.prefab.Config.EntityPlayerConfiguration)1 PlayerEntityTagMessage (com.wuest.prefab.Proxy.Messages.PlayerEntityTagMessage)1 StructureTagMessage (com.wuest.prefab.Proxy.Messages.StructureTagMessage)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 Style (net.minecraft.util.text.Style)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1