change block destruction logic
This commit is contained in:
parent
2504f24b7b
commit
2d476cbf8a
39 changed files with 175 additions and 746 deletions
|
@ -1078,7 +1078,8 @@ public class Client implements IThreadListener {
|
|||
this.secondary();
|
||||
}
|
||||
|
||||
this.sendClickBlockToController(this.open == null && Bind.PRIMARY.isDown() && this.viewEntity == this.player);
|
||||
if(this.open != null || !Bind.PRIMARY.isDown() || this.viewEntity != this.player)
|
||||
this.leftClickCounter = 0;
|
||||
}
|
||||
|
||||
this.primary = this.secondary = this.tertiary = this.quarternary = false;
|
||||
|
@ -1335,11 +1336,11 @@ public class Client implements IThreadListener {
|
|||
if(this.pointedLiquid != null ? block.getMaterial().isLiquid() : block != Blocks.air) {
|
||||
desc = block.getDisplay();
|
||||
line1 = block.getInfo(this.world, pos, state, this.player);
|
||||
boolean toolReq = block.getMaterial().isToolRequired();
|
||||
boolean toolReq = !this.player.hasEffect(Effect.PUNCHING);
|
||||
boolean harvestable = this.player.canHarvestBlock(block);
|
||||
line2 = Color.BLUE + "Werkzeug" + Color.DARK_GRAY + ": " + (block.getMiningTool() != null ? (toolReq ? (harvestable ? Color.GREEN : Color.RED) : Color.LIGHT_GRAY) + block.getMiningTool().getDisplay() + (block.getMiningTool().isLevelled() ? (toolReq ? (harvestable ? Color.ORK : Color.CRIMSON) : Color.DARK_GRAY) + " Level " + (toolReq ? (harvestable ? Color.DARK_GREEN : Color.DARK_RED) : Color.GRAY) + (block.getMiningLevel() + 1) : "") : Color.GRAY + "Keins");
|
||||
if(this.controller.isHittingBlock()) {
|
||||
bar = 1.0f - this.controller.getDamage(pos);
|
||||
if(block.getMiningTool() != null && block.getMiningTool().isLevelled()) {
|
||||
bar = (float)(block.getMiningLevel() + 1) / 20.0f;
|
||||
color = (int)(bar * 255.0f) << 8 | (int)((1.0f - bar) * 255.0f) << 16;
|
||||
}
|
||||
}
|
||||
|
@ -1646,33 +1647,6 @@ public class Client implements IThreadListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendClickBlockToController(boolean leftClick)
|
||||
{
|
||||
if (!leftClick)
|
||||
{
|
||||
this.leftClickCounter = 0;
|
||||
this.controller.resetInteraction();
|
||||
}
|
||||
|
||||
if (this.leftClickCounter <= 0 && !this.player.isUsingItem())
|
||||
{
|
||||
if (leftClick && this.pointed != null && this.pointed.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
LocalPos blockpos = this.pointed.block;
|
||||
|
||||
if (this.world.getState(blockpos).getBlock() != Blocks.air && this.controller.damageBlock(blockpos, this.pointed.side))
|
||||
{
|
||||
this.effectRenderer.damageBlock(blockpos, this.pointed.side);
|
||||
this.player.swingItem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.controller.resetProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void primary()
|
||||
{
|
||||
if (this.leftClickCounter <= 0)
|
||||
|
@ -1723,80 +1697,77 @@ public class Client implements IThreadListener {
|
|||
|
||||
private void secondary()
|
||||
{
|
||||
if (!this.controller.isHittingBlock())
|
||||
{
|
||||
this.rightClickTimer = 4;
|
||||
boolean flag = true;
|
||||
ItemStack itemstack = this.player.getHeldItem();
|
||||
this.rightClickTimer = 4;
|
||||
boolean flag = true;
|
||||
ItemStack itemstack = this.player.getHeldItem();
|
||||
|
||||
if (itemstack != null && itemstack.getItem() == Items.camera && !this.saving)
|
||||
if (itemstack != null && itemstack.getItem() == Items.camera && !this.saving)
|
||||
{
|
||||
this.screenshot = this.cameraUsed = true;
|
||||
}
|
||||
|
||||
if (this.pointed == null)
|
||||
{
|
||||
Log.TICK.warn("Null zurückgegeben als 'hitResult', das sollte niemals passieren!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock() == Blocks.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.SECONDARY, null))
|
||||
{
|
||||
this.screenshot = this.cameraUsed = true;
|
||||
this.player.swingItem();
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.clearHeldItem();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.pointed == null)
|
||||
|
||||
switch (this.pointed.type)
|
||||
{
|
||||
Log.TICK.warn("Null zurückgegeben als 'hitResult', das sollte niemals passieren!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock() == Blocks.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.SECONDARY, null))
|
||||
{
|
||||
this.player.swingItem();
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.clearHeldItem();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.pointed.type)
|
||||
{
|
||||
case ENTITY:
|
||||
if (this.controller.interact(this.player, this.pointed.entity))
|
||||
case ENTITY:
|
||||
if (this.controller.interact(this.player, this.pointed.entity))
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BLOCK:
|
||||
LocalPos blockpos = this.pointed.block;
|
||||
|
||||
if (this.world.getState(blockpos).getBlock() != Blocks.air)
|
||||
{
|
||||
int i = itemstack != null ? itemstack.getSize() : 0;
|
||||
|
||||
if (this.controller.clickRight(this.player, this.world, itemstack, blockpos, this.pointed.side, this.pointed.vec))
|
||||
{
|
||||
flag = false;
|
||||
this.player.swingItem();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BLOCK:
|
||||
LocalPos blockpos = this.pointed.block;
|
||||
|
||||
if (this.world.getState(blockpos).getBlock() != Blocks.air)
|
||||
if (itemstack == null)
|
||||
{
|
||||
int i = itemstack != null ? itemstack.getSize() : 0;
|
||||
|
||||
if (this.controller.clickRight(this.player, this.world, itemstack, blockpos, this.pointed.side, this.pointed.vec))
|
||||
{
|
||||
flag = false;
|
||||
this.player.swingItem();
|
||||
}
|
||||
|
||||
if (itemstack == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
this.player.clearHeldItem();
|
||||
}
|
||||
else if (itemstack.getSize() != i)
|
||||
{
|
||||
this.itemRenderer.resetProgress();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
this.player.clearHeldItem();
|
||||
}
|
||||
else if (itemstack.getSize() != i)
|
||||
{
|
||||
this.itemRenderer.resetProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
ItemStack itemstack1 = this.player.getHeldItem();
|
||||
|
||||
if (itemstack1 != null && this.controller.sendUseItem(this.player, this.world, itemstack1))
|
||||
{
|
||||
ItemStack itemstack1 = this.player.getHeldItem();
|
||||
|
||||
if (itemstack1 != null && this.controller.sendUseItem(this.player, this.world, itemstack1))
|
||||
{
|
||||
this.itemRenderer.resetProgress();
|
||||
}
|
||||
this.itemRenderer.resetProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -708,15 +708,10 @@ public class EffectRenderer {
|
|||
this.offsetY = rng.floatv() * 3.0F;
|
||||
}
|
||||
|
||||
protected Icon(double x, double y, double z, State state, boolean hit) {
|
||||
this(x, y, z, hit ? 0.6f : 1.0f, Client.CLIENT.renderer.getModelManager().getTexture(state));
|
||||
protected Icon(double x, double y, double z, State state) {
|
||||
this(x, y, z, 1.0f, Client.CLIENT.renderer.getModelManager().getTexture(state));
|
||||
this.gravity = 1.0F;
|
||||
this.red = this.green = this.blue = 0.6F;
|
||||
if(hit) {
|
||||
this.motionX *= 0.2;
|
||||
this.motionY = (this.motionY - 0.1) * 0.2 + 0.1;
|
||||
this.motionZ *= 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
protected Icon(double x, double y, double z, Item item) {
|
||||
|
@ -964,7 +959,7 @@ public class EffectRenderer {
|
|||
});
|
||||
this.register(ParticleType.BLOCK_CRACK, (x, y, z, id) -> {
|
||||
State state = BlockRegistry.byId(id);
|
||||
return state == null ? null : new Icon(x, y, z, state, false);
|
||||
return state == null ? null : new Icon(x, y, z, state);
|
||||
});
|
||||
this.register(ParticleType.EXPLOSION_HUGE, (x, y, z, u) -> new ExplosionSpawner(x, y, z));
|
||||
this.register(ParticleType.EXPLOSION_LARGE,
|
||||
|
@ -1089,57 +1084,13 @@ public class EffectRenderer {
|
|||
double d0 = (double)pos.getX() + ((double)j + 0.5D) / (double)i;
|
||||
double d1 = (double)pos.getY() + ((double)k + 0.5D) / (double)i;
|
||||
double d2 = (double)pos.getZ() + ((double)l + 0.5D) / (double)i;
|
||||
this.add(new Icon(d0, d1, d2, state, false));
|
||||
this.add(new Icon(d0, d1, d2, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void damageBlock(LocalPos pos, Facing side) {
|
||||
State iblockstate = this.world.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if(block != Blocks.air) {
|
||||
int i = pos.getX();
|
||||
int j = pos.getY();
|
||||
int k = pos.getZ();
|
||||
float f = 0.1F;
|
||||
double d0 = (double)i + this.rng.doublev() * (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX() - (double)(f * 2.0F)) + (double)f
|
||||
+ block.getBlockBoundsMinX();
|
||||
double d1 = (double)j + this.rng.doublev() * (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY() - (double)(f * 2.0F)) + (double)f
|
||||
+ block.getBlockBoundsMinY();
|
||||
double d2 = (double)k + this.rng.doublev() * (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ() - (double)(f * 2.0F)) + (double)f
|
||||
+ block.getBlockBoundsMinZ();
|
||||
|
||||
if(side == Facing.DOWN) {
|
||||
d1 = (double)j + block.getBlockBoundsMinY() - (double)f;
|
||||
}
|
||||
|
||||
if(side == Facing.UP) {
|
||||
d1 = (double)j + block.getBlockBoundsMaxY() + (double)f;
|
||||
}
|
||||
|
||||
if(side == Facing.NORTH) {
|
||||
d2 = (double)k + block.getBlockBoundsMinZ() - (double)f;
|
||||
}
|
||||
|
||||
if(side == Facing.SOUTH) {
|
||||
d2 = (double)k + block.getBlockBoundsMaxZ() + (double)f;
|
||||
}
|
||||
|
||||
if(side == Facing.WEST) {
|
||||
d0 = (double)i + block.getBlockBoundsMinX() - (double)f;
|
||||
}
|
||||
|
||||
if(side == Facing.EAST) {
|
||||
d0 = (double)i + block.getBlockBoundsMaxX() + (double)f;
|
||||
}
|
||||
|
||||
this.add(new Icon(d0, d1, d2, iblockstate, true));
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnCritParticles(Entity entity) {
|
||||
this.add(new HitSpawner(entity));
|
||||
}
|
||||
|
|
|
@ -262,25 +262,6 @@ public class ItemRenderer
|
|||
GL15.glTranslatef(f, f1, f2);
|
||||
}
|
||||
|
||||
private void performDrinking(EntityNPC clientPlayer, float partialTicks)
|
||||
{
|
||||
float f = (float)clientPlayer.getItemInUseCount() - partialTicks + 1.0F;
|
||||
float f1 = f / (float)this.itemToRender.getMaxItemUseDuration();
|
||||
float f2 = ExtMath.absf(ExtMath.cos(f / 4.0F * (float)Math.PI) * 0.1F);
|
||||
|
||||
if (f1 >= 0.8F)
|
||||
{
|
||||
f2 = 0.0F;
|
||||
}
|
||||
|
||||
GL15.glTranslatef(0.0F, f2, 0.0F);
|
||||
float f3 = 1.0F - (float)Math.pow((double)f1, 27.0D);
|
||||
GL15.glTranslatef(f3 * 0.6F, f3 * -0.5F, f3 * 0.0F);
|
||||
GL15.glRotatef(f3 * 90.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL15.glRotatef(f3 * 10.0F, 1.0F, 0.0F, 0.0F);
|
||||
GL15.glRotatef(f3 * 30.0F, 0.0F, 0.0F, 1.0F);
|
||||
}
|
||||
|
||||
private void transformFirstPersonItem(float equipProgress, float swingProgress)
|
||||
{
|
||||
GL15.glTranslatef(0.56F, -0.52F, -0.71999997F);
|
||||
|
@ -354,12 +335,6 @@ public class ItemRenderer
|
|||
this.transformFirstPersonItem(f, 0.0F);
|
||||
break;
|
||||
|
||||
case EAT:
|
||||
case DRINK:
|
||||
this.performDrinking(clientplayer, partialTicks);
|
||||
this.transformFirstPersonItem(f, 0.0F);
|
||||
break;
|
||||
|
||||
case BLOCK:
|
||||
this.transformFirstPersonItem(f, 0.0F);
|
||||
this.doBlockTransformations();
|
||||
|
|
|
@ -24,13 +24,7 @@ public class PlayerController {
|
|||
private final Client gm;
|
||||
private final ClientPlayer handler;
|
||||
|
||||
private LocalPos position = new LocalPos(-1, -World.MAX_SIZE_Y - 1, -1);
|
||||
private ItemStack stack;
|
||||
private float damage;
|
||||
private int delay;
|
||||
private boolean hitting;
|
||||
private int lastSelected;
|
||||
private boolean interacting;
|
||||
private int itemUseCooldown;
|
||||
private int itemUseCooldownMax;
|
||||
|
||||
|
@ -55,8 +49,6 @@ public class PlayerController {
|
|||
block.onBroken(world, pos, state);
|
||||
}
|
||||
|
||||
this.position = new LocalPos(this.position.getX(), -1, this.position.getZ());
|
||||
|
||||
ItemStack stack = this.gm.player.getHeldItem();
|
||||
|
||||
if(stack != null) {
|
||||
|
@ -78,84 +70,19 @@ public class PlayerController {
|
|||
else {
|
||||
ItemStack stack = this.gm.player.getHeldItem();
|
||||
if(stack != null && stack.getItem().onAction(stack, this.gm.player, this.gm.world, ItemControl.PRIMARY, pos)) {
|
||||
this.interacting = true;
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
|
||||
if(this.gm.player.getHeldItem() != null && this.gm.player.getHeldItem().isEmpty())
|
||||
this.gm.player.clearHeldItem();
|
||||
return true;
|
||||
}
|
||||
if(!this.hitting || !this.isHitting(pos)) {
|
||||
if(this.hitting) {
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.position, face));
|
||||
}
|
||||
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
|
||||
Block block = this.gm.world.getState(pos).getBlock();
|
||||
boolean flag = block != Blocks.air;
|
||||
|
||||
if(flag && this.damage == 0.0F) {
|
||||
block.onStartBreak(this.gm.world, pos, this.gm.player);
|
||||
}
|
||||
|
||||
if(flag && block.getHardness(this.gm.player, this.gm.player.worldObj, pos) >= 1.0F) {
|
||||
this.destroyBlock(pos, face);
|
||||
this.delay = 3;
|
||||
}
|
||||
else {
|
||||
this.hitting = true;
|
||||
this.position = pos;
|
||||
this.stack = this.gm.player.getHeldItem();
|
||||
this.damage = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void resetProgress() {
|
||||
if(this.hitting) {
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.position, Facing.DOWN));
|
||||
this.hitting = false;
|
||||
this.damage = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
public void resetInteraction() {
|
||||
this.interacting = false;
|
||||
}
|
||||
|
||||
public boolean damageBlock(LocalPos pos, Facing face) {
|
||||
if(this.interacting)
|
||||
return false;
|
||||
this.syncItem();
|
||||
|
||||
if(this.delay > 0) {
|
||||
--this.delay;
|
||||
return true;
|
||||
}
|
||||
else if(this.isHitting(pos)) {
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
|
||||
Block block = this.gm.world.getState(pos).getBlock();
|
||||
|
||||
if(block == Blocks.air) {
|
||||
this.hitting = false;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
this.damage += block.getHardness(this.gm.player, this.gm.player.worldObj, pos);
|
||||
|
||||
if(this.damage >= 1.0F) {
|
||||
this.hitting = false;
|
||||
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, pos, face));
|
||||
if(block != Blocks.air) {
|
||||
block.onStartBreak(this.gm.world, pos, this.gm.player);
|
||||
if(this.gm.player.canHarvestBlock(block))
|
||||
this.destroyBlock(pos, face);
|
||||
this.damage = 0.0F;
|
||||
this.delay = 5;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return this.clickBlock(pos, face);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,18 +99,6 @@ public class PlayerController {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isHitting(LocalPos pos) {
|
||||
ItemStack stack = this.gm.player.getHeldItem();
|
||||
boolean flag = this.stack == null && stack == null;
|
||||
|
||||
if(this.stack != null && stack != null) {
|
||||
flag = stack.getItem() == this.stack.getItem()
|
||||
&& ItemStack.dataEquals(stack, this.stack);
|
||||
}
|
||||
|
||||
return pos.equals(this.position) && flag;
|
||||
}
|
||||
|
||||
private void syncItem() {
|
||||
int slot = this.gm.player.getSelectedIndex();
|
||||
|
||||
|
@ -294,10 +209,6 @@ public class PlayerController {
|
|||
player.stopUsingItem();
|
||||
}
|
||||
|
||||
public boolean isHittingBlock() {
|
||||
return this.hitting;
|
||||
}
|
||||
|
||||
public int getUseCooldown() {
|
||||
return this.itemUseCooldown;
|
||||
}
|
||||
|
@ -309,8 +220,4 @@ public class PlayerController {
|
|||
public void resetUseCooldown() {
|
||||
this.itemUseCooldown = 0;
|
||||
}
|
||||
|
||||
public float getDamage(LocalPos pos) {
|
||||
return this.hitting && pos.equals(this.position) ? this.damage : 0.0f;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue