Skip to content

Commit

Permalink
Update 1.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Sep 4, 2023
1 parent b922df1 commit d0fddea
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class KeyBindingAPI {

public static void registerKeyBinding(KeyBinding keyBinding) {
if (loaded) throw new IllegalStateException("Options are already loaded");
if (registeredKeyBindings.size() >= 9) // This limit will be fixed in future update!
throw new IllegalStateException("Cannot register more than 9 custom key-binds!");
if (registeredKeyBindings.size() >= 8) // This limit will be fixed in future update!
throw new IllegalStateException("Cannot register more than 8 custom key-binds!");
registeredKeyBindings.add(keyBinding);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.fox2code.foxloader.client.gui;

import net.minecraft.src.client.gui.Container;

/**
* Tells FoxLoader that the container is a wrapped container.
* <p>
* If your container has client side only inventory slots please use {@link InventoryClientOnly} too
*/
public interface ContainerWrapped {
Container getParentContainer();

static Container getNetworkContainer(Container container) {
int antiSoftLock = 0;
while (container instanceof ContainerWrapped) {
container = ((ContainerWrapped) container).getParentContainer();
if (antiSoftLock++>100) return null;
}
return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fox2code.foxloader.client.gui;

import net.minecraft.src.client.inventory.InventoryBasic;

public class InventoryBasicClientOnly extends InventoryBasic implements InventoryClientOnly {
public InventoryBasicClientOnly(String var1, int var2) {
super(var1, var2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fox2code.foxloader.client.gui;

import net.minecraft.src.client.inventory.IInventory;

/**
* Mark a {@link IInventory} as client side only, and to avoid any network inconsistencies
*/
public interface InventoryClientOnly extends IInventory {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.client.gui.ContainerWrapped;
import net.minecraft.src.client.gui.Container;
import net.minecraft.src.client.gui.GuiContainer;
import net.minecraft.src.client.gui.Slot;
import net.minecraft.src.game.entity.player.EntityPlayer;
import net.minecraft.src.game.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
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;

import java.util.List;


@Mixin(Container.class)
Expand All @@ -16,4 +25,14 @@ public void hotfix_onCraftGuiClosedHook(EntityPlayer var1, CallbackInfo ci) {
ci.cancel();
}
}

/**
* Disable default behaviour on wrapped container for better stability.
*/
@Inject(method = "quickMove", at = @At("HEAD"), cancellable = true)
public void onQuickMove(int var1, CallbackInfoReturnable<ItemStack> cir) {
if (this instanceof ContainerWrapped) {
cir.setReturnValue(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.client.CreativeItems;
import com.fox2code.foxloader.client.gui.ContainerWrapped;
import net.minecraft.src.client.gui.Container;
import net.minecraft.src.client.gui.ContainerCreative;
import net.minecraft.src.game.entity.player.EntityPlayer;
import net.minecraft.src.game.item.ItemStack;
Expand All @@ -14,11 +16,13 @@
import java.util.List;

@Mixin(ContainerCreative.class)
public abstract class MixinContainerCreative {
public abstract class MixinContainerCreative implements ContainerWrapped {
@Shadow public List<ItemStack> itemList;

@Shadow public abstract void addToSlot(ItemStack itemstack);

@Shadow private EntityPlayer player;

@Inject(method = "addItems", at = @At("HEAD"), cancellable = true)
public void onAddItems(EntityPlayer player, CallbackInfo ci) {
List<ItemStack> creativeItemStacks =
Expand All @@ -36,4 +40,9 @@ public void onAddItems(EntityPlayer player, CallbackInfo ci) {
public void onItemsAdded(EntityPlayer player, CallbackInfo ci) {
CreativeItems.Internal.markLoadFinished(this.itemList);
}

@Override
public Container getParentContainer() {
return this.player.playerContainer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.src.client.EnumOptions;
import net.minecraft.src.client.GameSettings;
import net.minecraft.src.client.KeyBinding;
import org.lwjgl.input.Keyboard;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -27,4 +28,12 @@ public void onLoadOptionInit(GameSettings instance) {
public void onOptionInit(CallbackInfo ci) {
this.keyBindings = KeyBindingAPI.Internal.inject(this.keyBindings);
}

@Redirect(method = "*", at = @At(value = "INVOKE", target =
"Lorg/lwjgl/input/Keyboard;getKeyName(I)Ljava/lang/String;"))
public String getKeyName(int i) {
if (i > Keyboard.KEYBOARD_SIZE || i < 0)
return "#" + i;
return Keyboard.getKeyName(i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.client.gui.GuiModList;
import com.fox2code.foxloader.client.gui.GuiUpdateButton;
import net.minecraft.src.client.gui.GuiButton;
import net.minecraft.src.client.gui.GuiIngameMenu;
import net.minecraft.src.client.gui.GuiScreen;
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;

@Mixin(GuiIngameMenu.class)
public class MixinGuiIngameMenu extends GuiScreen {
@Inject(method = "initGui", at = @At(value = "RETURN"))
public void onInitGui(CallbackInfo ci) {
this.controlList.add(new GuiUpdateButton(500, this.width - 62, 2, 60, 20, "Mods"));
}

@Inject(method = "actionPerformed", at = @At(value = "HEAD"), cancellable = true)
public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
if (var1.id == 500) {
this.mc.displayGuiScreen(new GuiModList(this));
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ItemStack.class)
public abstract class MixinItemStack implements RegisteredItemStack, NetworkItemStack {
Expand All @@ -22,6 +25,16 @@ public abstract class MixinItemStack implements RegisteredItemStack, NetworkItem
@Shadow public abstract void setItemName(String par1Str);
@Shadow public abstract boolean hasDisplayName();

@Inject(method = "splitStack", at = @At("RETURN"))
public void onSplitStack(int stacksize, CallbackInfoReturnable<ItemStack> cir) {
((NetworkItemStack) (Object) cir.getReturnValue()).setRemoteNetworkId(this.networkId);
}

@Inject(method = "copy", at = @At("RETURN"))
public void onCopy(CallbackInfoReturnable<ItemStack> cir) {
((NetworkItemStack) (Object) cir.getReturnValue()).setRemoteNetworkId(this.networkId);
}

@Override
public RegisteredItem getRegisteredItem() {
return (RegisteredItem) this.getItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import net.minecraft.src.client.packets.*;
import net.minecraft.src.game.level.WorldClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(NetClientHandler.class)
public class MixinNetClientHandler implements NetClientHandlerExtensions {
boolean isFoxLoader = false;
@Unique boolean isFoxLoader = false;

@Inject(method = "handlePickupSpawn", at = @At("HEAD"))
public void onHandlePickupSpawn(Packet21PickupSpawn packet21, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public int generateNewItemId(String name, int fallbackId) {

@Override
public RegisteredBlock registerNewBlock(String name, BlockBuilder blockBuilder, int fallbackId) {
validateRegistryName(name);
name = validateAndFixRegistryName(name);
if (blockBuilder == null) blockBuilder = DEFAULT_BLOCK_BUILDER;
String secondaryExt = blockBuilder.builtInBlockType.secRegistryExt;
Block mainBlock = this.registerNewBlock0(name, blockBuilder, fallbackId, true);
Expand Down Expand Up @@ -245,7 +245,7 @@ public Block registerNewBlock0(String name, BlockBuilder blockBuilder, int fallb

@Override
public RegisteredItem registerNewItem(String name, ItemBuilder itemBuilder, int fallbackId) {
validateRegistryName(name);
name = validateAndFixRegistryName(name);
return this.registerNewItem0(name, itemBuilder, null, null, this.generateNewItemId(name, fallbackId), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.stream.Stream;

public class FoxLoaderClientSparkPlugin extends FoxLoaderSparkPlugin {
public class FoxLoaderClientSparkPlugin extends FoxLoaderSparkPlugin implements ClientMod {
public FoxLoaderClientSparkPlugin() {
super(PlatformInfo.Type.CLIENT);
}
Expand Down
1 change: 1 addition & 0 deletions client/src/main/resources/foxloader.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"MixinEntityRenderer",
"MixinGameSettings",
"MixinGuiDebug",
"MixinGuiIngameMenu",
"MixinGuiMainMenu",
"MixinGuiTextField",
"MixinItem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.logging.Logger;

public final class ModContainer {
private static final ThreadLocal<ModContainer> activeModContainer = new ThreadLocal<>();
// tmp is used to make getModContainer work in constructor.
static ModContainer tmp;
public final File file;
Expand Down Expand Up @@ -67,6 +68,27 @@ public final class ModContainer {
}
}

private ModContainer markActive() {
ModContainer modContainer = activeModContainer.get();
activeModContainer.set(this);
return modContainer;
}

public static ModContainer getActiveModContainer() {
return activeModContainer.get();
}

static void setActiveModContainer(ModContainer modContainer) {
if (modContainer == null) activeModContainer.remove();
else activeModContainer.set(modContainer);
}

public void runInContext(Runnable runnable) {
ModContainer modContainer = markActive();
runnable.run();
setActiveModContainer(modContainer);
}

public Mod getClientMod() {
return clientMod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,31 @@ static void initializeModdedInstance(boolean client) {
static void initializeMods(boolean client) {
gameThread = Thread.currentThread();
for (ModContainer modContainer : modContainers.values()) {
ModContainer.setActiveModContainer(modContainer);
try {
modContainer.applyMod(client);
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Caused by the mod: " + modContainer.id, e);
}
}
for (ModContainer modContainer : modContainers.values()) {
ModContainer.setActiveModContainer(modContainer);
modContainer.notifyOnPreInit();
}
for (ModContainer modContainer : modContainers.values()) {
ModContainer.setActiveModContainer(modContainer);
modContainer.notifyOnInit();
}
ModContainer.setActiveModContainer(null);
allModsLoaded = true;
}

static void postInitializeMods() {
for (ModContainer modContainer : modContainers.values()) {
ModContainer.setActiveModContainer(modContainer);
modContainer.notifyOnPostInit();
}
ModContainer.setActiveModContainer(null);
}

@Override
Expand Down Expand Up @@ -271,7 +277,7 @@ private static void loadModContainerFromLua(File file) {
Files.newInputStream(file.toPath()), StandardCharsets.UTF_8))) {
String line;
while ((line = bufferedReader.readLine()) != null
&& line.startsWith("-- ")) {
&& (line.equals("--") || line.startsWith("-- "))) {
if (line.startsWith(MOD_ID_LUA_PREFIX)) {
id = line.substring(MOD_ID_LUA_PREFIX.length());
} else if (line.startsWith(MOD_NAME_LUA_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class PreLoader {
private static final String metaInfPath = "META-INF/MANIFEST.MF";
private static final byte[] metaInf = ("Manifest-Version: 1.0\n" +
"FoxLoader-Transformer-Version: " + BuildConfig.FOXLOADER_TRANSFORMER_VERSION +
"FoxLoader-ReIndev-Version: " + BuildConfig.REINDEV_VERSION +
"Multi-Release: true\n").getBytes(StandardCharsets.UTF_8);
private static JvmCompatTransformer jvmCompatTransformer = null;
private static final boolean devFoxLoader = FoxLauncher.foxLoaderFile.getAbsolutePath().replace('\\', '/')
Expand All @@ -47,6 +48,7 @@ public class PreLoader {

static {
if (devFoxLoader) {
// Workaround FoxLoader not updating properly in dev mode
preLoadMetaJarHash.addLong(FoxLauncher.foxLoaderFile.length());
}
preComputedFilesForHash.add(FoxLauncher.foxLoaderFile);
Expand Down Expand Up @@ -190,6 +192,7 @@ static void loadPrePatches(boolean client) {
registerPrePatch(new MinecraftClientDebugTransformer());
registerPrePatch(new FrustrumHelperTransformer());
registerPrePatch(new NetworkMappingTransformer());
registerPrePatch(new ClientOnlyInventoryTransformer());
}
}

Expand Down Expand Up @@ -286,7 +289,20 @@ public static ClassDataProvider getClassDataProvider() {
static void registerPrePatch(PreClassTransformer classTransformer) {
if (prePatchInitialized)
throw new IllegalStateException("Minecraft already pre patched");
File file = SourceUtil.getSourceFile(classTransformer.getClass());
Class<?> prePatch = classTransformer.getClass();
FoxClassLoader foxClassLoader = FoxLauncher.getFoxClassLoader();
if (foxClassLoader != null) { // <- Can be null when making dev jar
PrePatcher prePatcher = prePatch.getAnnotation(PrePatcher.class);
if (prePatcher != null) {
for (String exclusion : prePatcher.transformerExclusions()) {
if (exclusion.indexOf('.') != -1 && // Add exclusion!
!foxClassLoader.isTransformExclude(exclusion)) {
foxClassLoader.addTransformerExclusion(exclusion);
}
}
}
}
File file = SourceUtil.getSourceFile(prePatch);
if (!preComputedFilesForHash.add(file)) {
preLoadMetaJarHash.addLong(file.length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

public class MixinTestModePlugin implements IMixinConfigPlugin {
private static final HashSet<String> testModeMixins = new HashSet<>(
Arrays.asList("MixinEntityPlayerMP", "MixinMinecraftServer"));
Arrays.asList("MixinEntity", "MixinEntityPlayerMP",
"MixinMinecraftServer", "MixinStringTranslate"));

@Override
public void onLoad(String mixinPackage) {
Expand Down
Loading

0 comments on commit d0fddea

Please sign in to comment.