Skip to content

Commit

Permalink
compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
AV306 committed Jun 25, 2024
1 parent 5ff1290 commit e315022
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 129 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ processResources {

tasks.withType( JavaCompile ).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
it.options.release = 21

//it.options.compilerArgs.add( "--enable-preview" )
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
archives_base_name = xenon

# Complete Config
complete_config_version = 2.5.3
complete_config_version = 2.5.4

# SLF4J
slf4j_version = 2.0.7
Expand Down
2 changes: 1 addition & 1 deletion init
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sudo apt update

sudo apt install qt6-base-dev libqt6core5compat6 -y

sudo apt install tcpdump -y
#sudo apt install tcpdump -y

# Cleanup
sudo apt autoremove
14 changes: 8 additions & 6 deletions src/main/java/me/av306/xenon/MainInitializer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.av306.xenon;

import me.av306.xenon.packets.OptInPacketPayload;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
Expand All @@ -12,16 +13,17 @@ public class MainInitializer implements ModInitializer
@Override
public void onInitialize()
{
Xenon.INSTANCE.LOGGER.info( "Doing server-side initialisation..." );
//if ( )
Xenon.INSTANCE.LOGGER.info( "Doing logical server-side initialisation..." );

// TODO
ServerPlayConnectionEvents.JOIN.register( (handler, sender, server) ->
{
/*Packet packet = new P
PacketByteBuf pak = PacketByteBufs.create();
pak.writeString( "timer" );
sender.sendPacket( pak );
//sender.sendPacket( Xenon.INSTANCE.BLOCKED_FEATURE_PACKET, pak );*/
// Uncomment this line and replace the placeholder text
// with the name of the feature you wish to block.
// Timer and ProxRadar are blocked by default, and will be
// removed in a future version.
//sender.sendPacket( new OptOutPacketPayload( "[FEATURE_NAME_HERE]" ) );
} );
}
}
77 changes: 38 additions & 39 deletions src/main/java/me/av306/xenon/Xenon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import me.av306.xenon.features.movement.*;
import me.av306.xenon.features.render.*;
import me.av306.xenon.mixin.MinecraftClientAccessor;
import me.av306.xenon.packets.OptInPacketPayload;
import me.av306.xenon.packets.OptOutPacketPayload;
import me.av306.xenon.util.KeybindUtil;
import me.av306.xenon.util.text.TextFactory;
import me.lortseam.completeconfig.data.Config;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.Version;
Expand All @@ -26,6 +29,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;

import org.lwjgl.glfw.GLFW;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,8 +87,8 @@ public enum Xenon
/**
* Identifier for the opt-out packet
*/
public final Identifier BLOCKED_FEATURE_PACKET = new Identifier( this.MODID, "block_feature" );
public final Identifier PERMIT_FEATURE_PACKET = new Identifier( this.MODID, "permit_feature" );
public final Identifier BLOCK_FEATURE_PACKET_ID = new Identifier( this.MODID, "block_feature" );
public final Identifier PERMIT_FEATURE_PACKET_ID = new Identifier( this.MODID, "permit_feature" );

//private boolean updateAvailable = false;
//public boolean getUpdateAvailable() { return updateAvailable; }
Expand Down Expand Up @@ -116,7 +120,7 @@ public void initialise()
ClientWorldEvents.DISCONNECT.register( this::disableAllFeatures );

// Register packet handler
//registerPacketHandlers();
registerPacketHandlers();

// register features
initCommands();
Expand All @@ -127,46 +131,41 @@ public void initialise()
ConfigScreenBuilder.setMain( this.MODID, new ClothConfigScreenBuilder() );*/
}

/*private void registerPacketHandlers()
private void registerPacketHandlers()
{
ClientPlayNetworking.registerGlobalReceiver(
this.BLOCKED_FEATURE_PACKET,
(client, handler, buf, responseSender) ->
PayloadTypeRegistry.playS2C().register( OptOutPacketPayload.ID, OptOutPacketPayload.CODEC );
ClientPlayNetworking.registerGlobalReceiver( OptOutPacketPayload.ID, (payload, context) ->
{
try
{
String name = buf.readString();
IFeature feature = this.featureRegistry.get( name );
try
{
feature.setForceDisabled( true );
this.LOGGER.info( "Server blocks feature: {}", feature.getName() );
this.sendInfoMessage( "text.xenon.featureblocked", feature.getName() );
}
catch ( NullPointerException npe )
{
this.LOGGER.info( "Server blocks non-existent feature: {}", name );
}
this.featureRegistry.get( payload.featureName() ).setForceDisabled( true );
this.LOGGER.info( "{} blocked by server", payload.featureName() );
this.sendInfoMessage( "text.xenon.featureblocked", payload.featureName() );
}
);
catch ( NullPointerException npe )
{
// Feature not present, error
this.LOGGER.warn( "Server blocks non-existent feature {}", payload.featureName() );
}
} );

ClientPlayNetworking.registerGlobalReceiver(
this.PERMIT_FEATURE_PACKET,
(client, handler, buf, responseSender) ->
{
String name = buf.readString();
IFeature feature = this.featureRegistry.get( name );
try
{
feature.setForceDisabled( false );
this.LOGGER.info( "Server permits feature: {}", feature.getName() );
this.sendInfoMessage( "text.xenon.featurepermitted", feature.getName() );
}
catch ( NullPointerException npe )
{
this.LOGGER.info( "Server permits non-existent feature: {}", name );
}
}
);
}*/
PayloadTypeRegistry.playS2C().register( OptInPacketPayload.ID, OptInPacketPayload.CODEC );
ClientPlayNetworking.registerGlobalReceiver( OptInPacketPayload.ID, (payload, context) ->
{
try
{
this.featureRegistry.get( payload.featureName() ).setForceDisabled( false );
this.LOGGER.info( "{} blocked by server", payload.featureName() );
this.sendInfoMessage( "text.xenon.featurepermitted", payload.featureName() );
}
catch ( NullPointerException npe )
{
// Feature not present, error
this.LOGGER.warn( "Server permits non-existent feature {}", payload.featureName() );
}

} );
}

private void initCommands()
{
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/me/av306/xenon/event/GetFovEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ public interface GetFovEvent
}
);

Event<GetFovEvent2> EVENT2 = EventFactory.createArrayBacked(
GetFovEvent2.class,
(listeners) -> (fov) ->
{
for ( GetFovEvent2 listener : listeners )
{
ActionResult result = listener.interact( fov );

if ( result != ActionResult.PASS ) return result;
}

return ActionResult.PASS;
}
);

ActionResult interact( Camera camera, float tickDelta, boolean changingFov );

public interface GetFovEvent2
{
ActionResult interact( double fov );
}

public class EventData
{
public static double FOV_ZOOM_LEVEL = 1f;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/av306/xenon/feature/IFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected void keyEvent()
if ( this.keyBinding.wasPressed() )
if ( this.forceDisabled )
// Server wishes to opt out of this feature
this.sendErrorMessage( "text.xenon.ifeature.forcedisabled" );
this.sendErrorMessage( "text.xenon.ifeature.blocked", this.getName() );
else this.enable();
}

Expand All @@ -234,11 +234,11 @@ public void enable()

//this.isEnabled = true;

if ( this.isForceDisabled() )
/*if ( this.forceDisabled )
{
Xenon.INSTANCE.sendInfoMessage( "text.xenon.featureblocked" );
return;
}
}*/

Xenon.INSTANCE.LOGGER.info( this.getName() + " enabled!" );

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/me/av306/xenon/feature/IToggleableFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ protected ActionResult onKeyboardKey( long window, int key, int scanCode, int ac
protected void keyEvent()
{
if ( this.keyBinding.wasPressed() && !Xenon.INSTANCE.modifierKey.isPressed() )
this.toggle();
{
if ( this.forceDisabled )
Xenon.INSTANCE.sendErrorMessage( "text.xenon.ifeature.blocked", this.name );

else this.toggle();
}
}

@Override
Expand All @@ -107,7 +112,7 @@ public void enable()

this.isEnabled = true;

Xenon.INSTANCE.LOGGER.info( this.getName() + " enabled!" );
Xenon.INSTANCE.LOGGER.info( "{} enabled!", this.getName() );

Xenon.INSTANCE.enabledFeatures.add( this );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public ProximityRadarFeature()
{
super( "ProximityRadar", "proxradar", "pr" );

this.setForceDisabled( true );

// Perform entity scanning in the render thread
// because they're gonna be rendered somewhere before this anyway,
// and we're rendering stuff too
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/me/av306/xenon/mixin/BowItemMixin.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/me/av306/xenon/mixin/ChatScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin( ChatScreen.class )
public class ChatScreenMixin extends Screen
Expand Down Expand Up @@ -54,8 +53,5 @@ public void onSendMessage( String message, boolean addToHistory, CallbackInfo ci
ci.cancel();
return;
}

// Unlike Wurst, this doesn't let you modify the message.
// You shouldn't need to do that anyway.
}
}
7 changes: 5 additions & 2 deletions src/main/java/me/av306/xenon/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Mixin( EntityRenderer.class )
public class EntityRendererMixin<T extends Entity>
{
@SuppressWarnings( "unchecked" )
@Inject(
method = "hasLabel(Lnet/minecraft/entity/Entity;)Z",
at = @At( "HEAD" ),
Expand All @@ -39,7 +40,7 @@ else if ( result == ActionResult.FAIL )
at = @At(
value = "LOAD",
ordinal = 1
)
) // Target the read of the first local variable (the Text to be rendered)
)
private Text modifyLabelText( Text text, T entity, Text textOther, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light, float tickDelta )
{
Expand All @@ -50,6 +51,8 @@ private Text modifyLabelText( Text text, T entity, Text textOther, MatrixStack m

Text textOverride = EntityRendererEvents.EventData.LABEL_TEXT_OVERRIDE;

return EntityRendererEvents.EventData.SHOULD_OVERRIDE_LABEL_TEXT && textOverride != null ? EntityRendererEvents.EventData.LABEL_TEXT_OVERRIDE : text;
return EntityRendererEvents.EventData.SHOULD_OVERRIDE_LABEL_TEXT && textOverride != null ?
EntityRendererEvents.EventData.LABEL_TEXT_OVERRIDE :
text;
}
}
Loading

0 comments on commit e315022

Please sign in to comment.