Skip to content

Commit

Permalink
accurate placement V3 (#7)
Browse files Browse the repository at this point in the history
* Attempting to fix accurate placement protocol for the Crafter (Doesn't yet work)

* Fixed Accurate Placement Protocol with V3

* cleanup

* cleanup

* cleanup

* Add Servux detection

* Add Servux detection
  • Loading branch information
sakura-ryoko authored Jun 30, 2024
1 parent b30bd0e commit 36a640f
Show file tree
Hide file tree
Showing 15 changed files with 554 additions and 198 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.9

# 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
10 changes: 10 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/Tweakeroo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ 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);
}
}
*/
}
2 changes: 1 addition & 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,7 @@ 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_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
7 changes: 5 additions & 2 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) or with Servux.\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,7 +47,6 @@ 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 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.");
Expand Down Expand Up @@ -117,7 +119,8 @@ 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,
CLIENT_PLACEMENT_ROTATION,
//DEBUG_LOGGING,
FAST_LEFT_CLICK_ALLOW_TOOLS,
Expand Down
4 changes: 2 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,7 @@ 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_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 +94,7 @@ public class Hotkeys
SKIP_WORLD_RENDERING,
STAND_UP_NEARBY_PETS,
SWAP_ELYTRA_CHESTPLATE,
TOGGLE_CARPET_AP_PROTOCOL,
TOGGLE_AP_PROTOCOL,
TOGGLE_GRAB_CURSOR,
TOOL_PICK,
WRITE_MAPS_AS_IMAGES,
Expand Down
52 changes: 52 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,52 @@
package fi.dy.masa.tweakeroo.data;

import net.minecraft.util.Identifier;

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

private DataManager()
{
}

public static DataManager getInstance() { return INSTANCE; }

public void reset(boolean isLogout)
{
if (isLogout)
{
//Tweakeroo.logger.info("DataManager#reset() - log-out");
this.hasCarpetServer = false;
this.hasServuxServer = false;
}
//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;
}

public void setHasServuxServer(boolean toggle)
{
this.hasServuxServer = toggle;
}

public boolean hasServuxServer()
{
return this.hasServuxServer;
}
}
24 changes: 1 addition & 23 deletions src/main/java/fi/dy/masa/tweakeroo/mixin/MixinBlockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private MixinBlockItem(Item.Settings builder)
super(builder);
}

@Shadow protected abstract BlockState getPlacementState(ItemPlacementContext context);
@Shadow protected abstract boolean canPlace(ItemPlacementContext context, BlockState state);
@Shadow public abstract Block getBlock();

Expand All @@ -41,32 +40,11 @@ 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.applyPlacementProtocolToPlacementState(stateOrig, context));
}
}
}

/*
@Redirect(method = "place(Lnet/minecraft/item/ItemPlacementContext)Lnet/minecraft/util/ActionResult;",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/item/BlockItem;getBlockState(" +
"Lnet/minecraft/item/ItemPlacementContext;)" +
"Lnet/minecraft/block/BlockState;"))
private BlockState modifyPlacementState(BlockItem item, ItemPlacementContext ctx)
{
BlockState stateOriginal = this.getBlockState(ctx);
// the state can be null in 1.13+
if (stateOriginal != null && Configs.Generic.CLIENT_PLACEMENT_ROTATION.getBooleanValue())
{
UseContext context = UseContext.from(ctx, Hand.MAIN);
return PlacementHandler.getStateForPlacement(stateOriginal, context);
}
return stateOriginal;
}
*/

@Override
public int getMaxStackSize(ItemStack stack)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.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))
{
DataManager.getInstance().setHasCarpetServer(true);
}
else if (packet.payload().getId().id().equals(DataManager.SERVUX_ENTITY_DATA))
{
DataManager.getInstance().setHasServuxServer(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package fi.dy.masa.tweakeroo.mixin;

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;
import fi.dy.masa.tweakeroo.data.DataManager;
import fi.dy.masa.tweakeroo.data.ServerDataSyncer;
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks;
import fi.dy.masa.tweakeroo.util.MiscUtils;

Expand Down Expand Up @@ -52,4 +54,17 @@ 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))
{
DataManager.getInstance().setHasCarpetServer(true);
}
else if (payload.getId().id().equals(DataManager.SERVUX_ENTITY_DATA))
{
DataManager.getInstance().setHasServuxServer(true);
}
}
}
Loading

0 comments on commit 36a640f

Please sign in to comment.