fix display in nether and claim saving
This commit is contained in:
parent
9a45382c6e
commit
835aa5ba21
@ -72,7 +72,7 @@ public class ClaimStorage {
|
||||
}
|
||||
claim.setClaimID(this.generateUUID());
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimCreateSuccess, Formatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class ClaimStorage {
|
||||
Claim newClaim = new Claim(opposite, to, player.getUuid(), player.getServerWorld());
|
||||
Set<Claim> conflicts = conflicts(newClaim, claim);
|
||||
if(!conflicts.isEmpty()) {
|
||||
conflicts.forEach(conf->PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT));
|
||||
conflicts.forEach(conf->PlayerClaimData.get(player).addDisplayClaim(conf, EnumDisplayType.CONFLICT, player.getBlockPos().getY()));
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class ClaimStorage {
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
claim.copySizes(newClaim);
|
||||
this.addClaim(claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeSuccess, Formatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
@ -231,12 +231,13 @@ public class ClaimStorage {
|
||||
break;
|
||||
}
|
||||
}
|
||||
FileWriter writer = new FileWriter(file);
|
||||
JsonArray arr = new JsonArray();
|
||||
if(dirty)
|
||||
if(dirty){
|
||||
FileWriter writer = new FileWriter(file);
|
||||
JsonArray arr = new JsonArray();
|
||||
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
|
||||
ConfigHandler.GSON.toJson(arr, writer);
|
||||
writer.close();
|
||||
ConfigHandler.GSON.toJson(arr, writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class CommandClaim {
|
||||
if (claim == null)
|
||||
return 0;
|
||||
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
}
|
||||
else{
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
|
@ -88,12 +88,12 @@ public class ItemInteractEvents {
|
||||
Claim subClaim = claim.getSubClaim(target);
|
||||
if (subClaim != null && data.currentEdit()==null) {
|
||||
if (subClaim.isCorner(target)) {
|
||||
data.setEditClaim(subClaim);
|
||||
data.setEditClaim(subClaim, player.getBlockPos().getY());
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
}
|
||||
else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
} else {
|
||||
@ -101,7 +101,7 @@ public class ItemInteractEvents {
|
||||
boolean fl = claim.resizeSubclaim(data.currentEdit(), data.editingCorner(), target);
|
||||
if(!fl)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
data.setEditClaim(null);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
@ -109,7 +109,7 @@ public class ItemInteractEvents {
|
||||
if(!fl)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
else{
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.subClaimCreateSuccess, Formatting.GOLD), false);
|
||||
}
|
||||
data.setEditingCorner(null);
|
||||
@ -118,22 +118,22 @@ public class ItemInteractEvents {
|
||||
}
|
||||
} else {
|
||||
if (claim.isCorner(target)) {
|
||||
data.setEditClaim(claim);
|
||||
data.setEditClaim(claim, player.getBlockPos().getY());
|
||||
data.setEditingCorner(target);
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeClaim, Formatting.GOLD), false);
|
||||
}
|
||||
else if(data.currentEdit()!=null){
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.cantClaimHere, Formatting.RED), false);
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class ItemInteractEvents {
|
||||
else {
|
||||
if(data.currentEdit()!=null){
|
||||
storage.resizeClaim(data.currentEdit(), data.editingCorner(), target, player);
|
||||
data.setEditClaim(null);
|
||||
data.setEditClaim(null, 0);
|
||||
data.setEditingCorner(null);
|
||||
}
|
||||
else if (data.editingCorner() != null) {
|
||||
@ -168,7 +168,7 @@ public class ItemInteractEvents {
|
||||
owner,
|
||||
target.getX(), target.getY(), target.getZ()), Formatting.GREEN);
|
||||
player.sendMessage(text, false);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
} else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.inspectNoClaim, Formatting.RED), false);
|
||||
}
|
||||
|
@ -5,18 +5,20 @@ import com.flemmli97.flan.claim.ParticleIndicators;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.particle.DustParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClaimDisplay {
|
||||
|
||||
private int displayTime;
|
||||
private int displayTime, height;
|
||||
private final Claim toDisplay;
|
||||
public final EnumDisplayType type;
|
||||
private int[][] poss;
|
||||
@ -26,11 +28,12 @@ public class ClaimDisplay {
|
||||
private int[] prevDims;
|
||||
|
||||
private final DustParticleEffect corner, middle;
|
||||
public ClaimDisplay(Claim claim, EnumDisplayType type) {
|
||||
public ClaimDisplay(Claim claim, EnumDisplayType type, int y) {
|
||||
this.toDisplay = claim;
|
||||
this.displayTime = ConfigHandler.config.claimDisplayTime;
|
||||
this.prevDims = claim.getDimensions();
|
||||
this.type = type;
|
||||
this.height = y;
|
||||
switch (type){
|
||||
case SUB:
|
||||
this.corner = ParticleIndicators.SUBCLAIMCORNER;
|
||||
@ -55,12 +58,12 @@ public class ClaimDisplay {
|
||||
this.displayTime--;
|
||||
int[] dims = this.toDisplay.getDimensions();
|
||||
if (this.poss == null || this.changed(dims)) {
|
||||
this.middlePoss = calculateDisplayPos(player.world, dims);
|
||||
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
|
||||
this.poss = new int[][]{
|
||||
this.getPosFrom(player.world, dims[0], dims[2], dims[4]),
|
||||
this.getPosFrom(player.world, dims[1], dims[2], dims[4]),
|
||||
this.getPosFrom(player.world, dims[0], dims[3], dims[4]),
|
||||
this.getPosFrom(player.world, dims[1], dims[3], dims[4]),
|
||||
this.getPosFrom(player.getServerWorld(), dims[0], dims[2], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[1], dims[2], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[0], dims[3], this.height),
|
||||
this.getPosFrom(player.getServerWorld(), dims[1], dims[3], this.height),
|
||||
};
|
||||
}
|
||||
for (int[] pos : this.poss) {
|
||||
@ -81,7 +84,7 @@ public class ClaimDisplay {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int[][] calculateDisplayPos(World world, int[] from) {
|
||||
public static int[][] calculateDisplayPos(ServerWorld world, int[] from, int height) {
|
||||
List<int[]> l = Lists.newArrayList();
|
||||
Set<Integer> xs = Sets.newHashSet();
|
||||
addEvenly(from[0], from[1], 10, xs);
|
||||
@ -92,13 +95,13 @@ public class ClaimDisplay {
|
||||
zs.add(from[2]+1);
|
||||
zs.add(from[3]-1);
|
||||
for (int x : xs) {
|
||||
l.add(getPosFrom(world, x, from[2], from[4]));
|
||||
l.add(getPosFrom(world, x, from[3], from[4]));
|
||||
l.add(getPosFrom(world, x, from[2], height));
|
||||
l.add(getPosFrom(world, x, from[3], height));
|
||||
|
||||
}
|
||||
for (int z : zs) {
|
||||
l.add(getPosFrom(world, from[0], z, from[4]));
|
||||
l.add(getPosFrom(world, from[1], z, from[4]));
|
||||
l.add(getPosFrom(world, from[0], z, height));
|
||||
l.add(getPosFrom(world, from[1], z, height));
|
||||
}
|
||||
|
||||
return l.toArray(new int[0][]);
|
||||
@ -117,8 +120,28 @@ public class ClaimDisplay {
|
||||
addEvenly(min + step, max - step, step, l);
|
||||
}
|
||||
|
||||
private static int[] getPosFrom(World world, int x, int z, int maxY) {
|
||||
return new int[]{x, Math.max(maxY, world.getChunk(x >> 4, z >> 4).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x & 15, z & 15) + 1), z};
|
||||
private static int[] getPosFrom(ServerWorld world, int x, int z, int maxY) {
|
||||
int y = nextAirBlockFrom(world, x, maxY, z);
|
||||
return new int[]{x, y, z};
|
||||
}
|
||||
|
||||
private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z){
|
||||
BlockPos pos = new BlockPos(x,y,z);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if(state.getMaterial().isReplaceable()){
|
||||
pos = pos.down();
|
||||
while(world.getBlockState(pos).getMaterial().isReplaceable()){
|
||||
pos = pos.down();
|
||||
}
|
||||
pos = pos.up();
|
||||
}
|
||||
else{
|
||||
pos = pos.up();
|
||||
while(!world.getBlockState(pos).getMaterial().isReplaceable()){
|
||||
pos = pos.up();
|
||||
}
|
||||
}
|
||||
return pos.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,19 +96,19 @@ public class PlayerClaimData {
|
||||
return this.editingClaim;
|
||||
}
|
||||
|
||||
public void setEditClaim(Claim claim) {
|
||||
public void setEditClaim(Claim claim, int height) {
|
||||
if(claim!=null)
|
||||
this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT);
|
||||
this.displayEditing = new ClaimDisplay(claim, EnumDisplayType.EDIT, height);
|
||||
else
|
||||
this.displayEditing = null;
|
||||
this.editingClaim = claim;
|
||||
}
|
||||
|
||||
public void addDisplayClaim(Claim claim, EnumDisplayType type) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type));
|
||||
public void addDisplayClaim(Claim claim, EnumDisplayType type, int height) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type, height));
|
||||
if(type==EnumDisplayType.MAIN)
|
||||
for(Claim sub : claim.getAllSubclaims())
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB));
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height));
|
||||
}
|
||||
|
||||
public EnumEditMode getEditMode() {
|
||||
|
Loading…
Reference in New Issue
Block a user