use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.
the class EntityAIWorkUndertaker method emptyGrave.
/**
* The undertaker empty the inventory from a grave to the graveyard inventory
* The undertake will make multiple trip if needed
*
* @return the next IAIState
*/
private IAIState emptyGrave() {
@Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
if (buildingGraveyard == null || checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
return IDLE;
}
worker.getCitizenData().setVisibleStatus(EMPTYING_ICON);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.emptying"));
worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0);
unequip();
@Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
// Still moving to the block
if (walkToBlock(gravePos, 3)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(gravePos);
if (entity instanceof TileEntityGrave) {
if (((TileEntityGrave) entity).isEmpty()) {
return TRY_RESURRECT;
}
if (worker.getInventoryCitizen().isFull()) {
return INVENTORY_FULL;
}
if (effortCounter < EFFORT_EMPTY_GRAVE) {
worker.swing(Hand.MAIN_HAND);
effortCounter += getPrimarySkillLevel();
return getState();
}
effortCounter = 0;
// at position - try to take all item
if (InventoryUtils.transferAllItemHandler(((TileEntityGrave) entity).getInventory(), worker.getInventoryCitizen())) {
return TRY_RESURRECT;
}
}
return IDLE;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.
the class EntityAIWorkUndertaker method startWorking.
/**
* Prepares the undertaker for digging.
* Also requests the tools and checks if the undertaker has queued graves.
*
* @return the next IAIState
*/
@NotNull
private IAIState startWorking() {
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
worker.getCitizenData().setIdleAtJob(false);
@Nullable final BlockPos currentGrave = getOwnBuilding().getGraveToWorkOn();
if (currentGrave != null) {
if (walkToBuilding()) {
return getState();
}
final TileEntity entity = world.getBlockEntity(currentGrave);
if (entity instanceof TileEntityGrave) {
getOwnBuilding().getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData((GraveData) ((TileEntityGrave) entity).getGraveData());
return EMPTY_GRAVE;
}
getOwnBuilding().ClearCurrentGrave();
}
return WANDER;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.
the class EntityAIWorkUndertaker method tryResurrect.
/**
* Attempt to resurrect buried citizen from its citizen data
* Randomize to see if resurrection successful and resurrect if need be
*
* @return the next IAIState
*/
private IAIState tryResurrect() {
@Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData() == null || buildingGraveyard.getGraveToWorkOn() == null) {
return IDLE;
}
unequip();
@Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
if (gravePos == null) {
return IDLE;
}
// Still moving to the block
if (walkToBlock(gravePos, 3)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(gravePos);
if (entity instanceof TileEntityGrave) {
if (effortCounter < EFFORT_RESURRECT) {
worker.swing(Hand.MAIN_HAND);
effortCounter += getSecondarySkillLevel();
return getState();
}
effortCounter = 0;
shouldDumpInventory = true;
final double chance = getResurrectChance(buildingGraveyard);
if (getTotemResurrectChance() > 0 && random.nextDouble() <= TOTEM_BREAK_CHANCE) {
worker.getInventoryCitizen().extractItem(InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.TOTEM_OF_UNDYING), 1, false);
worker.playSound(SoundEvents.TOTEM_USE, 1.0f, 1.0f);
}
if (chance >= random.nextDouble()) {
final ICitizenData citizenData = buildingGraveyard.getColony().getCitizenManager().resurrectCivilianData(buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData().getCitizenDataNBT(), true, world, gravePos);
LanguageHandler.sendPlayersMessage(buildingGraveyard.getColony().getImportantMessageEntityPlayers(), "com.minecolonies.coremod.resurrect", citizenData.getName());
worker.getCitizenColonyHandler().getColony().getCitizenManager().updateCitizenMourn(citizenData, false);
AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_RESURRECT.trigger(playerMP));
buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData(null);
world.setBlockAndUpdate(gravePos, Blocks.AIR.defaultBlockState());
return INVENTORY_FULL;
}
}
return DIG_GRAVE;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class GraveyardManagementWindow method onOpened.
@Override
public void onOpened() {
super.onOpened();
/*
* ScrollList with the graves.
*/
final ScrollingList graveList = findPaneOfTypeByID(LIST_GRAVES, ScrollingList.class);
graveList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return moduleView.getGraves().size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final BlockPos grave = moduleView.getGraves().get(index);
@NotNull final String distance = Integer.toString((int) Math.sqrt(BlockPosUtil.getDistanceSquared(grave, buildingView.getPosition())));
final ITextComponent direction = BlockPosUtil.calcDirection(buildingView.getPosition(), grave);
final TileEntity entity = world.getBlockEntity(grave);
if (entity instanceof TileEntityGrave) {
rowPane.findPaneOfTypeByID(TAG_NAME, Text.class).setText("Grave of " + ((((TileEntityGrave) entity).getGraveData() != null) ? ((TileEntityGrave) entity).getGraveData().getCitizenName() : "Unknown Citizen"));
rowPane.findPaneOfTypeByID(TAG_DISTANCE, Text.class).setText(distance + "m");
rowPane.findPaneOfTypeByID(TAG_DIRECTION, Text.class).setText(direction);
}
}
});
/*
* ScrollList with the resting citizen.
*/
final ScrollingList ripList = findPaneOfTypeByID(LIST_CITIZEN, ScrollingList.class);
ripList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return moduleView.getRestingCitizen().size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final String citizenName = moduleView.getRestingCitizen().get(index);
rowPane.findPaneOfTypeByID(TAG_CITIZEN_NAME, Text.class).setText(citizenName);
}
});
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class BlockMinecoloniesGrave method spawnAfterBreak.
@Override
public void spawnAfterBreak(final BlockState state, final ServerWorld worldIn, final BlockPos pos, final ItemStack stack) {
final TileEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof TileEntityGrave) {
final IItemHandler handler = ((AbstractTileEntityGrave) tileentity).getInventory();
InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
super.spawnAfterBreak(state, worldIn, pos, stack);
}
Aggregations