use of com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS 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.research.util.ResearchConstants.GRAVE_DECAY_BONUS 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