Skip to content

Commit

Permalink
Backup, #289
Browse files Browse the repository at this point in the history
  • Loading branch information
NightKosh committed Oct 28, 2018
1 parent 008443c commit 6ac6a92
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/nightkosh/gravestone/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public final void getConfigs() {
public static boolean generateEmptyPlayerGraves;
public static boolean dropGraveBlockAtDestruction;
public static List<Integer> playerGravesDimensionalBlackList;
public static boolean createBackups;

public static List<GraveStoneHelper.RestrictedArea> restrictGraveGenerationInArea;

Expand Down Expand Up @@ -106,6 +107,8 @@ private static void gravesConfig() {

playerGravesDimensionalBlackList = ConfigsHelper.getDimensionList(config, CATEGORY_GRAVES, "PlayerGravesDimensionalBlackList", "",
"List of dimension ids in which player's graves will not be generated at death");

createBackups = config.get(CATEGORY_GRAVES, "CreateBackups", true).getBoolean();
}


Expand Down
66 changes: 66 additions & 0 deletions src/main/java/nightkosh/gravestone/helper/BackupsHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package nightkosh.gravestone.helper;

import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* GraveStone mod
*
* @author NightKosh
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*/
public class BackupsHandler {

public static final Map<String, Backup> BACKUPS = new HashMap<>();

public static class Backup {
private int dimensionId;

private BlockPos pos;

private List<ItemStack> items = new ArrayList<>();

public Backup() {

}

public Backup(int dimensionId, BlockPos pos, List<ItemStack> items) {
this.dimensionId = dimensionId;
this.pos = pos;
setItems(items);
}

public int getDimensionId() {
return dimensionId;
}

public void setDimensionId(int dimensionId) {
this.dimensionId = dimensionId;
}

public BlockPos getPos() {
return pos;
}

public void setPos(BlockPos pos) {
this.pos = pos;
}

public List<ItemStack> getItems() {
return items;
}

public void setItems(List<ItemStack> items) {
for (ItemStack stack : items) {
if (stack != null && !stack.isEmpty()) {
this.items.add(stack.copy());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ private static void createOnDeath(Entity entity, World world, BlockPos pos, Deat
EnumFacing direction = EnumFacing.getHorizontal(MathHelper.floor((double) (entity.rotationYaw * 4 / 360F) + 0.5) & 3);

BlockPos newPos = findPlaceForGrave(world, entity, pos, damageSource);

if (Config.createBackups && entity instanceof EntityPlayer) {
try {
BackupsHandler.BACKUPS.put(entity.getName(), new BackupsHandler.Backup(world.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);
Expand Down

0 comments on commit 6ac6a92

Please sign in to comment.