Skip to content

Commit

Permalink
Some fixes + API + logs, #289
Browse files Browse the repository at this point in the history
  • Loading branch information
NightKosh committed Nov 3, 2018
1 parent eea15d8 commit f7c81e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/gravestone
Original file line number Diff line number Diff line change
Expand Up @@ -373,33 +373,44 @@ private static void createOnDeath(Entity entity, World world, BlockPos pos, Deat
int age, GraveInfoOnDeath graveInfo, DamageSource damageSource) {
BlockPos newPos = null;
EnumFacing direction = null;
World newWorld = null;

boolean hasCustomLocation = false;
for (IGravePositionHandler position : APIGraveGeneration.GRAVE_POSITION_HANDLERS) {
if (position.condition(world, entity, pos, damageSource)) {
hasCustomLocation = true;
newPos = position.gravePosition(world, entity, pos, damageSource);
direction = position.graveFacing(world, entity, pos, damageSource);
break;
try {
for (IGravePositionHandler position : APIGraveGeneration.GRAVE_POSITION_HANDLERS) {
if (position.condition(world, entity, pos, damageSource)) {
newPos = position.gravePosition(world, entity, pos, damageSource);
if (newPos != null) {
hasCustomLocation = true;
direction = position.graveFacing(world, entity, pos, damageSource);
newWorld = position.getWorld(world, entity, pos, damageSource);
break;
}
}
}
} catch (Exception e) {
GSLogger.logError("Can't get custom position of grave!");
}

if (!hasCustomLocation || newPos == null) {
if (hasCustomLocation) {
GSLogger.logInfo("Position of grave was changed by other mod");
} else {
direction = EnumFacing.getHorizontal(MathHelper.floor((double) (entity.rotationYaw * 4 / 360F) + 0.5) & 3);
newPos = findPlaceForGrave(world, entity, pos, damageSource);
newWorld = world;
}

if (Config.createBackups && entity instanceof EntityPlayer) {
try {
BackupsHandler.BACKUPS.put(entity.getName(), new BackupsHandler.Backup(world.provider.getDimension(), newPos, items));
BackupsHandler.BACKUPS.put(entity.getName(), new BackupsHandler.Backup(newWorld.provider.getDimension(), newPos, items));
} catch (Exception e) {
GSLogger.logError("Can't create backup!");
}
}

if (newPos != null) {
world.setBlockState(newPos, GSBlock.GRAVE_STONE.getDefaultState().withProperty(BlockGraveStone.FACING, direction), 2);
TileEntityGraveStone tileEntity = (TileEntityGraveStone) world.getTileEntity(newPos);
newWorld.setBlockState(newPos, GSBlock.GRAVE_STONE.getDefaultState().withProperty(BlockGraveStone.FACING, direction), 2);
TileEntityGraveStone tileEntity = (TileEntityGraveStone) newWorld.getTileEntity(newPos);

if (tileEntity != null) {
if (graveInfo.getSword() != null) {
Expand Down

0 comments on commit f7c81e6

Please sign in to comment.