added logic to retry use if attack successful.
This commit is contained in:
1 parent
9601ab9973
commit
786ae4ae7f
1 file changed
+46
-9
@@ -22,6 +22,7 @@ import net.minecraft.util.math.MathHelper;
|
|||||||
import net.minecraft.util.math.Vec2f;
|
import net.minecraft.util.math.Vec2f;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@@ -197,15 +198,30 @@ public class EntityPlayerActionPack
|
|||||||
|
|
||||||
public void onUpdate()
|
public void onUpdate()
|
||||||
{
|
{
|
||||||
boolean used = false;
|
Map<ActionType, Boolean> actionAttempts = new HashMap<>();
|
||||||
actions.entrySet().removeIf((e) -> e.getValue().done);
|
actions.entrySet().removeIf((e) -> e.getValue().done);
|
||||||
for (Map.Entry<ActionType, Action> e : actions.entrySet())
|
for (Map.Entry<ActionType, Action> e : actions.entrySet())
|
||||||
{
|
{
|
||||||
Action action = e.getValue();
|
Action action = e.getValue();
|
||||||
if (used && e.getKey() == ActionType.ATTACK)
|
// skipping attack if use was successful
|
||||||
continue;
|
if (!(actionAttempts.getOrDefault(ActionType.USE, false) && e.getKey() == ActionType.ATTACK))
|
||||||
if (action.tick(this, e.getKey()))
|
{
|
||||||
used = true;
|
Boolean actionStatus = action.tick(this, e.getKey());
|
||||||
|
if (actionStatus != null)
|
||||||
|
actionAttempts.put(e.getKey(), actionStatus);
|
||||||
|
}
|
||||||
|
// optionally retrying use after successful attack and unsuccessful use
|
||||||
|
if ( e.getKey() == ActionType.ATTACK
|
||||||
|
&& actionAttempts.getOrDefault(ActionType.ATTACK, false)
|
||||||
|
&& !actionAttempts.getOrDefault(ActionType.USE, true) )
|
||||||
|
{
|
||||||
|
// according to MinecraftClient.handleInputEvents
|
||||||
|
Action using = actions.get(ActionType.USE);
|
||||||
|
if (using != null) // this is always true - we know use worked, but just in case
|
||||||
|
{
|
||||||
|
using.retry(this, ActionType.USE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (forward != 0.0F)
|
if (forward != 0.0F)
|
||||||
{
|
{
|
||||||
@@ -316,7 +332,7 @@ public class EntityPlayerActionPack
|
|||||||
player.resetLastAttackedTicks();
|
player.resetLastAttackedTicks();
|
||||||
player.updateLastActionTime();
|
player.updateLastActionTime();
|
||||||
player.swingHand(Hand.MAIN_HAND);
|
player.swingHand(Hand.MAIN_HAND);
|
||||||
break;
|
return true;
|
||||||
}
|
}
|
||||||
case BLOCK: {
|
case BLOCK: {
|
||||||
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
||||||
@@ -328,6 +344,7 @@ public class EntityPlayerActionPack
|
|||||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||||
BlockPos pos = blockHit.getBlockPos();
|
BlockPos pos = blockHit.getBlockPos();
|
||||||
Direction side = blockHit.getSide();
|
Direction side = blockHit.getSide();
|
||||||
|
// rather should be canNotMine
|
||||||
if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false;
|
if (player.canMine(player.world, pos, player.interactionManager.getGameMode())) return false;
|
||||||
if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
|
if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
|
||||||
{
|
{
|
||||||
@@ -335,10 +352,12 @@ public class EntityPlayerActionPack
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BlockState state = player.world.getBlockState(pos);
|
BlockState state = player.world.getBlockState(pos);
|
||||||
|
boolean blockBroken = false;
|
||||||
if (player.interactionManager.getGameMode().isCreative())
|
if (player.interactionManager.getGameMode().isCreative())
|
||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.server.getWorldHeight());
|
||||||
ap.blockHitDelay = 5;
|
ap.blockHitDelay = 5;
|
||||||
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
else if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
|
else if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
|
||||||
{
|
{
|
||||||
@@ -355,6 +374,8 @@ public class EntityPlayerActionPack
|
|||||||
if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
|
if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
|
||||||
{
|
{
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
|
//instamine??
|
||||||
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -369,13 +390,14 @@ public class EntityPlayerActionPack
|
|||||||
{
|
{
|
||||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight());
|
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.server.getWorldHeight());
|
||||||
ap.currentBlock = null;
|
ap.currentBlock = null;
|
||||||
|
blockBroken = true;
|
||||||
}
|
}
|
||||||
player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||||
|
|
||||||
}
|
}
|
||||||
player.updateLastActionTime();
|
player.updateLastActionTime();
|
||||||
player.swingHand(Hand.MAIN_HAND);
|
player.swingHand(Hand.MAIN_HAND);
|
||||||
break;
|
return blockBroken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -499,10 +521,10 @@ public class EntityPlayerActionPack
|
|||||||
return new Action(-1, interval, offset);
|
return new Action(-1, interval, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
Boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
||||||
{
|
{
|
||||||
next--;
|
next--;
|
||||||
boolean cancel = false;
|
Boolean cancel = null;
|
||||||
if (next <= 0) {
|
if (next <= 0) {
|
||||||
|
|
||||||
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
||||||
@@ -527,5 +549,20 @@ public class EntityPlayerActionPack
|
|||||||
}
|
}
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void retry(EntityPlayerActionPack actionPack, ActionType type)
|
||||||
|
{
|
||||||
|
//assuming action run but was unsuccesful that tick, but opportunity emerged to retry it, lets retry it.
|
||||||
|
if (!type.preventSpectator || !actionPack.player.isSpectator())
|
||||||
|
{
|
||||||
|
type.execute(actionPack.player, this);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
if (count == limit)
|
||||||
|
{
|
||||||
|
type.stop(actionPack.player, null);
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user