ghost blocks fix

This commit is contained in:
gnembon committed 2019-07-28 12:29:02 -03:00
1 parent e021ca39b2
commit f393a36eaa
6 files changed
+79 -10

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.4.8+build.155
# Mod Properties
mod_version = 1.0.1+v190726
mod_version = 1.0.2+v190728
maven_group = carpet
archives_base_name = fabric-carpet
@@ -0,0 +1,48 @@
package carpet.mixins;
import carpet.settings.CarpetSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.server.network.packet.PlayerInteractBlockC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.IWorld;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientPlayerInteractionManager.class)
public abstract class ClientPlayerInteractionManager_ghostBlocksMixin
{
@Shadow @Final private MinecraftClient client;
@Redirect(method = "breakBlock", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V")
)
private void requestServerStatusForBlock(Block block, IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1) {
if ((CarpetSettings.miningGhostBlockFix || (
!client.isInSingleplayer() &&
!client.isIntegratedServerRunning() &&
client.getNetworkHandler().getCommandDispatcher().getRoot().getChild("carpet") == null)) &&
blockState_1.getHardness(client.world, blockPos_1) > 0.0 &&
blockState_1.getCollisionShape(iWorld_1, blockPos_1) != VoxelShapes.empty()
)
{
client.getNetworkHandler().sendPacket(new PlayerInteractBlockC2SPacket(
Hand.MAIN_HAND,
new BlockHitResult(new Vec3d(blockPos_1), Direction.DOWN, blockPos_1, false)
));
}
}
}
@@ -3,21 +3,23 @@ package carpet.mixins;
import carpet.settings.CarpetSettings;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.network.packet.PlayerActionC2SPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
//needs tests, WIP
@Mixin(ServerPlayerInteractionManager.class)
public class ServerPlayerInteractionManager_ghostBlocksMixin
{
@Shadow public ServerPlayerEntity player;
@Redirect(method = "method_14263", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;calcBlockBreakingDelta(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F")
@@ -27,12 +29,21 @@ public class ServerPlayerInteractionManager_ghostBlocksMixin
// main args
BlockPos blockPos_1a, PlayerActionC2SPacket.Action playerActionC2SPacket$Action_1, Direction direction_1, int int_1)
{
if (CarpetSettings.miningGhostBlockFix && playerActionC2SPacket$Action_1 == PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK)
float progress = blockState.calcBlockBreakingDelta(playerEntity_1, blockView_1, blockPos_1);
if (CarpetSettings.miningGhostBlockFix &&
(playerActionC2SPacket$Action_1 == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) &&
!playerEntity_1.onGround &&
progress >= 0.2
)
return progress*5;
if (CarpetSettings.miningGhostBlockFix &&
(playerActionC2SPacket$Action_1 == PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK)
)
return 1.0f;
return blockState.calcBlockBreakingDelta(playerEntity_1, blockView_1, blockPos_1);
return progress;
}
/*
@ModifyConstant(method = "method_14263",
constant = @Constant(doubleValue = 36D))
private double addDistance(double original) {
@@ -40,4 +51,10 @@ public class ServerPlayerInteractionManager_ghostBlocksMixin
return 1024D;
return original;
}
@Inject(method = "method_14263", at = @At("HEAD"))
private void logAction(BlockPos blockPos_1, PlayerActionC2SPacket.Action playerActionC2SPacket$Action_1, Direction direction_1, int int_1, CallbackInfo ci)
{
CarpetSettings.LOG.error("Got action: "+playerActionC2SPacket$Action_1+"("+int_1+")");
}
*/
}
@@ -26,7 +26,7 @@ import static carpet.settings.RuleCategory.SURVIVAL;
public class CarpetSettings
{
public static final String carpetVersion = "1.0.1-v190726";
public static final String carpetVersion = "1.0.2-v190728";
public static final Logger LOG = LogManager.getLogger();
public static boolean skipGenerationChecks = false;
public static boolean impendingFillSkipUpdates = false;
@@ -229,7 +229,7 @@ public class CarpetSettings
@Rule(desc = "smooth client animations with low tps settings", extra = "works only in SP, and will slow down players", category = CREATIVE)
public static boolean smoothClientAnimations;
//@Rule(desc="Fixes mining ghost blocks by allowing ANY mining speed from clients", category = SURVIVAL)
@Rule(desc="Fixes mining ghost blocks by allowing ANY mining speed from clients", category = SURVIVAL)
public static boolean miningGhostBlockFix;
private static class PushLimitLimits extends Validator<Integer> {
+4
View File
@@ -87,6 +87,8 @@
"PlayerEntity_horseFixMixin",
"ServerPlayerInteractionManager_ghostBlocksMixin",
"HopperBlockEntityMixin",
"ContainerMixin",
"ClientConnectionMixin",
@@ -128,6 +130,8 @@
"InGameHudMixin",
"PlayerListHudMixin",
"ClientPlayerInteractionManager_ghostBlocksMixin",
"BlockEntityRenderDispatcher_movableTEMixin",
"PistonBlockEntityRenderer_movableTEMixin"
],
+2 -2
View File
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "carpet",
"version": "1.0.1",
"version": "1.0.2",
"name": "Carpet Mod in Fabric",
"description": "Carpet made out of fabric",
@@ -25,7 +25,7 @@
"carpet.mixins.json"
],
"requires": {
"depends": {
"fabricloader": ">=0.4.0"
},
"suggests": {