Skip to content

Commit

Permalink
Attempting to fix accurate placement protocol for the Crafter (Doesn'…
Browse files Browse the repository at this point in the history
…t yet work)
  • Loading branch information
sakura-ryoko committed Jun 30, 2024
1 parent b30bd0e commit f240edf
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 168 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ author = masa
mod_file_name = tweakeroo-fabric

# Current mod version
mod_version = 0.20.999-sakura.8
mod_version = 0.20.999-sakura.8-accurate_placement.1

# Required malilib version
malilib_version = 0.19.999-sakura.3
malilib_id = b012771deb
malilib_version = 0.19.999-sakura.5
malilib_id = eed5e992ac

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import fi.dy.masa.malilib.event.InitializationHandler;
import fi.dy.masa.tweakeroo.config.Configs;

public class Tweakeroo implements ModInitializer
{
Expand All @@ -17,4 +18,12 @@ public void onInitialize()
{
InitializationHandler.getInstance().registerInitializationHandler(new InitHandler());
}

public static void debugLog(String msg, Object... args)
{
if (Configs.Generic.DEBUG_LOGGING.getBooleanValue())
{
Tweakeroo.logger.info(msg, args);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/fi/dy/masa/tweakeroo/config/Callbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public static void init(MinecraftClient mc)
Hotkeys.SIT_DOWN_NEARBY_PETS.getKeybind().setCallback((a, k) -> MiscUtils.commandNearbyPets(true));
Hotkeys.STAND_UP_NEARBY_PETS.getKeybind().setCallback((a, k) -> MiscUtils.commandNearbyPets(false));
Hotkeys.SWAP_ELYTRA_CHESTPLATE.getKeybind().setCallback(callbackGeneric);
Hotkeys.TOGGLE_CARPET_AP_PROTOCOL.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.Generic.CARPET_ACCURATE_PLACEMENT_PROTOCOL));
//Hotkeys.TOGGLE_CARPET_AP_PROTOCOL.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.Generic.CARPET_ACCURATE_PLACEMENT_PROTOCOL));
Hotkeys.TOGGLE_AP_PROTOCOL.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.Generic.ACCURATE_PLACEMENT_PROTOCOL));
Hotkeys.TOGGLE_GRAB_CURSOR.getKeybind().setCallback(callbackGeneric);
Hotkeys.TOOL_PICK.getKeybind().setCallback(callbackGeneric);
Hotkeys.WRITE_MAPS_AS_IMAGES.getKeybind().setCallback((a, k) -> MiscUtils.writeAllMapsAsImages());
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/fi/dy/masa/tweakeroo/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import fi.dy.masa.tweakeroo.Reference;
import fi.dy.masa.tweakeroo.tweaks.MiscTweaks;
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks;
import fi.dy.masa.tweakeroo.util.EasyPlacementProtocol;
import fi.dy.masa.tweakeroo.util.InventoryUtils;
import fi.dy.masa.tweakeroo.util.PlacementRestrictionMode;
import fi.dy.masa.tweakeroo.util.SnapAimMode;
Expand All @@ -36,6 +37,8 @@ public class Configs implements IConfigHandler

public static class Generic
{
public static final ConfigOptionList ACCURATE_PLACEMENT_PROTOCOL_MODE = new ConfigOptionList ("accuratePlacementProtocolMode", EasyPlacementProtocol.AUTO, "The type of \"accurate placement protocol\" to use.\n- Auto: Uses v3 in single player, and by default Slabs-only in multiplayer,\n unless the server has Carpet mod that sends a 'carpet:hello'\n packet, in which case v2 is used on that server.\n- Version 3: Supported by Tweakeroo itself (in single player) for now.\n- Version 2: Compatible with servers with the Carpet mod\n (either QuickCarpet by skyrising and DeadlyMC,\n or CarpetExtra in addition to FabricCarpet.\n And in both cases the 'accurateBlockPlacement' Carpet rule needs\n to be enabled on the server).\n- Slabs only: Only fixes top slabs. Compatible with Paper servers.\n- None: Does not modify coordinates.");
public static final ConfigBoolean ACCURATE_PLACEMENT_PROTOCOL = new ConfigBoolean ("accuratePlacementProtocol", true, "If enabled, then the Flexible Block Placement and the\nAccurate Block Placement use the protocol implemented in Carpet mod.\n§6Note: This is required for any block rotations to work, other than\n§6blocks that only care about the block side you click on (Hoppers, Logs etc.)");
public static final ConfigInteger AFTER_CLICKER_CLICK_COUNT = new ConfigInteger ("afterClickerClickCount", 1, 1, 32, "The number of right clicks to do per placed block when\ntweakAfterClicker is enabled");
public static final ConfigDouble ANGEL_BLOCK_PLACEMENT_DISTANCE = new ConfigDouble ("angelBlockPlacementDistance", 3, 1, 5, "The distance from the player blocks can be placed in\nthe air when tweakAngelBlock is enabled.\n5 is the maximum the server allows.");
public static final ConfigDouble BLOCK_REACH_DISTANCE = new ConfigDouble ("blockReachDistance", 4.5, 1, 64, "The block reach distance to use if the override tweak is enabled.\nThe maximum the game allows is 64.\n§6Do not attempt to use this at a value beyond\n[0.5 - 1.0] higher than the Game Rules defined on a server.");
Expand All @@ -44,10 +47,10 @@ public static class Generic
public static final ConfigOptionList BREAKING_RESTRICTION_MODE = new ConfigOptionList ("breakingRestrictionMode", PlacementRestrictionMode.LINE, "The Breaking Restriction mode to use (hotkey-selectable)");
public static final ConfigColor CHAT_BACKGROUND_COLOR = new ConfigColor ("chatBackgroundColor", "#80000000", "The background color for the chat messages,\nif 'tweakChatBackgroundColor' is enabled");
public static final ConfigString CHAT_TIME_FORMAT = new ConfigString ("chatTimeFormat", "[HH:mm:ss]", "The time format for chat messages, if tweakChatTimestamp is enabled\nUses the Java SimpleDateFormat format specifiers.");
public static final ConfigBoolean CARPET_ACCURATE_PLACEMENT_PROTOCOL = new ConfigBoolean ("carpetAccuratePlacementProtocol", true, "If enabled, then the Flexible Block Placement and the\nAccurate Block Placement use the protocol implemented in Carpet mod.\n§6Note: This is required for any block rotations to work, other than\n§6blocks that only care about the block side you click on (Hoppers, Logs etc.)");
//public static final ConfigBoolean CARPET_ACCURATE_PLACEMENT_PROTOCOL = new ConfigBoolean ("carpetAccuratePlacementProtocol", true, "If enabled, then the Flexible Block Placement and the\nAccurate Block Placement use the protocol implemented in Carpet mod.\n§6Note: This is required for any block rotations to work, other than\n§6blocks that only care about the block side you click on (Hoppers, Logs etc.)");
public static final ConfigBoolean CLIENT_PLACEMENT_ROTATION = new ConfigBoolean ("clientPlacementRotation", true, "Enable single player and client side placement rotations,\nsuch as Accurate Placement working in single player without Carpet mod");
public static final ConfigInteger CUSTOM_INVENTORY_GUI_SCALE = new ConfigInteger ("customInventoryGuiScale", 2, 1, 10, "The GUI scale value to use for inventory screens, if\n§etweakCustomInventoryScreenScale§r is enabled.");
//public static final ConfigBoolean DEBUG_LOGGING = new ConfigBoolean ("debugLogging", false, "Enables some debug log messages in the game console,\nfor debugging certain issues or crashes.");
public static final ConfigBoolean DEBUG_LOGGING = new ConfigBoolean ("debugLogging", false, "Enables some debug log messages in the game console,\nfor debugging certain issues or crashes.");
public static final ConfigOptionList ELYTRA_CAMERA_INDICATOR = new ConfigOptionList ("elytraCameraIndicator", ActiveMode.WITH_KEY, "Whether or not to render the real pitch angle\nindicator when the elytra camera mode is active");
public static final ConfigDouble ENTITY_REACH_DISTANCE = new ConfigDouble ("entityReachDistance", 3.0, 1, 64, "The entity reach distance to use if the override tweak is enabled.\nThe maximum the game allows is 64.\n§6Do not attempt to use this at a value beyond\n[0.5 - 1.0] higher than the Game Rules defined on a server.");
public static final ConfigOptionList ENTITY_TYPE_ATTACK_RESTRICTION_WARN = new ConfigOptionList ("entityTypeAttackRestrictionWarn", MessageOutputType.MESSAGE, "Selects which type of warning message to show (if any)\nwhen the Entity Type Attack Restriction feature prevents attacking an entity");
Expand Down Expand Up @@ -117,9 +120,11 @@ public static class Generic
public static final ConfigDouble ZOOM_FOV = new ConfigDouble ("zoomFov", 30, 0.01, 359.99, "The FOV value used for the zoom feature");

public static final ImmutableList<IConfigBase> OPTIONS = ImmutableList.of(
CARPET_ACCURATE_PLACEMENT_PROTOCOL,
ACCURATE_PLACEMENT_PROTOCOL_MODE,
ACCURATE_PLACEMENT_PROTOCOL,
//CARPET_ACCURATE_PLACEMENT_PROTOCOL,
CLIENT_PLACEMENT_ROTATION,
//DEBUG_LOGGING,
DEBUG_LOGGING,
FAST_LEFT_CLICK_ALLOW_TOOLS,
FAST_PLACEMENT_REMEMBER_ALWAYS,
FREE_CAMERA_PLAYER_INPUTS,
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/fi/dy/masa/tweakeroo/config/Hotkeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class Hotkeys
public static final ConfigHotkey SKIP_WORLD_RENDERING = new ConfigHotkey("skipWorldRendering", "", "Toggles skipping world rendering");
public static final ConfigHotkey STAND_UP_NEARBY_PETS = new ConfigHotkey("standUpNearbyPets", "", "Makes all nearby pets stand up");
public static final ConfigHotkey SWAP_ELYTRA_CHESTPLATE = new ConfigHotkey("swapElytraChestplate", "", "Swaps the currently equipped item in the chest slot between an Elytra and a Chest Plate");
public static final ConfigHotkey TOGGLE_CARPET_AP_PROTOCOL = new ConfigHotkey("toggleCarpetAccuratePlacementProtocol", "", "Toggles the value of the Generic -> 'carpetAccuratePlacementProtocol' option");
//public static final ConfigHotkey TOGGLE_CARPET_AP_PROTOCOL = new ConfigHotkey("toggleCarpetAccuratePlacementProtocol", "", "Toggles the value of the Generic -> 'carpetAccuratePlacementProtocol' option");
public static final ConfigHotkey TOGGLE_AP_PROTOCOL = new ConfigHotkey("toggleAccuratePlacementProtocol", "", "Toggles the value of the Generic -> 'accuratePlacementProtocol' option");
public static final ConfigHotkey TOGGLE_GRAB_CURSOR = new ConfigHotkey("toggleGrabCursor", "", "Grabs or ungrabs the mouse cursor, depending on the current state");
public static final ConfigHotkey TOOL_PICK = new ConfigHotkey("toolPick", "", "Switches to the effective tool for the targeted block");
public static final ConfigHotkey WRITE_MAPS_AS_IMAGES = new ConfigHotkey("writeMapsAsImages", "", "Writes all the currently available maps as images\nto the 'config/tweakeroo/map_images/<worldname>/' directory");
Expand Down Expand Up @@ -94,7 +95,8 @@ public class Hotkeys
SKIP_WORLD_RENDERING,
STAND_UP_NEARBY_PETS,
SWAP_ELYTRA_CHESTPLATE,
TOGGLE_CARPET_AP_PROTOCOL,
//TOGGLE_CARPET_AP_PROTOCOL,
TOGGLE_AP_PROTOCOL,
TOGGLE_GRAB_CURSOR,
TOOL_PICK,
WRITE_MAPS_AS_IMAGES,
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/data/DataManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fi.dy.masa.tweakeroo.data;

import net.minecraft.util.Identifier;

public class DataManager
{
private static final DataManager INSTANCE = new DataManager();
private boolean hasCarpetServer;
public static final Identifier CARPET_HELLO = Identifier.of("carpet", "hello");

private DataManager()
{
}

public static DataManager getInstance() { return INSTANCE; }

public void reset(boolean isLogout)
{
if (isLogout)
{
//Tweakeroo.logger.info("DataManager#reset() - log-out");
}
else
{
//Tweakeroo.logger.info("DataManager#reset() - dimension change or log-in");
}
}

public void setHasCarpetServer(boolean toggle)
{
this.hasCarpetServer = toggle;
}

public boolean hasCarpetServer()
{
return this.hasCarpetServer;
}
}
5 changes: 3 additions & 2 deletions src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBlockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ private void modifyPlacementState(ItemPlacementContext ctx, CallbackInfoReturnab
if (stateOrig != null && this.canPlace(ctx, stateOrig))
{
UseContext context = UseContext.from(ctx, ctx.getHand());
cir.setReturnValue(PlacementHandler.getStateForPlacement(stateOrig, context));
//cir.setReturnValue(PlacementHandler_V2Only.getStateForPlacement(stateOrig, context));
cir.setReturnValue(PlacementHandler.applyPlacementProtocolToPlacementState(stateOrig, context));
}
}
}
Expand All @@ -60,7 +61,7 @@ private BlockState modifyPlacementState(BlockItem item, ItemPlacementContext ctx
if (stateOriginal != null && Configs.Generic.CLIENT_PLACEMENT_ROTATION.getBooleanValue())
{
UseContext context = UseContext.from(ctx, Hand.MAIN);
return PlacementHandler.getStateForPlacement(stateOriginal, context);
return PlacementHandler_V2Only.getStateForPlacement(stateOriginal, context);
}
return stateOriginal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fi.dy.masa.tweakeroo.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import fi.dy.masa.tweakeroo.Tweakeroo;
import fi.dy.masa.tweakeroo.data.DataManager;

@Mixin(ClientCommonNetworkHandler.class)
public class MixinClientCommonNetworkHandler
{
@Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"))
private void tweakeroo_onCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci)
{
if (packet.payload().getId().id().equals(DataManager.CARPET_HELLO))
{
Tweakeroo.debugLog("ClientCommonNetworkHandler#tweakeroo_onCustomPayload(): received carpet hello packet");
DataManager.getInstance().setHasCarpetServer(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package fi.dy.masa.tweakeroo.mixin;

import fi.dy.masa.tweakeroo.Tweakeroo;
import fi.dy.masa.tweakeroo.data.DataManager;
import fi.dy.masa.tweakeroo.data.ServerDataSyncer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.s2c.play.DeathMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import fi.dy.masa.tweakeroo.config.FeatureToggle;
Expand Down Expand Up @@ -52,4 +55,14 @@ private void onCommandTree(CallbackInfo ci)
ServerDataSyncer.getInstance().recheckOpStatus();
}
}

@Inject(method = "onCustomPayload", at = @At("HEAD"))
private void tweakeroo_onCustomPayload(CustomPayload payload, CallbackInfo ci)
{
if (payload.getId().id().equals(DataManager.CARPET_HELLO))
{
Tweakeroo.debugLog("MixinClientPlayNetworkHandler#tweakeroo_onCustomPayload(): received carpet hello packet");
DataManager.getInstance().setHasCarpetServer(true);
}
}
}
Loading

0 comments on commit f240edf

Please sign in to comment.