Search in sources :

Example 1 with GraveData

use of com.minecolonies.api.colony.GraveData in project minecolonies by ldtteam.

the class GraveyardManagementModule method deserializeNBT.

@Override
public void deserializeNBT(final CompoundNBT compound) {
    restingCitizen.clear();
    if (compound.getAllKeys().contains(TAG_RIP_CITIZEN_LIST)) {
        final ListNBT ripCitizen = compound.getList(TAG_RIP_CITIZEN_LIST, TAG_STRING);
        for (int i = 0; i < ripCitizen.size(); i++) {
            final String citizenName = ripCitizen.getString(i);
            restingCitizen.add(citizenName);
        }
    }
    if (compound.getAllKeys().contains(TAG_GRAVE_DATA)) {
        lastGraveData = new GraveData();
        lastGraveData.read(compound.getCompound(TAG_GRAVE_DATA));
    } else
        lastGraveData = null;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) GraveData(com.minecolonies.api.colony.GraveData)

Example 2 with GraveData

use of com.minecolonies.api.colony.GraveData in project minecolonies by ldtteam.

the class GraveManager method createCitizenGrave.

/**
 * Attempt to create a TileEntityGrave at @pos containing the specific @citizenData
 * <p>
 * On failure: drop all the citizen inventory on the ground.
 *
 * @param world       The world.
 * @param pos         The position where to spawn a grave
 * @param citizenData The citizenData
 */
@Override
public void createCitizenGrave(final World world, final BlockPos pos, final ICitizenData citizenData) {
    final BlockState here = world.getBlockState(pos);
    if (here.getBlock() == Blocks.LAVA) {
        LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.grave.lava");
        return;
    }
    BlockPos firstValidPosition = null;
    if (here.getBlock() == Blocks.WATER) {
        for (int i = 1; i <= 10; i++) {
            if (world.getBlockState(pos.above(i)).getBlock() instanceof AirBlock) {
                firstValidPosition = searchShore(world, pos.above(i));
                break;
            }
        }
        if (firstValidPosition == null) {
            LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.grave.water");
        }
    } else {
        firstValidPosition = BlockPosUtil.findAround(world, pos, 10, 10, (blockAccess, current) -> blockAccess.getBlockState(current).getMaterial() == Material.AIR && blockAccess.getBlockState(current.below()).getMaterial().isSolid());
    }
    if (firstValidPosition != null) {
        world.setBlockAndUpdate(firstValidPosition, BlockMinecoloniesGrave.getPlacementState(ModBlocks.blockGrave.defaultBlockState(), new TileEntityGrave(), firstValidPosition));
        final TileEntityGrave graveEntity = (TileEntityGrave) world.getBlockEntity(firstValidPosition);
        if (!InventoryUtils.transferAllItemHandler(citizenData.getInventory(), graveEntity.getInventory())) {
            InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
        }
        graveEntity.delayDecayTimer(colony.getResearchManager().getResearchEffects().getEffectStrength(GRAVE_DECAY_BONUS));
        GraveData graveData = new GraveData();
        graveData.setCitizenName(citizenData.getName());
        if (citizenData.getJob() != null) {
            final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
            graveData.setCitizenJobName(jobName.getString());
        }
        graveData.setCitizenDataNBT(citizenData.serializeNBT());
        graveEntity.setGraveData(graveData);
        colony.getGraveManager().addNewGrave(firstValidPosition);
        LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.gravespawned");
    } else {
        InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
    }
}
Also used : LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) AirBlock(net.minecraft.block.AirBlock) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) HashMap(java.util.HashMap) Direction(net.minecraft.util.Direction) ModBlocks(com.minecolonies.api.blocks.ModBlocks) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockMinecoloniesGrave(com.minecolonies.coremod.blocks.BlockMinecoloniesGrave) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ListNBT(net.minecraft.nbt.ListNBT) MAX_TICKRATE(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE) Iterator(java.util.Iterator) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) GraveData(com.minecolonies.api.colony.GraveData) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) IGraveManager(com.minecolonies.api.colony.managers.interfaces.IGraveManager) Material(net.minecraft.block.material.Material) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) GRAVE_DECAY_BONUS(com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS) BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) GraveData(com.minecolonies.api.colony.GraveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent)

Example 3 with GraveData

use of com.minecolonies.api.colony.GraveData in project minecolonies by ldtteam.

the class TileEntityGrave method load.

@Override
public void load(final BlockState state, final CompoundNBT compound) {
    super.load(state, compound);
    inventory = createInventory(DEFAULT_SIZE);
    final ListNBT inventoryTagList = compound.getList(TAG_INVENTORY, TAG_COMPOUND);
    for (int i = 0; i < inventoryTagList.size(); i++) {
        final CompoundNBT inventoryCompound = inventoryTagList.getCompound(i);
        if (!inventoryCompound.contains(TAG_EMPTY)) {
            final ItemStack stack = ItemStack.of(inventoryCompound);
            inventory.setStackInSlot(i, stack);
        }
    }
    decay_timer = compound.contains(TAG_DECAY_TIMER) ? compound.getInt(TAG_DECAY_TIMER) : DEFAULT_DECAY_TIMER;
    decayed = compound.contains(TAG_DECAYED) ? compound.getBoolean(TAG_DECAYED) : false;
    if (compound.getAllKeys().contains(TAG_GRAVE_DATA)) {
        graveData = new GraveData();
        graveData.read(compound.getCompound(TAG_GRAVE_DATA));
    } else
        graveData = null;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) GraveData(com.minecolonies.api.colony.GraveData) ItemStack(net.minecraft.item.ItemStack)

Example 4 with GraveData

use of com.minecolonies.api.colony.GraveData in project minecolonies by Minecolonies.

the class GraveyardManagementModule method deserializeNBT.

@Override
public void deserializeNBT(final CompoundNBT compound) {
    restingCitizen.clear();
    if (compound.getAllKeys().contains(TAG_RIP_CITIZEN_LIST)) {
        final ListNBT ripCitizen = compound.getList(TAG_RIP_CITIZEN_LIST, TAG_STRING);
        for (int i = 0; i < ripCitizen.size(); i++) {
            final String citizenName = ripCitizen.getString(i);
            restingCitizen.add(citizenName);
        }
    }
    if (compound.getAllKeys().contains(TAG_GRAVE_DATA)) {
        lastGraveData = new GraveData();
        lastGraveData.read(compound.getCompound(TAG_GRAVE_DATA));
    } else
        lastGraveData = null;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) GraveData(com.minecolonies.api.colony.GraveData)

Example 5 with GraveData

use of com.minecolonies.api.colony.GraveData in project minecolonies by Minecolonies.

the class GraveManager method createCitizenGrave.

/**
 * Attempt to create a TileEntityGrave at @pos containing the specific @citizenData
 * <p>
 * On failure: drop all the citizen inventory on the ground.
 *
 * @param world       The world.
 * @param pos         The position where to spawn a grave
 * @param citizenData The citizenData
 */
@Override
public void createCitizenGrave(final World world, final BlockPos pos, final ICitizenData citizenData) {
    final BlockState here = world.getBlockState(pos);
    if (here.getBlock() == Blocks.LAVA) {
        MessageUtils.format(WARNING_GRAVE_LAVA).sendTo(colony).forManagers();
        return;
    }
    BlockPos firstValidPosition = null;
    if (here.getBlock() == Blocks.WATER) {
        for (int i = 1; i <= 10; i++) {
            if (world.getBlockState(pos.above(i)).getBlock() instanceof AirBlock) {
                firstValidPosition = searchShore(world, pos.above(i));
                break;
            }
        }
        if (firstValidPosition == null) {
            MessageUtils.format(WARNING_GRAVE_WATER).sendTo(colony).forManagers();
        }
    } else {
        firstValidPosition = BlockPosUtil.findAround(world, pos, 10, 10, (blockAccess, current) -> blockAccess.getBlockState(current).getMaterial() == Material.AIR && blockAccess.getBlockState(current.below()).getMaterial().isSolid());
    }
    if (firstValidPosition != null) {
        world.setBlockAndUpdate(firstValidPosition, BlockMinecoloniesGrave.getPlacementState(ModBlocks.blockGrave.defaultBlockState(), new TileEntityGrave(), firstValidPosition));
        final TileEntityGrave graveEntity = (TileEntityGrave) world.getBlockEntity(firstValidPosition);
        if (!InventoryUtils.transferAllItemHandler(citizenData.getInventory(), graveEntity.getInventory())) {
            InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
        }
        graveEntity.delayDecayTimer(colony.getResearchManager().getResearchEffects().getEffectStrength(GRAVE_DECAY_BONUS));
        GraveData graveData = new GraveData();
        graveData.setCitizenName(citizenData.getName());
        if (citizenData.getJob() != null) {
            final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
            graveData.setCitizenJobName(jobName.getString());
        }
        graveData.setCitizenDataNBT(citizenData.serializeNBT());
        graveEntity.setGraveData(graveData);
        colony.getGraveManager().addNewGrave(firstValidPosition);
        MessageUtils.format(WARNING_GRAVE_SPAWNED).sendTo(colony).forManagers();
    } else {
        InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) HashMap(java.util.HashMap) Direction(net.minecraft.util.Direction) ModBlocks(com.minecolonies.api.blocks.ModBlocks) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockMinecoloniesGrave(com.minecolonies.coremod.blocks.BlockMinecoloniesGrave) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ListNBT(net.minecraft.nbt.ListNBT) MAX_TICKRATE(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) MessageUtils(com.minecolonies.api.util.MessageUtils) Iterator(java.util.Iterator) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) GraveData(com.minecolonies.api.colony.GraveData) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) IGraveManager(com.minecolonies.api.colony.managers.interfaces.IGraveManager) Material(net.minecraft.block.material.Material) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) GRAVE_DECAY_BONUS(com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS) BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) GraveData(com.minecolonies.api.colony.GraveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent)

Aggregations

GraveData (com.minecolonies.api.colony.GraveData)6 ListNBT (net.minecraft.nbt.ListNBT)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2 IGraveManager (com.minecolonies.api.colony.managers.interfaces.IGraveManager)2 MAX_TICKRATE (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE)2 GRAVE_DECAY_BONUS (com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS)2 TileEntityGrave (com.minecolonies.api.tileentities.TileEntityGrave)2 BlockPosUtil (com.minecolonies.api.util.BlockPosUtil)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 WorldUtil (com.minecolonies.api.util.WorldUtil)2 NbtTagConstants (com.minecolonies.api.util.constant.NbtTagConstants)2 BlockMinecoloniesGrave (com.minecolonies.coremod.blocks.BlockMinecoloniesGrave)2 Colony (com.minecolonies.coremod.colony.Colony)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 AirBlock (net.minecraft.block.AirBlock)2