Skip to content

Commit

Permalink
Merge branch 'dev' into duplicate-macro-indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Bitlett authored Jun 8, 2023
2 parents 73cbe24 + cffa749 commit 0c77f39
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tools.redstone.redstonetools.features.commands;

import com.google.auto.service.AutoService;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.command.ServerCommandSource;
import tools.redstone.redstonetools.RedstoneToolsClient;
import tools.redstone.redstonetools.features.AbstractFeature;
import tools.redstone.redstonetools.features.Feature;
import tools.redstone.redstonetools.features.arguments.Argument;
import tools.redstone.redstonetools.features.feedback.Feedback;
import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature;

import static tools.redstone.redstonetools.features.arguments.serializers.FloatSerializer.floatArg;

@AutoService(AbstractFeature.class)
@Feature(name = "Air Place", description = "Allows you to place blocks in the air.", command = "airplace")
public class AirPlaceReachFeature extends CommandFeature {

public float reach = 5.0f;

public static final Argument<Float> distance = Argument
.ofType(floatArg(5.0f));

@Override
protected Feedback execute(ServerCommandSource source) throws CommandSyntaxException {

reach = distance.getValue();

AirPlaceFeature airPlaceFeature = RedstoneToolsClient.INJECTOR.getInstance(AirPlaceFeature.class);
if (!airPlaceFeature.isEnabled()) {
airPlaceFeature.enable(source);
}

return Feedback.success("Air Place reach set to " + distance.getValue().toString() + " blocks.");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,33 @@ public boolean isEnabled() {
return enabled;
}

private int toggle(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
enabled = !enabled;
public int toggle(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return toggle(context.getSource());
}

return enabled ? onEnable(context.getSource()) : onDisable(context.getSource());
public int toggle(ServerCommandSource source) throws CommandSyntaxException {
return !enabled ? enable(source) : disable(source);
}

//TODO: these need to be replaced when the sendMessage util gets made.
protected int onEnable(ServerCommandSource source) throws CommandSyntaxException {
public int enable(ServerCommandSource source) throws CommandSyntaxException {
enabled = true;
INJECTOR.getInstance(FeedbackSender.class).sendFeedback(source, Feedback.success(info.name() + " has been enabled."));

return 0;
}

protected int onDisable(ServerCommandSource source) throws CommandSyntaxException {
INJECTOR.getInstance(FeedbackSender.class).sendFeedback(source, Feedback.success(info.name() + " has been disabled."));
public int enable(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return enable(context.getSource());
}

public int disable(ServerCommandSource source) throws CommandSyntaxException {
enabled = false;
INJECTOR.getInstance(FeedbackSender.class).sendFeedback(source, Feedback.success(info.name() + " has been disabled."));
return 0;
}

public int disable(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return disable(context.getSource());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import tools.redstone.redstonetools.RedstoneToolsClient;
import tools.redstone.redstonetools.features.commands.AirPlaceReachFeature;
import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature;

@Mixin(MinecraftClient.class)
public class AirplaceMixin {
public class AirPlaceClientMixin {
private final AirPlaceFeature airPlaceFeature = RedstoneToolsClient.INJECTOR.getInstance(AirPlaceFeature.class);
private final AirPlaceReachFeature airPlaceReachFeature = RedstoneToolsClient.INJECTOR.getInstance(AirPlaceReachFeature.class);

@Shadow
public HitResult crosshairTarget;
Expand Down Expand Up @@ -70,10 +72,7 @@ private Vec3d getAirplaceHitResult() {
assert getInteractionManager() != null;
assert getPlayer() != null;

var reach = getInteractionManager().getReachDistance();
var hitResult = getPlayer().raycast(reach, 0, false);

return hitResult.getPos();
return getPlayer().raycast(airPlaceReachFeature.reach, 0, false).getPos();
}

private MinecraftClient getMinecraftClient() {
Expand All @@ -87,4 +86,5 @@ private ClientPlayerEntity getPlayer() {
private ClientPlayerInteractionManager getInteractionManager() {
return getMinecraftClient().interactionManager;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tools.redstone.redstonetools.mixin.features;

import net.minecraft.server.network.ServerPlayNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import tools.redstone.redstonetools.RedstoneToolsClient;
import tools.redstone.redstonetools.features.commands.AirPlaceReachFeature;
import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature;

@Mixin(ServerPlayNetworkHandler.class)
public class AirPlaceServerMixin {

private final AirPlaceFeature airPlaceFeature = RedstoneToolsClient.INJECTOR.getInstance(AirPlaceFeature.class);
private final AirPlaceReachFeature airPlaceReachFeature = RedstoneToolsClient.INJECTOR.getInstance(AirPlaceReachFeature.class);

@ModifyConstant(method = "onPlayerInteractBlock", constant = @Constant(doubleValue = 64.0) )
private double modifyConstant(double originalValue) {

if (airPlaceFeature.isEnabled()) {
return (airPlaceReachFeature.reach+5) * (airPlaceReachFeature.reach+5);
} else {
return originalValue;
}

}

}
3 changes: 2 additions & 1 deletion src/main/resources/redstonetools.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"defaultRequire": 1
},
"mixins": [
"features.AirPlaceServerMixin",
"features.AutoDustMixin",
"features.CopyStateMixin",
"gamerules.DoContainerDropsMixin",
Expand All @@ -15,7 +16,7 @@
],
"client": [
"accessors.MinecraftClientAccessor",
"features.AirplaceMixin",
"features.AirPlaceClientMixin",
"macros.AddMacroButtonMixin",
"macros.InitializeMacroManagerMixin",
"macros.KeyBindingMixinImpl",
Expand Down

0 comments on commit 0c77f39

Please sign in to comment.