Search in sources :

Example 1 with ModerateHouseConfiguration

use of com.wuest.prefab.structures.config.ModerateHouseConfiguration 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 player        The player which initiated the construction.
 */
@Override
public void AfterBuilding(StructureConfiguration configuration, ServerLevel world, BlockPos originalPos, Player player) {
    ModerateHouseConfiguration houseConfig = (ModerateHouseConfiguration) configuration;
    EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
    BuildingMethods.FillFurnaces(world, this.furnacePosition);
    if (this.chestPosition != null && !playerConfig.builtStarterHouse && houseConfig.addChestContents) {
        // Fill the chest if the player hasn't generated the starting house yet.
        BuildingMethods.FillChest(world, this.chestPosition);
    }
    int minimumHeightForMineshaft = world.getMinBuildHeight() + 21;
    if (this.trapDoorPosition != null && this.trapDoorPosition.getY() > minimumHeightForMineshaft && houseConfig.addMineshaft) {
        // Build the mineshaft.
        BuildingMethods.PlaceMineShaft(world, this.trapDoorPosition.below(), 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);
    // 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)), ((ServerPlayer) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
Also used : ModerateHouseConfiguration(com.wuest.prefab.structures.config.ModerateHouseConfiguration) PlayerEntityTagMessage(com.wuest.prefab.proxy.messages.PlayerEntityTagMessage) EntityPlayerConfiguration(com.wuest.prefab.config.EntityPlayerConfiguration) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Aggregations

EntityPlayerConfiguration (com.wuest.prefab.config.EntityPlayerConfiguration)1 PlayerEntityTagMessage (com.wuest.prefab.proxy.messages.PlayerEntityTagMessage)1 ModerateHouseConfiguration (com.wuest.prefab.structures.config.ModerateHouseConfiguration)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1