Search in sources :

Example 1 with EntityPlayerConfiguration

use of com.wuest.prefab.Config.EntityPlayerConfiguration in project MC-Prefab by Brian-Wuest.

the class ModEventHandler method PlayerJoinedWorld.

/**
 * This event is used to determine if the player should be given the starting house item when they log in.
 * @param event The event object.
 */
@SubscribeEvent
public static void PlayerJoinedWorld(EntityJoinWorldEvent event) {
    if (!event.getWorld().isRemote && event.getEntity() instanceof EntityPlayerMP) {
        System.out.println("Player joined world, checking to see if the house builder should be provided.");
        EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
        EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) event.getEntity());
        if (!playerConfig.givenHouseBuilder && Prefab.proxy.proxyConfiguration.addHouseItem) {
            ItemStack stack = Prefab.proxy.proxyConfiguration.addModerateHouseInstead ? new ItemStack(ModRegistry.ModerateHouse()) : new ItemStack(ModRegistry.StartHouse());
            player.inventory.addItemStackToInventory(stack);
            player.inventoryContainer.detectAndSendChanges();
            // Make sure to set the tag for this player so they don't get the item again.
            playerConfig.givenHouseBuilder = true;
            playerConfig.saveToPlayer(player);
        }
        // Send the persist tag to the client.
        Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), player);
    }
}
Also used : PlayerEntityTagMessage(com.wuest.prefab.Proxy.Messages.PlayerEntityTagMessage) EntityPlayerConfiguration(com.wuest.prefab.Config.EntityPlayerConfiguration) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityPlayerConfiguration

use of com.wuest.prefab.Config.EntityPlayerConfiguration in project MC-Prefab by Brian-Wuest.

the class StructureModerateHouse method AfterBuilding.

/**
 * This method is used after the main building is build for any additional
 * structures or modifications.
 *
 * @param configuration The structure configuration.
 * @param world The current world.
 * @param originalPos The original position clicked on.
 * @param assumedNorth The assumed northern direction.
 * @param player The player which initiated the construction.
 */
@Override
public void AfterBuilding(StructureConfiguration configuration, World world, BlockPos originalPos, EnumFacing assumedNorth, EntityPlayer player) {
    ModerateHouseConfiguration houseConfig = (ModerateHouseConfiguration) configuration;
    EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) player);
    if (this.furnacePosition != null) {
        for (BlockPos furnacePos : this.furnacePosition) {
            // Fill the furnace.
            TileEntity tileEntity = world.getTileEntity(furnacePos);
            if (tileEntity instanceof TileEntityFurnace) {
                TileEntityFurnace furnaceTile = (TileEntityFurnace) tileEntity;
                furnaceTile.setInventorySlotContents(1, new ItemStack(Items.COAL, 20));
            }
        }
    }
    if (this.chestPosition != null && !playerConfig.builtStarterHouse && houseConfig.addChestContents) {
        // Fill the chest if the player hasn't generated the starting house yet.
        StructureModerateHouse.FillChest(world, this.chestPosition, houseConfig, player);
    }
    if (this.trapDoorPosition != null && this.trapDoorPosition.getY() > 15 && houseConfig.addMineshaft) {
        // Build the mineshaft.
        StructureAlternateStart.PlaceMineShaft(world, this.trapDoorPosition.down(), houseConfig.houseFacing, false);
    }
    // Make sure to set this value so the player cannot fill the chest a second time.
    playerConfig.builtStarterHouse = true;
    playerConfig.saveToPlayer(player);
}
Also used : ModerateHouseConfiguration(com.wuest.prefab.Config.Structures.ModerateHouseConfiguration) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayerConfiguration(com.wuest.prefab.Config.EntityPlayerConfiguration) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with EntityPlayerConfiguration

use of com.wuest.prefab.Config.EntityPlayerConfiguration 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

EntityPlayerConfiguration (com.wuest.prefab.Config.EntityPlayerConfiguration)3 PlayerEntityTagMessage (com.wuest.prefab.Proxy.Messages.PlayerEntityTagMessage)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 ModerateHouseConfiguration (com.wuest.prefab.Config.Structures.ModerateHouseConfiguration)1 StructureAlternateStart (com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityFurnace (net.minecraft.tileentity.TileEntityFurnace)1 EnumFacing (net.minecraft.util.EnumFacing)1 Style (net.minecraft.util.text.Style)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1