Since a lot of the logic in Mixins is identical to that in forge push the code into an interop class for reuse
.onKeyPressHandler(ClientProxy::toggleOuterBoxesOnly);
}
- private static ClientProxy instance;
- public static ClientProxy getInstance() {
- if(instance == null)
- instance = new ClientProxy();
- return instance;
- }
-
- private ClientProxy() {
- }
-
private boolean ready;
public static void toggleActive() {
EventBus.subscribe(AddBoundingBoxReceived.class, this::addBoundingBox);
EventBus.subscribe(RemoveBoundingBoxReceived.class, this::onRemoveBoundingBoxReceived);
EventBus.subscribe(UpdateWorldSpawnReceived.class, this::onUpdateWorldSpawnReceived);
+ EventBus.subscribe(SeedCommandTyped.class, this::onSeedCommandTyped);
renderer = new ClientRenderer(this::getCache);
KeyListener.init();
setSeed(seed);
}
+ private void onSeedCommandTyped(SeedCommandTyped event) {
+ setSeed(event.getSeed());
+ }
+
@Override
public void setSeed(long seed) {
super.setSeed(seed);
--- /dev/null
+package com.irtimaled.bbor.client.events;
+
+public class SeedCommandTyped {
+ private final Long seed;
+
+ public SeedCommandTyped(Long seed) {
+ this.seed = seed;
+ }
+
+ public Long getSeed() {
+ return seed;
+ }
+}
--- /dev/null
+package com.irtimaled.bbor.client.interop;
+
+import com.irtimaled.bbor.client.PlayerCoords;
+import com.irtimaled.bbor.client.events.ConnectedToRemoteServer;
+import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
+import com.irtimaled.bbor.client.events.Render;
+import com.irtimaled.bbor.client.events.SeedCommandTyped;
+import com.irtimaled.bbor.common.EventBus;
+import com.irtimaled.bbor.common.TypeHelper;
+import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.network.NetworkManager;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+public class ClientInterop {
+ public static void connectedToRemoteServer(NetworkManager networkManager) {
+ SocketAddress remoteAddress = networkManager.getRemoteAddress();
+ TypeHelper.doIfType(remoteAddress, InetSocketAddress.class, inetSocketAddress -> EventBus.publish(new ConnectedToRemoteServer(inetSocketAddress)));
+ }
+
+ public static void disconnectedFromRemoteServer() {
+ EventBus.publish(new DisconnectedFromRemoteServer());
+ }
+
+ public static void render(float partialTicks, EntityPlayerSP player) {
+ PlayerCoords.setPlayerPosition(partialTicks, player);
+ EventBus.publish(new Render(player.dimension));
+ }
+
+ public static boolean interceptChatMessage(String message) {
+ if (message.startsWith("/bbor:seed")) {
+ if (message.length() > 11) {
+ String argument = message.substring(11);
+ Long seed = parseNumericSeed(argument);
+ if (seed == null) {
+ seed = (long) argument.hashCode();
+ }
+ EventBus.publish(new SeedCommandTyped(seed));
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private static Long parseNumericSeed(String argument) {
+ try {
+ return Long.parseLong(argument);
+ } catch (final NumberFormatException ex) {
+ return null;
+ }
+ }
+}
--- /dev/null
+package com.irtimaled.bbor.common.interop;
+
+import com.irtimaled.bbor.common.EventBus;
+import com.irtimaled.bbor.common.events.*;
+import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.ServerPlayer;
+import com.irtimaled.bbor.config.ConfigManager;
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockMobSpawner;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.network.NetworkManager;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
+import net.minecraft.world.chunk.Chunk;
+
+import java.io.File;
+
+public class CommonInterop {
+ public static void init() {
+ ConfigManager.loadConfig(new File("."));
+ }
+
+ public static void chunkLoaded(Chunk chunk) {
+ EventBus.publish(new ChunkLoaded(chunk));
+ }
+
+ public static void loadWorlds(WorldServer[] worlds) {
+ for (WorldServer world : worlds) {
+ EventBus.publish(new WorldLoaded(world));
+ }
+ }
+
+ public static void tick() {
+ EventBus.publish(new ServerTick());
+ }
+
+ public static void worldTick(WorldServer worldServer) {
+ EventBus.publish(new ServerWorldTick(worldServer));
+ }
+
+ public static void playerLoggedIn(EntityPlayerMP player) {
+ NetHandlerPlayServer connection = player.connection;
+ if (connection == null) return;
+
+ NetworkManager networkManager = connection.netManager;
+ if (networkManager.isLocalChannel()) return;
+
+ EventBus.publish(new PlayerLoggedIn(new ServerPlayer(player)));
+ }
+
+ public static void playerLoggedOut(EntityPlayerMP player) {
+ EventBus.publish(new PlayerLoggedOut(new ServerPlayer(player)));
+ }
+
+ public static void tryHarvestBlock(Block block, BlockPos pos, World world) {
+ if(block instanceof BlockMobSpawner) {
+ EventBus.publish(new MobSpawnerBroken(world.dimension.getType().getId(), new Coords(pos)));
+ }
+ }
+}
package com.irtimaled.bbor.mixin.client;
import com.irtimaled.bbor.client.ClientProxy;
-import com.irtimaled.bbor.config.ConfigManager;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfiguration;
import org.spongepowered.asm.mixin.Mixin;
@Inject(method = "<init>", at = @At("RETURN"))
private void constructor(GameConfiguration configuration, CallbackInfo ci) {
- ConfigManager.loadConfig(configuration.folderInfo.gameDir);
- clientProxy = ClientProxy.getInstance();
+ CommonInterop.init();
+ clientProxy = new ClientProxy();
}
@Inject(method = "init", at = @At("RETURN"))
package com.irtimaled.bbor.mixin.client.entity;
-import com.irtimaled.bbor.client.ClientProxy;
+import com.irtimaled.bbor.client.interop.ClientInterop;
import net.minecraft.client.entity.EntityPlayerSP;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
public abstract class MixinEntityPlayerSP {
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void sendChatMessage(String message, CallbackInfo ci) {
- if(message.startsWith("/bbor:seed")) {
- if(message.length()<11) return;
-
- String argument = message.substring(11);
- Long seed = parseNumericSeed(argument);
- if(seed == null) {
- seed = (long) argument.hashCode();
- }
- ClientProxy.getInstance().setSeed(seed);
+ if(ClientInterop.interceptChatMessage(message))
ci.cancel();
- }
- }
-
- private Long parseNumericSeed(String argument) {
- try {
- return Long.parseLong(argument);
- } catch (final NumberFormatException ex) {
- return null;
- }
}
}
if (button.y >= top && button.y < bottom)
button.y -= 12;
}
- this.addButton(new SettingsScreenButton(200, this.width / 2 - 155, top + 84, 150, "BBOR", this));
+ this.addButton(new SettingsScreenButton(199, this.width / 2 - 155, top + 84, 150, "BBOR", this));
}
}
package com.irtimaled.bbor.mixin.client.multiplayer;
-import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
-import com.irtimaled.bbor.common.EventBus;
+import com.irtimaled.bbor.client.interop.ClientInterop;
import net.minecraft.client.multiplayer.WorldClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
public class MixinWorldClient {
@Inject(method = "sendQuittingDisconnectingPacket", at = @At("RETURN"))
private void sendQuittingDisconnectingPacket(CallbackInfo ci) {
- EventBus.publish(new DisconnectedFromRemoteServer());
+ ClientInterop.disconnectedFromRemoteServer();
}
}
package com.irtimaled.bbor.mixin.client.network;
-import com.irtimaled.bbor.client.events.ConnectedToRemoteServer;
-import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.TypeHelper;
+import com.irtimaled.bbor.client.interop.ClientInterop;
import net.minecraft.client.network.NetHandlerLoginClient;
import net.minecraft.network.NetworkManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-
@Mixin(NetHandlerLoginClient.class)
public abstract class MixinNetHandlerLoginClient {
@Shadow
@Inject(method = "handleLoginSuccess", at = @At(value = "RETURN"))
private void handleLoginSuccess(CallbackInfo ci) {
- SocketAddress remoteAddress = this.networkManager.getRemoteAddress();
- TypeHelper.doIfType(remoteAddress, InetSocketAddress.class, inetSocketAddress -> {
- EventBus.publish(new ConnectedToRemoteServer(inetSocketAddress));
- });
+ ClientInterop.connectedToRemoteServer(networkManager);
}
@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onDisconnect(CallbackInfo ci) {
- EventBus.publish(new DisconnectedFromRemoteServer());
+ ClientInterop.disconnectedFromRemoteServer();
}
}
package com.irtimaled.bbor.mixin.client.network;
-import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer;
-import com.irtimaled.bbor.common.EventBus;
+import com.irtimaled.bbor.client.interop.ClientInterop;
import net.minecraft.client.network.NetHandlerPlayClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
public class MixinNetHandlerPlayClient {
@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onDisconnect(CallbackInfo ci) {
- EventBus.publish(new DisconnectedFromRemoteServer());
+ ClientInterop.disconnectedFromRemoteServer();
}
}
package com.irtimaled.bbor.mixin.client.renderer;
-import com.irtimaled.bbor.client.PlayerCoords;
-import com.irtimaled.bbor.client.events.Render;
-import com.irtimaled.bbor.common.EventBus;
+import com.irtimaled.bbor.client.interop.ClientInterop;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.EntityRenderer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@Inject(method = "updateCameraAndRender(FJ)V", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", args = "ldc=hand", shift = At.Shift.BEFORE))
private void render(float partialTicks, long ignored, CallbackInfo ci) {
- EntityPlayerSP player = this.mc.player;
- PlayerCoords.setPlayerPosition(partialTicks, player);
- EventBus.publish(new Render(player.dimension));
+ ClientInterop.render(partialTicks, this.mc.player);
}
}
@Shadow
public abstract void loadOptions();
- @Inject(method = "<init>()V", at = @At("RETURN"))
- private void init(CallbackInfo ci) {
- keyBindings = getKeysAll();
- }
-
- private KeyBinding[] getKeysAll() {
- return ArrayUtils.addAll(keyBindings, KeyListener.keyBindings());
- }
-
@Inject(method = "<init>(Lnet/minecraft/client/Minecraft;Ljava/io/File;)V", at = @At("RETURN"))
private void init(Minecraft minecraft, File file, CallbackInfo ci) {
- keyBindings = getKeysAll();
+ keyBindings = ArrayUtils.addAll(keyBindings, KeyListener.keyBindings());
this.loadOptions();
}
}
package com.irtimaled.bbor.mixin.server;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.events.ServerTick;
-import com.irtimaled.bbor.common.events.WorldLoaded;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import org.spongepowered.asm.mixin.Mixin;
@Inject(method = "initialWorldChunkLoad", at = @At("HEAD"))
private void initialWorldChunkLoad(CallbackInfo ci) {
- for (WorldServer world : worlds) {
- EventBus.publish(new WorldLoaded(world));
- }
+ CommonInterop.loadWorlds(worlds);
}
@Inject(method = "tick", at = @At("RETURN"))
private void tick(CallbackInfo ci) {
- EventBus.publish(new ServerTick());
+ CommonInterop.tick();
}
}
package com.irtimaled.bbor.mixin.server.dedicated;
import com.irtimaled.bbor.common.CommonProxy;
-import com.irtimaled.bbor.config.ConfigManager;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.server.dedicated.DedicatedServer;
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.CallbackInfoReturnable;
-import java.io.File;
-
@Mixin(DedicatedServer.class)
public class MixinDedicatedServer {
@Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServer;loadAllWorlds(Ljava/lang/String;Ljava/lang/String;JLnet/minecraft/world/WorldType;Lcom/google/gson/JsonElement;)V"))
private void init(CallbackInfoReturnable<Boolean> cir) {
- ConfigManager.loadConfig(new File("."));
+ CommonInterop.init();
new CommonProxy().init();
}
}
package com.irtimaled.bbor.mixin.server.management;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.TypeHelper;
-import com.irtimaled.bbor.common.events.MobSpawnerBroken;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.block.Block;
-import net.minecraft.block.BlockMobSpawner;
import net.minecraft.server.management.PlayerInteractionManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@Inject(method = "tryHarvestBlock", at = @At("HEAD"))
private void tryHarvestBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
Block block = this.world.getBlockState(pos).getBlock();
- TypeHelper.doIfType(block, BlockMobSpawner.class, ms ->
- EventBus.publish(new MobSpawnerBroken(this.world.dimension.getType().getId(), new Coords(pos))));
+ CommonInterop.tryHarvestBlock(block, pos, world);
}
}
package com.irtimaled.bbor.mixin.server.management;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.TypeHelper;
-import com.irtimaled.bbor.common.events.PlayerLoggedIn;
-import com.irtimaled.bbor.common.events.PlayerLoggedOut;
-import com.irtimaled.bbor.common.models.ServerPlayer;
-import io.netty.channel.local.LocalAddress;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
public class MixinPlayerList {
@Inject(method = "playerLoggedIn", at = @At("RETURN"))
private void playerLoggedIn(EntityPlayerMP player, CallbackInfo ci) {
- if (TypeHelper.as(player.connection.netManager.getRemoteAddress(), LocalAddress.class) != null) return;
- EventBus.publish(new PlayerLoggedIn(new ServerPlayer(player)));
+ CommonInterop.playerLoggedIn(player);
}
@Inject(method = "playerLoggedOut", at = @At("HEAD"))
private void playerLoggedOut(EntityPlayerMP player, CallbackInfo ci) {
- EventBus.publish(new PlayerLoggedOut(new ServerPlayer(player)));
+ CommonInterop.playerLoggedOut(player);
}
}
package com.irtimaled.bbor.mixin.world;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.events.ServerWorldTick;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.world.WorldServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
public class MixinWorldServer {
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/village/VillageCollection;tick()V", shift = At.Shift.AFTER))
private void afterVillageTick(CallbackInfo ci) {
- EventBus.publish(new ServerWorldTick((WorldServer) (Object) this));
+ CommonInterop.worldTick((WorldServer) (Object) this);
}
}
package com.irtimaled.bbor.mixin.world.chunk;
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.events.ChunkLoaded;
+import com.irtimaled.bbor.common.interop.CommonInterop;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
public class MixinChunk {
@Inject(method = "onLoad", at = @At("RETURN"))
private void onLoad(CallbackInfo ci) {
- EventBus.publish(new ChunkLoaded((Chunk) (Object) this));
+ CommonInterop.chunkLoaded((Chunk) (Object) this);
}
}