improved claim display with liquids
This commit is contained in:
parent
2a1d65a30d
commit
5ca457c882
@ -5,7 +5,7 @@ import net.minecraft.particle.DustParticleEffect;
|
|||||||
public class ParticleIndicators {
|
public class ParticleIndicators {
|
||||||
|
|
||||||
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(194 / 255f, 130 / 255f, 4 / 255f, 1);
|
public static final DustParticleEffect CLAIMCORNER = new DustParticleEffect(194 / 255f, 130 / 255f, 4 / 255f, 1);
|
||||||
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(230 / 255f, 170 / 255f, 53 / 255f, 1);
|
public static final DustParticleEffect CLAIMMIDDLE = new DustParticleEffect(237 / 255f, 187 / 255f, 38 / 255f, 1);
|
||||||
|
|
||||||
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(125 / 255f, 125 / 255f, 125 / 255f, 1);
|
public static final DustParticleEffect SUBCLAIMCORNER = new DustParticleEffect(125 / 255f, 125 / 255f, 125 / 255f, 1);
|
||||||
public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(194 / 255f, 194 / 255f, 194 / 255f, 1);
|
public static final DustParticleEffect SUBCLAIMMIDDLE = new DustParticleEffect(194 / 255f, 194 / 255f, 194 / 255f, 1);
|
||||||
|
@ -56,7 +56,8 @@ public class ClaimDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean display(ServerPlayerEntity player) {
|
public boolean display(ServerPlayerEntity player) {
|
||||||
this.displayTime--;
|
if(--this.displayTime % 2 == 0)
|
||||||
|
return toDisplay.isRemoved();
|
||||||
int[] dims = this.toDisplay.getDimensions();
|
int[] dims = this.toDisplay.getDimensions();
|
||||||
if (this.poss == null || this.changed(dims)) {
|
if (this.poss == null || this.changed(dims)) {
|
||||||
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
|
this.middlePoss = calculateDisplayPos(player.getServerWorld(), dims, this.height);
|
||||||
@ -68,11 +69,15 @@ public class ClaimDisplay {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
for (int[] pos : this.poss) {
|
for (int[] pos : this.poss) {
|
||||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
if(pos[1]!=pos[2])
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(this.corner, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||||
}
|
}
|
||||||
if (this.middlePoss != null)
|
if (this.middlePoss != null)
|
||||||
for (int[] pos : this.middlePoss) {
|
for (int[] pos : this.middlePoss) {
|
||||||
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[2] + 0.5, 0, 0.25f, 0, 0, 1));
|
if(pos[1]!=pos[2])
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[2] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(this.middle, true, pos[0] + 0.5, pos[1] + 0.25, pos[3] + 0.5, 0, 0.5f, 0, 0, 1));
|
||||||
}
|
}
|
||||||
this.prevDims = dims;
|
this.prevDims = dims;
|
||||||
return toDisplay.isRemoved() || displayTime < 0;
|
return toDisplay.isRemoved() || displayTime < 0;
|
||||||
@ -121,27 +126,48 @@ public class ClaimDisplay {
|
|||||||
addEvenly(min + step, max - step, step, l);
|
addEvenly(min + step, max - step, step, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] getPosFrom(ServerWorld world, int x, int z, int maxY) {
|
/**
|
||||||
int y = nextAirBlockFrom(world, x, maxY, z);
|
* Returns an array of of form [x,y1,y2,z] where y1 = height of the lowest replaceable block and y2 = height of the
|
||||||
return new int[]{x, y, z};
|
* lowest air block above water (if possible)
|
||||||
|
*/
|
||||||
|
public static int[] getPosFrom(ServerWorld world, int x, int z, int maxY) {
|
||||||
|
int[] y = nextAirAndWaterBlockFrom(world, x, maxY, z);
|
||||||
|
return new int[]{x, y[0], y[1], z};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int nextAirBlockFrom(ServerWorld world, int x, int y, int z) {
|
private static int[] nextAirAndWaterBlockFrom(ServerWorld world, int x, int y, int z) {
|
||||||
BlockPos pos = new BlockPos(x, y, z);
|
BlockPos pos = new BlockPos(x, y, z);
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
if (state.getMaterial().isReplaceable()) {
|
if (state.getMaterial().isReplaceable()) {
|
||||||
pos = pos.down();
|
pos = pos.down();
|
||||||
while (world.getBlockState(pos).getMaterial().isReplaceable()) {
|
state = world.getBlockState(pos);
|
||||||
|
while (state.getMaterial().isReplaceable()) {
|
||||||
pos = pos.down();
|
pos = pos.down();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
pos = pos.up();
|
pos = pos.up();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
} else {
|
} else {
|
||||||
pos = pos.up();
|
pos = pos.up();
|
||||||
while (!world.getBlockState(pos).getMaterial().isReplaceable()) {
|
state = world.getBlockState(pos);
|
||||||
|
while (!state.getMaterial().isReplaceable()) {
|
||||||
pos = pos.up();
|
pos = pos.up();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pos.getY();
|
int[] yRet = new int[]{pos.getY(), pos.getY()};
|
||||||
|
if(state.getMaterial().isLiquid()){
|
||||||
|
pos = pos.up();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
|
while (state.getMaterial().isLiquid()) {
|
||||||
|
pos = pos.up();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
|
}
|
||||||
|
if(state.getMaterial().isReplaceable())
|
||||||
|
yRet[1] = pos.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
return yRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,7 +27,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class PlayerClaimData {
|
public class PlayerClaimData {
|
||||||
|
|
||||||
private int claimBlocks, additionalClaimBlocks, confirmTick;
|
private int claimBlocks, additionalClaimBlocks, confirmTick, actionCooldown;
|
||||||
|
|
||||||
private int lastBlockTick;
|
private int lastBlockTick;
|
||||||
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
private EnumEditMode mode = EnumEditMode.DEFAULT;
|
||||||
@ -35,6 +35,7 @@ public class PlayerClaimData {
|
|||||||
private ClaimDisplay displayEditing;
|
private ClaimDisplay displayEditing;
|
||||||
|
|
||||||
private BlockPos firstCorner;
|
private BlockPos firstCorner;
|
||||||
|
private int[] cornerRenderPos;
|
||||||
|
|
||||||
private final Set<ClaimDisplay> claimDisplayList = Sets.newHashSet();
|
private final Set<ClaimDisplay> claimDisplayList = Sets.newHashSet();
|
||||||
private final Set<ClaimDisplay> displayToAdd = Sets.newHashSet();
|
private final Set<ClaimDisplay> displayToAdd = Sets.newHashSet();
|
||||||
@ -88,6 +89,19 @@ public class PlayerClaimData {
|
|||||||
return this.calculateUsedClaimBlocks();
|
return this.calculateUsedClaimBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To prevent double processing. most notably when right clicking on a block and the block doesnt do anything ->
|
||||||
|
* block onUse -> item use. Might be a better way but for now this. But also handles having
|
||||||
|
* same items on both hands triggering
|
||||||
|
*/
|
||||||
|
public void setClaimActionCooldown(){
|
||||||
|
this.actionCooldown = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean claimCooldown(){
|
||||||
|
return this.actionCooldown>0;
|
||||||
|
}
|
||||||
|
|
||||||
public Claim currentEdit() {
|
public Claim currentEdit() {
|
||||||
return this.editingClaim;
|
return this.editingClaim;
|
||||||
}
|
}
|
||||||
@ -113,8 +127,8 @@ public class PlayerClaimData {
|
|||||||
|
|
||||||
public void setEditMode(EnumEditMode mode) {
|
public void setEditMode(EnumEditMode mode) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.editingClaim = null;
|
this.setEditClaim(null, 0);
|
||||||
this.firstCorner = null;
|
this.setEditingCorner(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPos editingCorner() {
|
public BlockPos editingCorner() {
|
||||||
@ -128,7 +142,10 @@ public class PlayerClaimData {
|
|||||||
pos = pos.down();
|
pos = pos.down();
|
||||||
state = this.player.world.getBlockState(pos);
|
state = this.player.world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
|
this.cornerRenderPos = ClaimDisplay.getPosFrom(this.player.getServerWorld(), pos.getX(), pos.getZ(), pos.getY());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
this.cornerRenderPos = null;
|
||||||
this.firstCorner = pos;
|
this.firstCorner = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,16 +179,20 @@ public class PlayerClaimData {
|
|||||||
this.addClaimBlocks(1);
|
this.addClaimBlocks(1);
|
||||||
this.lastBlockTick = 0;
|
this.lastBlockTick = 0;
|
||||||
}
|
}
|
||||||
if (this.firstCorner != null)
|
if (this.cornerRenderPos != null) {
|
||||||
this.player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.firstCorner.getX() + 0.5, this.firstCorner.getY() + 1.25, this.firstCorner.getZ() + 0.5, 0, 0.25f, 0, 0, 3));
|
if(this.cornerRenderPos[1]!=this.cornerRenderPos[2])
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[2] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||||
|
player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleIndicators.SETCORNER, true, this.cornerRenderPos[0] + 0.5, this.cornerRenderPos[1] + 0.25, this.cornerRenderPos[3] + 0.5, 0, 0.25f, 0, 0, 2));
|
||||||
|
}
|
||||||
if (--this.confirmTick < 0)
|
if (--this.confirmTick < 0)
|
||||||
this.confirmDeleteAll = false;
|
this.confirmDeleteAll = false;
|
||||||
if (this.displayEditing != null)
|
if (this.displayEditing != null)
|
||||||
this.displayEditing.display(this.player);
|
this.displayEditing.display(this.player);
|
||||||
if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) {
|
if (this.player.getMainHandStack().getItem() != ConfigHandler.config.claimingItem && this.player.getOffHandStack().getItem() != ConfigHandler.config.claimingItem) {
|
||||||
this.firstCorner = null;
|
this.setEditingCorner(null);
|
||||||
this.editingClaim = null;
|
this.setEditClaim(null, 0);
|
||||||
}
|
}
|
||||||
|
this.actionCooldown--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(MinecraftServer server) {
|
public void save(MinecraftServer server) {
|
||||||
|
Loading…
Reference in New Issue
Block a user