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;
}
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());
}
}
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;
}
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;
}
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());
}
}
Aggregations