Compare commits
No commits in common. "a42bb0507e870ff5b76f18bba1d9cf9f440d464a" and "04b4ddd3d864af64a513a4e7a32f88f99717f566" have entirely different histories.
a42bb0507e
...
04b4ddd3d8
28 changed files with 544 additions and 749 deletions
19
build.gradle
19
build.gradle
|
@ -48,8 +48,7 @@ dependencies {
|
||||||
|
|
||||||
modImplementation libs.quilted.fabric.api
|
modImplementation libs.quilted.fabric.api
|
||||||
|
|
||||||
// not JiJ because it causes its mixins to fail to load
|
modApi include("dev.emi:trinkets:${libs.versions.trinkets.get()}")
|
||||||
modApi "dev.emi:trinkets:${libs.versions.trinkets.get()}"
|
|
||||||
modApi include("com.unascribed:lib39-core:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
|
modApi include("com.unascribed:lib39-core:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
|
||||||
modApi include("com.unascribed:lib39-dessicant:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
|
modApi include("com.unascribed:lib39-dessicant:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
|
||||||
|
|
||||||
|
@ -58,22 +57,10 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property 'version', version
|
inputs.properties 'version': version, 'group': project.group
|
||||||
inputs.property 'group', project.group
|
|
||||||
inputs.property 'minecraft_version', libs.versions.minecraft.get()
|
|
||||||
inputs.property 'trinkets_version', libs.versions.trinkets.get()
|
|
||||||
inputs.property 'lib39_version', libs.versions.lib39.get()
|
|
||||||
inputs.property 'emi_version', libs.versions.emi.get()
|
|
||||||
|
|
||||||
filesMatching('quilt.mod.json') {
|
filesMatching('quilt.mod.json') {
|
||||||
expand (
|
expand 'version': version, 'group': project.group
|
||||||
"version": version,
|
|
||||||
"group": project.group,
|
|
||||||
"minecraft_version": libs.versions.minecraft.get(),
|
|
||||||
"trinkets_version": libs.versions.trinkets.get(),
|
|
||||||
"lib39_version": libs.versions.lib39.get(),
|
|
||||||
"emi_version": libs.versions.emi.get()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import org.quiltmc.loader.api.ModContainer;
|
import org.quiltmc.loader.api.ModContainer;
|
||||||
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
|
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
|
||||||
|
import pm.c7.scout.config.ScoutConfigHandler;
|
||||||
import pm.c7.scout.registry.ScoutItems;
|
import pm.c7.scout.registry.ScoutItems;
|
||||||
|
|
||||||
public class Scout implements ModInitializer {
|
public class Scout implements ModInitializer {
|
||||||
|
@ -31,6 +32,7 @@ public class Scout implements ModInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize(ModContainer mod) {
|
public void onInitialize(ModContainer mod) {
|
||||||
|
new ScoutConfigHandler();
|
||||||
ScoutItems.init();
|
ScoutItems.init();
|
||||||
Registry.register(Registries.ITEM_GROUP, new Identifier(ScoutUtil.MOD_ID, "itemgroup"), ITEM_GROUP);
|
Registry.register(Registries.ITEM_GROUP, new Identifier(ScoutUtil.MOD_ID, "itemgroup"), ITEM_GROUP);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package pm.c7.scout;
|
|
||||||
|
|
||||||
import org.quiltmc.config.api.ReflectiveConfig;
|
|
||||||
import org.quiltmc.config.api.annotations.Comment;
|
|
||||||
import org.quiltmc.config.api.values.TrackedValue;
|
|
||||||
import org.quiltmc.loader.api.config.v2.QuiltConfig;
|
|
||||||
|
|
||||||
public class ScoutConfig extends ReflectiveConfig {
|
|
||||||
public static final ScoutConfig CONFIG = QuiltConfig.create("", ScoutUtil.MOD_ID, ScoutConfig.class);
|
|
||||||
|
|
||||||
@Comment("Allow shulker boxes to be placed in bags. Bags are already blacklisted from shulker boxes with no toggle.")
|
|
||||||
public final TrackedValue<Boolean> allowShulkers = this.value(true);
|
|
||||||
|
|
||||||
@Comment("Allow bags to act as a quiver and pull arrows.")
|
|
||||||
public final TrackedValue<Boolean> useArrows = this.value(true);
|
|
||||||
}
|
|
|
@ -3,5 +3,5 @@ package pm.c7.scout;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ScoutNetworking {
|
public class ScoutNetworking {
|
||||||
public static final Identifier ENABLE_SLOTS = new Identifier(ScoutUtil.MOD_ID, "enable_slots");
|
public static final Identifier ENABLE_SLOTS = new Identifier(ScoutUtil.MOD_ID, "enable_slots");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.util.collection.DefaultedList;
|
||||||
import pm.c7.scout.screen.BagSlot;
|
import pm.c7.scout.screen.BagSlot;
|
||||||
|
|
||||||
public interface ScoutScreenHandler {
|
public interface ScoutScreenHandler {
|
||||||
DefaultedList<BagSlot> scout$getSatchelSlots();
|
DefaultedList<BagSlot> scout$getSatchelSlots();
|
||||||
DefaultedList<BagSlot> scout$getLeftPouchSlots();
|
DefaultedList<BagSlot> scout$getLeftPouchSlots();
|
||||||
DefaultedList<BagSlot> scout$getRightPouchSlots();
|
DefaultedList<BagSlot> scout$getRightPouchSlots();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtList;
|
import net.minecraft.nbt.NbtList;
|
||||||
import net.minecraft.screen.PlayerScreenHandler;
|
import net.minecraft.screen.PlayerScreenHandler;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import net.minecraft.screen.slot.SlotActionType;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Pair;
|
import net.minecraft.util.Pair;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
@ -45,59 +44,59 @@ public class ScoutUtil {
|
||||||
public static final int BAG_SLOTS_END = RIGHT_POUCH_SLOT_START - MAX_POUCH_SLOTS;
|
public static final int BAG_SLOTS_END = RIGHT_POUCH_SLOT_START - MAX_POUCH_SLOTS;
|
||||||
|
|
||||||
public static ItemStack findBagItem(PlayerEntity player, BaseBagItem.BagType type, boolean right) {
|
public static ItemStack findBagItem(PlayerEntity player, BaseBagItem.BagType type, boolean right) {
|
||||||
ItemStack targetStack = ItemStack.EMPTY;
|
ItemStack targetStack = ItemStack.EMPTY;
|
||||||
|
|
||||||
boolean hasFirstPouch = false;
|
boolean hasFirstPouch = false;
|
||||||
Optional<TrinketComponent> _component = TrinketsApi.getTrinketComponent(player);
|
Optional<TrinketComponent> _component = TrinketsApi.getTrinketComponent(player);
|
||||||
if (_component.isPresent()) {
|
if (_component.isPresent()) {
|
||||||
TrinketComponent component = _component.get();
|
TrinketComponent component = _component.get();
|
||||||
for (Pair<SlotReference, ItemStack> pair : component.getAllEquipped()) {
|
for (Pair<SlotReference, ItemStack> pair : component.getAllEquipped()) {
|
||||||
ItemStack slotStack = pair.getRight();
|
ItemStack slotStack = pair.getRight();
|
||||||
|
|
||||||
if (slotStack.getItem() instanceof BaseBagItem bagItem) {
|
if (slotStack.getItem() instanceof BaseBagItem bagItem) {
|
||||||
if (bagItem.getType() == type) {
|
if (bagItem.getType() == type) {
|
||||||
if (type == BagType.POUCH) {
|
if (type == BagType.POUCH) {
|
||||||
if (right && !hasFirstPouch) {
|
if (right && !hasFirstPouch) {
|
||||||
hasFirstPouch = true;
|
hasFirstPouch = true;
|
||||||
} else {
|
} else {
|
||||||
targetStack = slotStack;
|
targetStack = slotStack;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
targetStack = slotStack;
|
targetStack = slotStack;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetStack;
|
return targetStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NbtList inventoryToTag(Inventory inventory) {
|
public static NbtList inventoryToTag(Inventory inventory) {
|
||||||
NbtList tag = new NbtList();
|
NbtList tag = new NbtList();
|
||||||
|
|
||||||
for(int i = 0; i < inventory.size(); i++) {
|
for(int i = 0; i < inventory.size(); i++) {
|
||||||
NbtCompound stackTag = new NbtCompound();
|
NbtCompound stackTag = new NbtCompound();
|
||||||
stackTag.putInt("Slot", i);
|
stackTag.putInt("Slot", i);
|
||||||
stackTag.put("Stack", inventory.getStack(i).writeNbt(new NbtCompound()));
|
stackTag.put("Stack", inventory.getStack(i).writeNbt(new NbtCompound()));
|
||||||
tag.add(stackTag);
|
tag.add(stackTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void inventoryFromTag(NbtList tag, Inventory inventory) {
|
public static void inventoryFromTag(NbtList tag, Inventory inventory) {
|
||||||
inventory.clear();
|
inventory.clear();
|
||||||
|
|
||||||
tag.forEach(element -> {
|
tag.forEach(element -> {
|
||||||
NbtCompound stackTag = (NbtCompound) element;
|
NbtCompound stackTag = (NbtCompound) element;
|
||||||
int slot = stackTag.getInt("Slot");
|
int slot = stackTag.getInt("Slot");
|
||||||
ItemStack stack = ItemStack.fromNbt(stackTag.getCompound("Stack"));
|
ItemStack stack = ItemStack.fromNbt(stackTag.getCompound("Stack"));
|
||||||
inventory.setStack(slot, stack);
|
inventory.setStack(slot, stack);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBagSlot(int slot) {
|
public static boolean isBagSlot(int slot) {
|
||||||
return slot <= SATCHEL_SLOT_START && slot > BAG_SLOTS_END;
|
return slot <= SATCHEL_SLOT_START && slot > BAG_SLOTS_END;
|
||||||
|
|
|
@ -27,79 +27,79 @@ import pm.c7.scout.mixin.client.HandledScreenAccessor;
|
||||||
import pm.c7.scout.screen.BagSlot;
|
import pm.c7.scout.screen.BagSlot;
|
||||||
|
|
||||||
public class ScoutClient implements ClientModInitializer {
|
public class ScoutClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient(ModContainer mod) {
|
public void onInitializeClient(ModContainer mod) {
|
||||||
ClientPlayNetworking.registerGlobalReceiver(ScoutNetworking.ENABLE_SLOTS, (client, handler, packet, sender) -> {
|
ClientPlayNetworking.registerGlobalReceiver(ScoutNetworking.ENABLE_SLOTS, (client, handler, packet, sender) -> {
|
||||||
client.execute(() -> {
|
client.execute(() -> {
|
||||||
assert client.player != null;
|
assert client.player != null;
|
||||||
ScoutScreenHandler screenHandler = (ScoutScreenHandler) client.player.playerScreenHandler;
|
ScoutScreenHandler screenHandler = (ScoutScreenHandler) client.player.playerScreenHandler;
|
||||||
|
|
||||||
ItemStack satchelStack = ScoutUtil.findBagItem(client.player, BagType.SATCHEL, false);
|
ItemStack satchelStack = ScoutUtil.findBagItem(client.player, BagType.SATCHEL, false);
|
||||||
DefaultedList<BagSlot> satchelSlots = screenHandler.scout$getSatchelSlots();
|
DefaultedList<BagSlot> satchelSlots = screenHandler.scout$getSatchelSlots();
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
|
||||||
BagSlot slot = satchelSlots.get(i);
|
BagSlot slot = satchelSlots.get(i);
|
||||||
slot.setInventory(null);
|
slot.setInventory(null);
|
||||||
slot.setEnabled(false);
|
slot.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (!satchelStack.isEmpty()) {
|
if (!satchelStack.isEmpty()) {
|
||||||
BaseBagItem satchelItem = (BaseBagItem) satchelStack.getItem();
|
BaseBagItem satchelItem = (BaseBagItem) satchelStack.getItem();
|
||||||
Inventory satchelInv = satchelItem.getInventory(satchelStack);
|
Inventory satchelInv = satchelItem.getInventory(satchelStack);
|
||||||
|
|
||||||
for (int i = 0; i < satchelItem.getSlotCount(); i++) {
|
for (int i = 0; i < satchelItem.getSlotCount(); i++) {
|
||||||
BagSlot slot = satchelSlots.get(i);
|
BagSlot slot = satchelSlots.get(i);
|
||||||
slot.setInventory(satchelInv);
|
slot.setInventory(satchelInv);
|
||||||
slot.setEnabled(true);
|
slot.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
|
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
|
||||||
DefaultedList<BagSlot> leftPouchSlots = screenHandler.scout$getLeftPouchSlots();
|
DefaultedList<BagSlot> leftPouchSlots = screenHandler.scout$getLeftPouchSlots();
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
||||||
BagSlot slot = leftPouchSlots.get(i);
|
BagSlot slot = leftPouchSlots.get(i);
|
||||||
slot.setInventory(null);
|
slot.setInventory(null);
|
||||||
slot.setEnabled(false);
|
slot.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (!leftPouchStack.isEmpty()) {
|
if (!leftPouchStack.isEmpty()) {
|
||||||
BaseBagItem leftPouchItem = (BaseBagItem) leftPouchStack.getItem();
|
BaseBagItem leftPouchItem = (BaseBagItem) leftPouchStack.getItem();
|
||||||
Inventory leftPouchInv = leftPouchItem.getInventory(leftPouchStack);
|
Inventory leftPouchInv = leftPouchItem.getInventory(leftPouchStack);
|
||||||
|
|
||||||
for (int i = 0; i < leftPouchItem.getSlotCount(); i++) {
|
for (int i = 0; i < leftPouchItem.getSlotCount(); i++) {
|
||||||
BagSlot slot = leftPouchSlots.get(i);
|
BagSlot slot = leftPouchSlots.get(i);
|
||||||
slot.setInventory(leftPouchInv);
|
slot.setInventory(leftPouchInv);
|
||||||
slot.setEnabled(true);
|
slot.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
|
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
|
||||||
DefaultedList<BagSlot> rightPouchSlots = screenHandler.scout$getRightPouchSlots();
|
DefaultedList<BagSlot> rightPouchSlots = screenHandler.scout$getRightPouchSlots();
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
||||||
BagSlot slot = rightPouchSlots.get(i);
|
BagSlot slot = rightPouchSlots.get(i);
|
||||||
slot.setInventory(null);
|
slot.setInventory(null);
|
||||||
slot.setEnabled(false);
|
slot.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (!rightPouchStack.isEmpty()) {
|
if (!rightPouchStack.isEmpty()) {
|
||||||
BaseBagItem rightPouchItem = (BaseBagItem) rightPouchStack.getItem();
|
BaseBagItem rightPouchItem = (BaseBagItem) rightPouchStack.getItem();
|
||||||
Inventory rightPouchInv = rightPouchItem.getInventory(rightPouchStack);
|
Inventory rightPouchInv = rightPouchItem.getInventory(rightPouchStack);
|
||||||
|
|
||||||
for (int i = 0; i < rightPouchItem.getSlotCount(); i++) {
|
for (int i = 0; i < rightPouchItem.getSlotCount(); i++) {
|
||||||
BagSlot slot = rightPouchSlots.get(i);
|
BagSlot slot = rightPouchSlots.get(i);
|
||||||
slot.setInventory(rightPouchInv);
|
slot.setInventory(rightPouchInv);
|
||||||
slot.setEnabled(true);
|
slot.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
TooltipComponentCallback.EVENT.register(data -> {
|
TooltipComponentCallback.EVENT.register(data -> {
|
||||||
if (data instanceof BagTooltipData d) {
|
if (data instanceof BagTooltipData d) {
|
||||||
return new BagTooltipComponent(d);
|
return new BagTooltipComponent(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
|
LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
|
||||||
if (entityType == EntityType.PLAYER) {
|
if (entityType == EntityType.PLAYER) {
|
||||||
|
@ -200,5 +200,5 @@ public class ScoutClient implements ClientModInitializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,34 +12,34 @@ import pm.c7.scout.item.BaseBagItem.BagType;
|
||||||
import pm.c7.scout.mixin.client.HandledScreenAccessor;
|
import pm.c7.scout.mixin.client.HandledScreenAccessor;
|
||||||
|
|
||||||
public class ScoutEmiPlugin implements EmiPlugin {
|
public class ScoutEmiPlugin implements EmiPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void register(EmiRegistry registry) {
|
public void register(EmiRegistry registry) {
|
||||||
registry.addExclusionArea(InventoryScreen.class, (screen, consumer) -> {
|
registry.addExclusionArea(InventoryScreen.class, (screen, consumer) -> {
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
|
ItemStack leftPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, false);
|
||||||
if (!leftPouchStack.isEmpty()) {
|
if (!leftPouchStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
int columns = (int) Math.ceil(slots / 3);
|
int columns = (int) Math.ceil(slots / 3);
|
||||||
|
|
||||||
int x = ((HandledScreenAccessor) screen).getX() - (columns * 18);
|
int x = ((HandledScreenAccessor) screen).getX() - (columns * 18);
|
||||||
int y = ((HandledScreenAccessor) screen).getY() + 76;
|
int y = ((HandledScreenAccessor) screen).getY() + 76;
|
||||||
|
|
||||||
consumer.accept(new Bounds(x, y, columns * 18, 68));
|
consumer.accept(new Bounds(x, y, columns * 18, 68));
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
|
ItemStack rightPouchStack = ScoutUtil.findBagItem(client.player, BagType.POUCH, true);
|
||||||
if (!rightPouchStack.isEmpty()) {
|
if (!rightPouchStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
int columns = (int) Math.ceil(slots / 3);
|
int columns = (int) Math.ceil(slots / 3);
|
||||||
|
|
||||||
int x = ((HandledScreenAccessor) screen).getX() + 176;
|
int x = ((HandledScreenAccessor) screen).getX() + 176;
|
||||||
int y = ((HandledScreenAccessor) screen).getY() + 76;
|
int y = ((HandledScreenAccessor) screen).getY() + 76;
|
||||||
|
|
||||||
consumer.accept(new Bounds(x, y, columns * 18, 68));
|
consumer.accept(new Bounds(x, y, columns * 18, 68));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
12
src/main/java/pm/c7/scout/config/ScoutConfig.java
Normal file
12
src/main/java/pm/c7/scout/config/ScoutConfig.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package pm.c7.scout.config;
|
||||||
|
|
||||||
|
import org.quiltmc.config.api.WrappedConfig;
|
||||||
|
import org.quiltmc.config.api.annotations.Comment;
|
||||||
|
|
||||||
|
public class ScoutConfig extends WrappedConfig {
|
||||||
|
@Comment("Allow shulker boxes to be placed in bags. Bags are already blacklisted from shulker boxes with no toggle.")
|
||||||
|
public final boolean allowShulkers = true;
|
||||||
|
|
||||||
|
@Comment("Allow bags to act as a quiver and pull arrows.")
|
||||||
|
public final boolean useArrows = true;
|
||||||
|
}
|
17
src/main/java/pm/c7/scout/config/ScoutConfigHandler.java
Normal file
17
src/main/java/pm/c7/scout/config/ScoutConfigHandler.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package pm.c7.scout.config;
|
||||||
|
|
||||||
|
import org.quiltmc.config.api.values.TrackedValue;
|
||||||
|
import org.quiltmc.loader.api.config.QuiltConfig;
|
||||||
|
import pm.c7.scout.ScoutUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ScoutConfigHandler {
|
||||||
|
public static final ScoutConfig CONFIG = QuiltConfig.create("", ScoutUtil.MOD_ID, ScoutConfig.class);
|
||||||
|
|
||||||
|
public ScoutConfigHandler() {}
|
||||||
|
|
||||||
|
public static TrackedValue<?> getConfigValue(String key) {
|
||||||
|
return CONFIG.getValue(List.of(key));
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,19 +5,19 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
public class BagTooltipData implements TooltipData {
|
public class BagTooltipData implements TooltipData {
|
||||||
private final DefaultedList<ItemStack> inventory;
|
private final DefaultedList<ItemStack> inventory;
|
||||||
private final int slotCount;
|
private final int slotCount;
|
||||||
|
|
||||||
public BagTooltipData(DefaultedList<ItemStack> inventory, int slots) {
|
public BagTooltipData(DefaultedList<ItemStack> inventory, int slots) {
|
||||||
this.inventory = inventory;
|
this.inventory = inventory;
|
||||||
this.slotCount = slots;
|
this.slotCount = slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultedList<ItemStack> getInventory() {
|
public DefaultedList<ItemStack> getInventory() {
|
||||||
return this.inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlotCount() {
|
public int getSlotCount() {
|
||||||
return this.slotCount;
|
return this.slotCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,85 +31,85 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BaseBagItem extends TrinketItem {
|
public class BaseBagItem extends TrinketItem {
|
||||||
private static final String ITEMS_KEY = "Items";
|
private static final String ITEMS_KEY = "Items";
|
||||||
|
|
||||||
private final int slots;
|
private final int slots;
|
||||||
private final BagType type;
|
private final BagType type;
|
||||||
|
|
||||||
public BaseBagItem(Settings settings, int slots, BagType type) {
|
public BaseBagItem(Settings settings, int slots, BagType type) {
|
||||||
super(settings);
|
super(settings);
|
||||||
|
|
||||||
if (type == BagType.SATCHEL && slots > ScoutUtil.MAX_SATCHEL_SLOTS) {
|
if (type == BagType.SATCHEL && slots > ScoutUtil.MAX_SATCHEL_SLOTS) {
|
||||||
throw new IllegalArgumentException("Satchel has too many slots.");
|
throw new IllegalArgumentException("Satchel has too many slots.");
|
||||||
}
|
}
|
||||||
if (type == BagType.POUCH && slots > ScoutUtil.MAX_POUCH_SLOTS) {
|
if (type == BagType.POUCH && slots > ScoutUtil.MAX_POUCH_SLOTS) {
|
||||||
throw new IllegalArgumentException("Pouch has too many slots.");
|
throw new IllegalArgumentException("Pouch has too many slots.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.slots = slots;
|
this.slots = slots;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlotCount() {
|
public int getSlotCount() {
|
||||||
return this.slots;
|
return this.slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BagType getType() {
|
public BagType getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
|
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
|
||||||
super.appendTooltip(stack, world, tooltip, context);
|
super.appendTooltip(stack, world, tooltip, context);
|
||||||
tooltip.add(Text.translatable("tooltip.scout.slots", Text.literal(String.valueOf(this.slots)).formatted(Formatting.BLUE)).formatted(Formatting.GRAY));
|
tooltip.add(Text.translatable("tooltip.scout.slots", Text.literal(String.valueOf(this.slots)).formatted(Formatting.BLUE)).formatted(Formatting.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory getInventory(ItemStack stack) {
|
public Inventory getInventory(ItemStack stack) {
|
||||||
SimpleInventory inventory = new SimpleInventory(this.slots) {
|
SimpleInventory inventory = new SimpleInventory(this.slots) {
|
||||||
@Override
|
@Override
|
||||||
public void markDirty() {
|
public void markDirty() {
|
||||||
stack.getOrCreateNbt().put(ITEMS_KEY, ScoutUtil.inventoryToTag(this));
|
stack.getOrCreateNbt().put(ITEMS_KEY, ScoutUtil.inventoryToTag(this));
|
||||||
super.markDirty();
|
super.markDirty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NbtCompound compound = stack.getOrCreateNbt();
|
NbtCompound compound = stack.getOrCreateNbt();
|
||||||
if (!compound.contains(ITEMS_KEY)) {
|
if (!compound.contains(ITEMS_KEY)) {
|
||||||
compound.put(ITEMS_KEY, new NbtList());
|
compound.put(ITEMS_KEY, new NbtList());
|
||||||
}
|
}
|
||||||
|
|
||||||
NbtList items = compound.getList(ITEMS_KEY, 10);
|
NbtList items = compound.getList(ITEMS_KEY, 10);
|
||||||
|
|
||||||
ScoutUtil.inventoryFromTag(items, inventory);
|
ScoutUtil.inventoryFromTag(items, inventory);
|
||||||
|
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<TooltipData> getTooltipData(ItemStack stack) {
|
public Optional<TooltipData> getTooltipData(ItemStack stack) {
|
||||||
DefaultedList<ItemStack> stacks = DefaultedList.of();
|
DefaultedList<ItemStack> stacks = DefaultedList.of();
|
||||||
Inventory inventory = getInventory(stack);
|
Inventory inventory = getInventory(stack);
|
||||||
|
|
||||||
for (int i = 0; i < slots; i++) {
|
for (int i = 0; i < slots; i++) {
|
||||||
stacks.add(inventory.getStack(i));
|
stacks.add(inventory.getStack(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stacks.stream().allMatch(ItemStack::isEmpty)) return Optional.empty();
|
if (stacks.stream().allMatch(ItemStack::isEmpty)) return Optional.empty();
|
||||||
|
|
||||||
return Optional.of(new BagTooltipData(stacks, slots));
|
return Optional.of(new BagTooltipData(stacks, slots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEquip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
|
public void onEquip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
|
||||||
|
if (entity instanceof PlayerEntity player)
|
||||||
|
updateSlots(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnequip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
|
||||||
if (entity instanceof PlayerEntity player)
|
if (entity instanceof PlayerEntity player)
|
||||||
updateSlots(player);
|
updateSlots(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnequip(ItemStack stack, SlotReference slotRef, LivingEntity entity) {
|
|
||||||
if (entity instanceof PlayerEntity player)
|
|
||||||
updateSlots(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSlots(PlayerEntity player) {
|
private void updateSlots(PlayerEntity player) {
|
||||||
ScoutScreenHandler handler = (ScoutScreenHandler) player.playerScreenHandler;
|
ScoutScreenHandler handler = (ScoutScreenHandler) player.playerScreenHandler;
|
||||||
|
@ -177,37 +177,37 @@ public class BaseBagItem extends TrinketItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
|
public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
|
|
||||||
ItemStack slotStack = slot.inventory().getStack(slot.index());
|
ItemStack slotStack = slot.inventory().getStack(slot.index());
|
||||||
Item slotItem = slotStack.getItem();
|
Item slotItem = slotStack.getItem();
|
||||||
|
|
||||||
if (slotItem instanceof BaseBagItem) {
|
if (slotItem instanceof BaseBagItem) {
|
||||||
if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
|
if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
|
||||||
if (((BaseBagItem) slotItem).getType() == BagType.SATCHEL) {
|
if (((BaseBagItem) slotItem).getType() == BagType.SATCHEL) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
|
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
|
||||||
}
|
}
|
||||||
} else if (((BaseBagItem) item).getType() == BagType.POUCH) {
|
} else if (((BaseBagItem) item).getType() == BagType.POUCH) {
|
||||||
if (((BaseBagItem) slotItem).getType() == BagType.POUCH) {
|
if (((BaseBagItem) slotItem).getType() == BagType.POUCH) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
|
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
|
if (((BaseBagItem) item).getType() == BagType.SATCHEL) {
|
||||||
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
|
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.SATCHEL, false).isEmpty();
|
||||||
} else if (((BaseBagItem) item).getType() == BagType.POUCH) {
|
} else if (((BaseBagItem) item).getType() == BagType.POUCH) {
|
||||||
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
|
return ScoutUtil.findBagItem((PlayerEntity) entity, BagType.POUCH, true).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||||
|
@ -219,8 +219,8 @@ public class BaseBagItem extends TrinketItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BagType {
|
public enum BagType {
|
||||||
SATCHEL,
|
SATCHEL,
|
||||||
POUCH
|
POUCH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,14 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
import pm.c7.scout.ScoutUtil;
|
import pm.c7.scout.ScoutUtil;
|
||||||
import pm.c7.scout.ScoutConfig;
|
import pm.c7.scout.config.ScoutConfigHandler;
|
||||||
import pm.c7.scout.item.BaseBagItem;
|
import pm.c7.scout.item.BaseBagItem;
|
||||||
|
|
||||||
@Mixin(BowItem.class)
|
@Mixin(BowItem.class)
|
||||||
public class BowItemMixin {
|
public class BowItemMixin {
|
||||||
@Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
|
@Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||||
public void scout$arrowsFromBags(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci, PlayerEntity playerEntity, boolean bl, ItemStack itemStack, int maxTime, float f) {
|
public void scout$arrowsFromBags(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci, PlayerEntity playerEntity, boolean bl, ItemStack itemStack, int maxTime, float f) {
|
||||||
if (ScoutConfig.CONFIG.useArrows.value()) {
|
if ((boolean) ScoutConfigHandler.getConfigValue("useArrows").value()) {
|
||||||
boolean infinity = bl && itemStack.isOf(Items.ARROW);
|
boolean infinity = bl && itemStack.isOf(Items.ARROW);
|
||||||
boolean hasRan = false;
|
boolean hasRan = false;
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,15 @@ import pm.c7.scout.item.BaseBagItem;
|
||||||
|
|
||||||
@Mixin(ItemStack.class)
|
@Mixin(ItemStack.class)
|
||||||
public class ItemStackMixin {
|
public class ItemStackMixin {
|
||||||
// Trinkets calls areEqual to check whether it should unequip old and equip new (https://github.com/emilyploszaj/trinkets/blob/7cb63ce0/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java#L155-L158)
|
|
||||||
// Excluding ourselves from this check to force unequip/equip when switching bag items fixes a duplication bug
|
// Trinkets calls areEqual to check whether it should unequip old and equip new (https://github.com/emilyploszaj/trinkets/blob/7cb63ce0/src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java#L155-L158)
|
||||||
// Gross and hacky but oh well, can't mixin mixins.
|
// Excluding ourselves from this check to force unequip/equip when switching bag items fixes a duplication bug
|
||||||
@Inject(method = "areEqual", at = @At("HEAD"), cancellable = true)
|
// Gross and hacky but oh well, can't mixin mixins.
|
||||||
private static void scout$grossTrinketsEquipFix(ItemStack stack, ItemStack otherStack, CallbackInfoReturnable<Boolean> callbackInfo) {
|
@Inject(method = "areEqual", at = @At("HEAD"), cancellable = true)
|
||||||
if (stack.getItem() instanceof BaseBagItem && otherStack.getItem() instanceof BaseBagItem) {
|
private void scout$grossTrinketsEquipFix(ItemStack newStack, CallbackInfoReturnable<Boolean> callbackInfo) {
|
||||||
callbackInfo.setReturnValue(false);
|
ItemStack self = (ItemStack) (Object) this;
|
||||||
}
|
if (self.getItem() instanceof BaseBagItem && newStack.getItem() instanceof BaseBagItem) {
|
||||||
}
|
callbackInfo.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
import pm.c7.scout.ScoutUtil;
|
import pm.c7.scout.ScoutUtil;
|
||||||
import pm.c7.scout.ScoutConfig;
|
import pm.c7.scout.config.ScoutConfigHandler;
|
||||||
import pm.c7.scout.item.BaseBagItem;
|
import pm.c7.scout.item.BaseBagItem;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.function.Predicate;
|
||||||
public class PlayerEntityMixin {
|
public class PlayerEntityMixin {
|
||||||
@Inject(method = "getArrowType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/RangedWeaponItem;getProjectiles()Ljava/util/function/Predicate;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
|
@Inject(method = "getArrowType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/RangedWeaponItem;getProjectiles()Ljava/util/function/Predicate;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
|
||||||
public void scout$arrowsFromBags(ItemStack stack, CallbackInfoReturnable<ItemStack> cir, Predicate<ItemStack> predicate, ItemStack itemStack) {
|
public void scout$arrowsFromBags(ItemStack stack, CallbackInfoReturnable<ItemStack> cir, Predicate<ItemStack> predicate, ItemStack itemStack) {
|
||||||
if (ScoutConfig.CONFIG.useArrows.value()) {
|
if ((boolean) ScoutConfigHandler.getConfigValue("useArrows").value()) {
|
||||||
var self = (PlayerEntity) (Object) this;
|
var self = (PlayerEntity) (Object) this;
|
||||||
var leftPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, false);
|
var leftPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, false);
|
||||||
var rightPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, true);
|
var rightPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, true);
|
||||||
|
|
|
@ -12,90 +12,88 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import pm.c7.scout.ScoutScreenHandler;
|
import pm.c7.scout.ScoutScreenHandler;
|
||||||
import pm.c7.scout.ScoutUtil;
|
import pm.c7.scout.ScoutUtil;
|
||||||
import pm.c7.scout.ScoutMixin.Transformer;
|
|
||||||
import pm.c7.scout.screen.BagSlot;
|
import pm.c7.scout.screen.BagSlot;
|
||||||
|
|
||||||
@Mixin(value = PlayerScreenHandler.class, priority = 950)
|
@Mixin(value = PlayerScreenHandler.class, priority = 950)
|
||||||
@Transformer(PlayerScreenHandlerTransformer.class)
|
|
||||||
public abstract class PlayerScreenHandlerMixin extends ScreenHandler implements ScoutScreenHandler {
|
public abstract class PlayerScreenHandlerMixin extends ScreenHandler implements ScoutScreenHandler {
|
||||||
protected PlayerScreenHandlerMixin() {
|
protected PlayerScreenHandlerMixin() {
|
||||||
super(null, 0);
|
super(null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
public final DefaultedList<BagSlot> scout$satchelSlots = DefaultedList.ofSize(ScoutUtil.MAX_SATCHEL_SLOTS);
|
public final DefaultedList<BagSlot> scout$satchelSlots = DefaultedList.ofSize(ScoutUtil.MAX_SATCHEL_SLOTS);
|
||||||
@Unique
|
@Unique
|
||||||
public final DefaultedList<BagSlot> scout$leftPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
|
public final DefaultedList<BagSlot> scout$leftPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
|
||||||
@Unique
|
@Unique
|
||||||
public final DefaultedList<BagSlot> scout$rightPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
|
public final DefaultedList<BagSlot> scout$rightPouchSlots = DefaultedList.ofSize(ScoutUtil.MAX_POUCH_SLOTS);
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
private void scout$addSlots(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo callbackInfo) {
|
private void scout$addSlots(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo callbackInfo) {
|
||||||
// satchel
|
// satchel
|
||||||
int x = 8;
|
int x = 8;
|
||||||
int y = 168;
|
int y = 168;
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_SATCHEL_SLOTS; i++) {
|
||||||
if (i % 9 == 0) {
|
if (i % 9 == 0) {
|
||||||
x = 8;
|
x = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
BagSlot slot = new BagSlot(i, x, y);
|
BagSlot slot = new BagSlot(i, x, y);
|
||||||
slot.id = ScoutUtil.SATCHEL_SLOT_START - i;
|
slot.id = ScoutUtil.SATCHEL_SLOT_START - i;
|
||||||
scout$satchelSlots.add(slot);
|
scout$satchelSlots.add(slot);
|
||||||
|
|
||||||
x += 18;
|
x += 18;
|
||||||
|
|
||||||
if ((i + 1) % 9 == 0) {
|
if ((i + 1) % 9 == 0) {
|
||||||
y += 18;
|
y += 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// left pouch
|
// left pouch
|
||||||
x = 8;
|
x = 8;
|
||||||
y = 66;
|
y = 66;
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
||||||
if (i % 3 == 0) {
|
if (i % 3 == 0) {
|
||||||
x -= 18;
|
x -= 18;
|
||||||
y += 54;
|
y += 54;
|
||||||
}
|
}
|
||||||
|
|
||||||
BagSlot slot = new BagSlot(i, x, y);
|
BagSlot slot = new BagSlot(i, x, y);
|
||||||
slot.id = ScoutUtil.LEFT_POUCH_SLOT_START - i;
|
slot.id = ScoutUtil.LEFT_POUCH_SLOT_START - i;
|
||||||
scout$leftPouchSlots.add(slot);
|
scout$leftPouchSlots.add(slot);
|
||||||
|
|
||||||
y -= 18;
|
y -= 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
// right pouch
|
// right pouch
|
||||||
x = 152;
|
x = 152;
|
||||||
y = 66;
|
y = 66;
|
||||||
|
|
||||||
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
for (int i = 0; i < ScoutUtil.MAX_POUCH_SLOTS; i++) {
|
||||||
if (i % 3 == 0) {
|
if (i % 3 == 0) {
|
||||||
x += 18;
|
x += 18;
|
||||||
y += 54;
|
y += 54;
|
||||||
}
|
}
|
||||||
|
|
||||||
BagSlot slot = new BagSlot(i, x, y);
|
BagSlot slot = new BagSlot(i, x, y);
|
||||||
slot.id = ScoutUtil.RIGHT_POUCH_SLOT_START - i;
|
slot.id = ScoutUtil.RIGHT_POUCH_SLOT_START - i;
|
||||||
scout$rightPouchSlots.add(slot);
|
scout$rightPouchSlots.add(slot);
|
||||||
|
|
||||||
y -= 18;
|
y -= 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final DefaultedList<BagSlot> scout$getSatchelSlots() {
|
public final DefaultedList<BagSlot> scout$getSatchelSlots() {
|
||||||
return scout$satchelSlots;
|
return scout$satchelSlots;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public final DefaultedList<BagSlot> scout$getLeftPouchSlots() {
|
public final DefaultedList<BagSlot> scout$getLeftPouchSlots() {
|
||||||
return scout$leftPouchSlots;
|
return scout$leftPouchSlots;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public final DefaultedList<BagSlot> scout$getRightPouchSlots() {
|
public final DefaultedList<BagSlot> scout$getRightPouchSlots() {
|
||||||
return scout$rightPouchSlots;
|
return scout$rightPouchSlots;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
package pm.c7.scout.mixin;
|
|
||||||
|
|
||||||
import org.objectweb.asm.tree.*;
|
|
||||||
import org.quiltmc.loader.api.QuiltLoader;
|
|
||||||
|
|
||||||
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
|
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
|
||||||
|
|
||||||
public class PlayerScreenHandlerTransformer implements ClassNodeTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(String name, ClassNode node) {
|
|
||||||
var resolver = QuiltLoader.getMappingResolver();
|
|
||||||
var namespace = "intermediary";
|
|
||||||
|
|
||||||
var LPlayerScreenHandler = L(slash(name));
|
|
||||||
|
|
||||||
var quickMove = resolver.mapMethodName(namespace, name, "method_7601", "(Lnet/minecraft/class_1657;I)Lnet/minecraft/class_1799;");
|
|
||||||
|
|
||||||
var Slot = slash(resolver.mapClassName(namespace, "net.minecraft.class_1735"));
|
|
||||||
var LSlot = L(Slot);
|
|
||||||
|
|
||||||
var DefaultedList = slash(resolver.mapClassName(namespace, "net.minecraft.class_2371"));
|
|
||||||
|
|
||||||
for (var mn : node.methods) {
|
|
||||||
// that other comment was a half truth, you can transform mixins :^)
|
|
||||||
if (mn.name.endsWith("trinkets$quickMove") || mn.name.equals(quickMove)) {
|
|
||||||
for (var insn : mn.instructions) {
|
|
||||||
if (insn instanceof VarInsnNode vin) {
|
|
||||||
if (vin.getOpcode() == ASTORE && vin.var == 4) {
|
|
||||||
if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
|
|
||||||
if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
|
|
||||||
if(prevPrevInsn.owner.equals(DefaultedList)) {
|
|
||||||
LabelNode LnotBag = new LabelNode();
|
|
||||||
LabelNode Lend = new LabelNode();
|
|
||||||
mn.instructions.insertBefore(prevPrevInsn.getPrevious().getPrevious().getPrevious(), insns(
|
|
||||||
ILOAD(2),
|
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
|
||||||
IFEQ(LnotBag),
|
|
||||||
ILOAD(2),
|
|
||||||
ALOAD(0),
|
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "getBagSlot", "(I" + LPlayerScreenHandler + ")" + LSlot),
|
|
||||||
CHECKCAST(Slot),
|
|
||||||
ASTORE(vin.var),
|
|
||||||
GOTO(Lend),
|
|
||||||
LnotBag
|
|
||||||
));
|
|
||||||
mn.instructions.insert(vin, insns(
|
|
||||||
Lend
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String slash(String clazz) {
|
|
||||||
return clazz.replaceAll("\\.", "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String L(String clazz) {
|
|
||||||
return "L" + clazz + ";";
|
|
||||||
}
|
|
||||||
|
|
||||||
private InsnList insns(AbstractInsnNode... insns) {
|
|
||||||
var li = new InsnList();
|
|
||||||
for (var i : insns) li.add(i);
|
|
||||||
return li;
|
|
||||||
}
|
|
||||||
private static VarInsnNode ILOAD(int v) {
|
|
||||||
return new VarInsnNode(ILOAD, v);
|
|
||||||
}
|
|
||||||
private static MethodInsnNode INVOKESTATIC(String owner, String name, String desc) {
|
|
||||||
return new MethodInsnNode(INVOKESTATIC, owner, name, desc);
|
|
||||||
}
|
|
||||||
private static JumpInsnNode IFEQ(LabelNode v) {
|
|
||||||
return new JumpInsnNode(IFEQ, v);
|
|
||||||
}
|
|
||||||
private static VarInsnNode ALOAD(int v) {
|
|
||||||
return new VarInsnNode(ALOAD, v);
|
|
||||||
}
|
|
||||||
private static VarInsnNode ASTORE(int v) {
|
|
||||||
return new VarInsnNode(ASTORE, v);
|
|
||||||
}
|
|
||||||
private static TypeInsnNode CHECKCAST(String desc) {
|
|
||||||
return new TypeInsnNode(CHECKCAST, desc);
|
|
||||||
}
|
|
||||||
private static JumpInsnNode GOTO(LabelNode v) {
|
|
||||||
return new JumpInsnNode(GOTO, v);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,21 +6,18 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import net.minecraft.screen.slot.SlotActionType;
|
import net.minecraft.screen.slot.SlotActionType;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
import pm.c7.scout.ScoutMixin.Transformer;
|
import pm.c7.scout.ScoutMixin.Transformer;
|
||||||
import pm.c7.scout.ScoutUtil;
|
import pm.c7.scout.ScoutUtil;
|
||||||
|
|
||||||
@Mixin(value = ScreenHandler.class, priority = 950)
|
@Mixin(ScreenHandler.class)
|
||||||
@Transformer(ScreenHandlerTransformer.class)
|
@Transformer(ScreenHandlerTransformer.class)
|
||||||
public abstract class ScreenHandlerMixin {
|
public abstract class ScreenHandlerMixin {
|
||||||
@Inject(method = "getSlot", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getSlot", at = @At("HEAD"), cancellable = true)
|
||||||
|
@ -58,15 +55,6 @@ public abstract class ScreenHandlerMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "internalOnSlotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;get(I)Ljava/lang/Object;", ordinal = 5))
|
|
||||||
public Object scout$fixSlotIndexing(DefaultedList<Slot> self, int index, int slotIndex, int button, SlotActionType actionType, PlayerEntity player) {
|
|
||||||
if (ScoutUtil.isBagSlot(index)) {
|
|
||||||
return ScoutUtil.getBagSlot(index, player.playerScreenHandler);
|
|
||||||
} else {
|
|
||||||
return self.get(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public static boolean canInsertItemIntoSlot(@Nullable Slot slot, ItemStack stack, boolean allowOverflow) {
|
public static boolean canInsertItemIntoSlot(@Nullable Slot slot, ItemStack stack, boolean allowOverflow) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2,91 +2,58 @@ package pm.c7.scout.mixin;
|
||||||
|
|
||||||
import org.objectweb.asm.tree.*;
|
import org.objectweb.asm.tree.*;
|
||||||
import org.quiltmc.loader.api.QuiltLoader;
|
import org.quiltmc.loader.api.QuiltLoader;
|
||||||
|
|
||||||
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
|
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
public class ScreenHandlerTransformer implements ClassNodeTransformer {
|
public class ScreenHandlerTransformer implements ClassNodeTransformer {
|
||||||
//private static final Logger LOGGER = LoggerFactory.getLogger("Scout:ScreenHandlerTransformer");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(String name, ClassNode node) {
|
public void transform(String name, ClassNode node) {
|
||||||
var resolver = QuiltLoader.getMappingResolver();
|
var internalOnSlotClick = "m_nqfgpzfl";
|
||||||
var namespace = "intermediary";
|
var insertItem = "m_jpjdgbxy";
|
||||||
|
|
||||||
var internalOnSlotClick = resolver.mapMethodName(namespace, name, "method_30010", "(IILnet/minecraft/class_1713;Lnet/minecraft/class_1657;)V");
|
var PlayerEntity = "net/minecraft/unmapped/C_jzrpycqo";
|
||||||
|
var playerScreenHandler = "f_xvlfpipb";
|
||||||
|
|
||||||
|
var PlayerScreenHandler = "net/minecraft/unmapped/C_wgehrbdx";
|
||||||
|
var Slot = "net/minecraft/unmapped/C_nhvqfffd";
|
||||||
|
var DefaultedList = "net/minecraft/unmapped/C_rnrfftze";
|
||||||
|
|
||||||
|
if (QuiltLoader.isDevelopmentEnvironment()) {
|
||||||
|
internalOnSlotClick = "internalOnSlotClick";
|
||||||
|
insertItem = "insertItem";
|
||||||
|
|
||||||
|
PlayerEntity = "net/minecraft/entity/player/PlayerEntity";
|
||||||
|
playerScreenHandler = "playerScreenHandler";
|
||||||
|
|
||||||
|
PlayerScreenHandler = "net/minecraft/screen/PlayerScreenHandler";
|
||||||
|
Slot = "net/minecraft/screen/slot/Slot";
|
||||||
|
DefaultedList = "net/minecraft/util/collection/DefaultedList";
|
||||||
|
}
|
||||||
|
|
||||||
var PlayerEntity = resolver.mapClassName(namespace, "net.minecraft.class_1657");
|
|
||||||
var PlayerScreenHandler = slash(resolver.mapClassName(namespace, "net.minecraft.class_1723"));
|
|
||||||
var LPlayerScreenHandler = L(PlayerScreenHandler);
|
var LPlayerScreenHandler = L(PlayerScreenHandler);
|
||||||
String playerScreenHandler = resolver.mapFieldName(namespace, PlayerEntity, "field_7498", LPlayerScreenHandler);
|
|
||||||
PlayerEntity = slash(PlayerEntity);
|
|
||||||
|
|
||||||
var Slot = slash(resolver.mapClassName(namespace, "net.minecraft.class_1735"));
|
|
||||||
var LSlot = L(Slot);
|
var LSlot = L(Slot);
|
||||||
|
|
||||||
var DefaultedList = slash(resolver.mapClassName(namespace, "net.minecraft.class_2371"));
|
|
||||||
//var LDefaultedList = L(DefaultedList);
|
|
||||||
|
|
||||||
//var slots = resolver.mapFieldName(namespace, name, "field_7761", LDefaultedList);
|
|
||||||
|
|
||||||
int ordinal = 0;
|
|
||||||
|
|
||||||
for (var mn : node.methods) {
|
for (var mn : node.methods) {
|
||||||
if (mn.name.equals(internalOnSlotClick)) {
|
if (mn.name.equals(internalOnSlotClick)) {
|
||||||
for (var insn : mn.instructions) {
|
for (var insn : mn.instructions) {
|
||||||
if (insn instanceof VarInsnNode vin) {
|
if (insn instanceof VarInsnNode vin) {
|
||||||
if (vin.getOpcode() == ILOAD && vin.var == 1) {
|
if (vin.getOpcode() == ILOAD && vin.var == 1) {
|
||||||
if (insn.getNext() instanceof JumpInsnNode nextInsn && nextInsn.getOpcode() == IFGE) {
|
if (insn.getNext() instanceof JumpInsnNode nextInsn && nextInsn.getOpcode() == IFGE) {
|
||||||
// `if (slotIndex < 0) return` -> `if (slotIndex < 0 && !isBagSlot(slotIndex)) return`
|
|
||||||
var jumpTo = nextInsn.label;
|
var jumpTo = nextInsn.label;
|
||||||
mn.instructions.insert(nextInsn, insns(
|
mn.instructions.insert(nextInsn, insns(
|
||||||
ILOAD(1),
|
ILOAD(1),
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
||||||
IFNE(jumpTo)
|
IFNE(jumpTo)
|
||||||
));
|
|
||||||
} else if (insn.getPrevious() instanceof JumpInsnNode prevInsn && prevInsn.getOpcode() == IFEQ && insn.getNext() instanceof JumpInsnNode nextInsn && nextInsn.getOpcode() == IFLT) {
|
|
||||||
// skip creative duping, it uses same signature and i dont feel like overcomplicating the check
|
|
||||||
if (ordinal != 1) {
|
|
||||||
ordinal++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fix dropping from bags not working
|
|
||||||
LabelNode Lcheck = new LabelNode();
|
|
||||||
nextInsn.label = Lcheck;
|
|
||||||
nextInsn.setOpcode(IFGE);
|
|
||||||
mn.instructions.insert(nextInsn, insns(
|
|
||||||
ILOAD(1),
|
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
|
||||||
IFNE(Lcheck),
|
|
||||||
RETURN(),
|
|
||||||
Lcheck
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if (vin.getOpcode() == ASTORE && (vin.var == 6 || vin.var == 7)) {
|
} else if (vin.getOpcode() == ASTORE && (vin.var == 6 || vin.var == 7)) {
|
||||||
// fix most but not all calls to `slots.get`
|
|
||||||
if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
|
if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
|
||||||
if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
|
if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
|
||||||
if(prevPrevInsn.owner.equals(DefaultedList)) {
|
if(prevPrevInsn.owner.equals(DefaultedList)) {
|
||||||
var insertPoint = prevPrevInsn.getPrevious();
|
LabelNode LnotBag = new LabelNode();
|
||||||
|
LabelNode Lend = new LabelNode();
|
||||||
if (insertPoint.getOpcode() == ILOAD) {
|
mn.instructions.insertBefore(prevPrevInsn.getPrevious().getPrevious().getPrevious(), insns(
|
||||||
var beforeInsert = insertPoint.getPrevious();
|
|
||||||
|
|
||||||
if (beforeInsert != null && beforeInsert.getPrevious() != null){
|
|
||||||
if (beforeInsert.getOpcode() == GETFIELD && beforeInsert.getPrevious().getOpcode() == ALOAD) {
|
|
||||||
insertPoint = beforeInsert.getPrevious();
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LabelNode LnotBag = new LabelNode();
|
|
||||||
LabelNode Lend = (LabelNode) vin.getNext();
|
|
||||||
|
|
||||||
mn.instructions.insertBefore(insertPoint, insns(
|
|
||||||
ILOAD(1),
|
ILOAD(1),
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
||||||
IFEQ(LnotBag),
|
IFEQ(LnotBag),
|
||||||
|
@ -98,44 +65,9 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
|
||||||
ASTORE(vin.var),
|
ASTORE(vin.var),
|
||||||
GOTO(Lend),
|
GOTO(Lend),
|
||||||
LnotBag
|
LnotBag
|
||||||
));
|
));
|
||||||
}
|
mn.instructions.insert(vin, insns(
|
||||||
}
|
Lend
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (mn.name.endsWith("debugify$handleCtrlQCrafting")) { // ughghghhghghghghgh
|
|
||||||
for (var insn : mn.instructions) {
|
|
||||||
if (insn instanceof VarInsnNode vin && vin.getOpcode() == ASTORE && vin.var == 6) {
|
|
||||||
if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
|
|
||||||
if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
|
|
||||||
if(prevPrevInsn.owner.equals(DefaultedList)) {
|
|
||||||
var insertPoint = prevPrevInsn.getPrevious();
|
|
||||||
|
|
||||||
if (insertPoint.getOpcode() == ILOAD) {
|
|
||||||
var beforeInsert = insertPoint.getPrevious();
|
|
||||||
|
|
||||||
if (beforeInsert != null && beforeInsert.getPrevious() != null && beforeInsert.getOpcode() == GETFIELD && beforeInsert.getPrevious().getOpcode() == ALOAD) {
|
|
||||||
insertPoint = beforeInsert.getPrevious();
|
|
||||||
}
|
|
||||||
|
|
||||||
LabelNode LnotBag = new LabelNode();
|
|
||||||
LabelNode Lend = (LabelNode) vin.getNext();
|
|
||||||
|
|
||||||
mn.instructions.insertBefore(insertPoint, insns(
|
|
||||||
ILOAD(1),
|
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
|
||||||
IFEQ(LnotBag),
|
|
||||||
ILOAD(1),
|
|
||||||
ALOAD(4),
|
|
||||||
GETFIELD(PlayerEntity, playerScreenHandler, LPlayerScreenHandler),
|
|
||||||
INVOKESTATIC("pm/c7/scout/ScoutUtil", "getBagSlot", "(I" + LPlayerScreenHandler + ")" + LSlot),
|
|
||||||
CHECKCAST(Slot),
|
|
||||||
ASTORE(vin.var),
|
|
||||||
GOTO(Lend),
|
|
||||||
LnotBag
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,84 +75,44 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}/* else if (mn.name.equals(insertItem)) {
|
||||||
|
for (var insn : mn.instructions) {
|
||||||
|
if (insn instanceof VarInsnNode vin && vin.getOpcode() == ASTORE && vin.var == 7) {
|
||||||
|
if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
|
||||||
|
if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
|
||||||
|
if(prevPrevInsn.owner.equals(DefaultedList)) {
|
||||||
|
LabelNode LnotBag = new LabelNode();
|
||||||
|
LabelNode LpastSlot = new LabelNode();
|
||||||
|
mn.instructions.insertBefore(prevPrevInsn.getPrevious().getPrevious().getPrevious(), insns(
|
||||||
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "getPlayerScreenHandler", "()" + LPlayerScreenHandler),
|
||||||
|
ASTORE(20),
|
||||||
|
ALOAD(20),
|
||||||
|
IFNULL(LpastSlot),
|
||||||
|
ILOAD(6),
|
||||||
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
||||||
|
IFEQ(LnotBag),
|
||||||
|
ILOAD(6),
|
||||||
|
ALOAD(20),
|
||||||
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "getBagSlot", "(I" + LPlayerScreenHandler + ")" + LSlot),
|
||||||
|
CHECKCAST(Slot),
|
||||||
|
ASTORE(vin.var),
|
||||||
|
LnotBag,
|
||||||
|
ILOAD(6),
|
||||||
|
INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
|
||||||
|
IFNE(LpastSlot)
|
||||||
|
));
|
||||||
|
mn.instructions.insert(vin, insns(
|
||||||
|
LpastSlot
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug, keeping here for future use
|
|
||||||
/*private static List<Field> allOpcodes = Arrays.asList(Opcodes.class.getFields());
|
|
||||||
|
|
||||||
private String getOpcodeName(int v) {
|
|
||||||
Optional<Field> opcode = allOpcodes.stream()
|
|
||||||
.filter(f -> f.getType() == int.class)
|
|
||||||
.filter(f -> {
|
|
||||||
if (f.getName().startsWith("F_")) {
|
|
||||||
return f.getName().equals("F_NEW");
|
|
||||||
} else {
|
|
||||||
return !f.getName().startsWith("V")
|
|
||||||
&& !f.getName().startsWith("ASM")
|
|
||||||
&& !f.getName().startsWith("SOURCE_")
|
|
||||||
&& !f.getName().startsWith("ACC_")
|
|
||||||
&& !f.getName().startsWith("H_")
|
|
||||||
&& !f.getName().startsWith("T_");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(f -> {
|
|
||||||
try {
|
|
||||||
var field = f.get(Opcodes.class);
|
|
||||||
//LOGGER.info("{} {} | {}", f.getName(), f.getType(), field);
|
|
||||||
return field.equals(v);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (opcode.isEmpty()) {
|
|
||||||
return "<unknown: " + String.valueOf(v) + ">";
|
|
||||||
}
|
|
||||||
|
|
||||||
return opcode.get().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printNode(AbstractInsnNode node) {
|
|
||||||
var name = getOpcodeName(node.getOpcode());
|
|
||||||
String val = "";
|
|
||||||
|
|
||||||
if (node instanceof VarInsnNode vin) {
|
|
||||||
val = String.valueOf(vin.var);
|
|
||||||
} else if(node instanceof FieldInsnNode fin) {
|
|
||||||
val = fin.owner + "." + fin.name + ":" + fin.desc;
|
|
||||||
} else if(node instanceof MethodInsnNode min) {
|
|
||||||
val = min.owner + "." + min.name + ":" + min.desc;
|
|
||||||
} else if (node instanceof TypeInsnNode tin) {
|
|
||||||
val = tin.desc;
|
|
||||||
} else if (node instanceof JumpInsnNode jin) {
|
|
||||||
val = jin.label.toString();
|
|
||||||
} else if (node instanceof LabelNode label) {
|
|
||||||
name = "L";
|
|
||||||
val = label.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.info("{} {}", name, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dumpInstructions(InsnList insns, int start, int end) {
|
|
||||||
for (var i = start; i < end + 1; i++) {
|
|
||||||
printNode(insns.get(i));
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private String slash(String clazz) {
|
|
||||||
return clazz.replaceAll("\\.", "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String L(String clazz) {
|
private String L(String clazz) {
|
||||||
return "L" + clazz + ";";
|
return "L" + clazz + ";";
|
||||||
}
|
}
|
||||||
|
@ -230,34 +122,34 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
|
||||||
for (var i : insns) li.add(i);
|
for (var i : insns) li.add(i);
|
||||||
return li;
|
return li;
|
||||||
}
|
}
|
||||||
private static VarInsnNode ILOAD(int v) {
|
private static VarInsnNode ILOAD(int var) {
|
||||||
return new VarInsnNode(ILOAD, v);
|
return new VarInsnNode(ILOAD, var);
|
||||||
}
|
}
|
||||||
private static MethodInsnNode INVOKESTATIC(String owner, String name, String desc) {
|
private static MethodInsnNode INVOKESTATIC(String owner, String name, String desc) {
|
||||||
return new MethodInsnNode(INVOKESTATIC, owner, name, desc);
|
return new MethodInsnNode(INVOKESTATIC, owner, name, desc);
|
||||||
}
|
}
|
||||||
private static JumpInsnNode IFNE(LabelNode v) {
|
private static JumpInsnNode IFNE(LabelNode var) {
|
||||||
return new JumpInsnNode(IFNE, v);
|
return new JumpInsnNode(IFNE, var);
|
||||||
}
|
}
|
||||||
private static JumpInsnNode IFEQ(LabelNode v) {
|
private static JumpInsnNode IFEQ(LabelNode var) {
|
||||||
return new JumpInsnNode(IFEQ, v);
|
return new JumpInsnNode(IFEQ, var);
|
||||||
}
|
}
|
||||||
private static VarInsnNode ALOAD(int v) {
|
private static VarInsnNode ALOAD(int var) {
|
||||||
return new VarInsnNode(ALOAD, v);
|
return new VarInsnNode(ALOAD, var);
|
||||||
}
|
}
|
||||||
private static VarInsnNode ASTORE(int v) {
|
private static VarInsnNode ASTORE(int var) {
|
||||||
return new VarInsnNode(ASTORE, v);
|
return new VarInsnNode(ASTORE, var);
|
||||||
}
|
}
|
||||||
private static FieldInsnNode GETFIELD(String owner, String name, String desc) {
|
private static FieldInsnNode GETFIELD(String owner, String name, String desc) {
|
||||||
return new FieldInsnNode(GETFIELD, owner, name, desc);
|
return new FieldInsnNode(GETFIELD, owner, name, desc);
|
||||||
}
|
}
|
||||||
|
private static JumpInsnNode IFNULL(LabelNode var) {
|
||||||
|
return new JumpInsnNode(IFNULL, var);
|
||||||
|
}
|
||||||
private static TypeInsnNode CHECKCAST(String desc) {
|
private static TypeInsnNode CHECKCAST(String desc) {
|
||||||
return new TypeInsnNode(CHECKCAST, desc);
|
return new TypeInsnNode(CHECKCAST, desc);
|
||||||
}
|
}
|
||||||
private static JumpInsnNode GOTO(LabelNode v) {
|
private static JumpInsnNode GOTO(LabelNode var) {
|
||||||
return new JumpInsnNode(GOTO, v);
|
return new JumpInsnNode(GOTO, var);
|
||||||
}
|
|
||||||
private static InsnNode RETURN() {
|
|
||||||
return new InsnNode(RETURN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen;
|
import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
|
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.AbstractFurnaceScreenHandler;
|
import net.minecraft.screen.AbstractFurnaceScreenHandler;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
|
|
@ -9,10 +9,10 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
@Mixin(HandledScreen.class)
|
@Mixin(HandledScreen.class)
|
||||||
public interface HandledScreenAccessor {
|
public interface HandledScreenAccessor {
|
||||||
@Accessor("x")
|
@Accessor("x")
|
||||||
int getX();
|
int getX();
|
||||||
@Accessor("y")
|
@Accessor("y")
|
||||||
int getY();
|
int getY();
|
||||||
@Accessor("backgroundWidth")
|
@Accessor("backgroundWidth")
|
||||||
int getBackgroundWidth();
|
int getBackgroundWidth();
|
||||||
@Accessor("backgroundHeight")
|
@Accessor("backgroundHeight")
|
||||||
|
|
|
@ -3,12 +3,14 @@ package pm.c7.scout.mixin.client;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
|
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
|
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
|
||||||
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen;
|
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
@ -44,7 +46,7 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
|
||||||
@Shadow
|
@Shadow
|
||||||
protected int backgroundHeight;
|
protected int backgroundHeight;
|
||||||
|
|
||||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/gui/GuiGraphics;FII)V"))
|
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/util/math/MatrixStack;FII)V"))
|
||||||
private void scout$drawSatchelRow(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
private void scout$drawSatchelRow(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
|
if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
|
||||||
ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BaseBagItem.BagType.SATCHEL, false);
|
ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BaseBagItem.BagType.SATCHEL, false);
|
||||||
|
@ -270,12 +272,13 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/gui/GuiGraphics;II)V"))
|
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/util/math/MatrixStack;II)V"))
|
||||||
public void scout$drawOurSlots(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
public void scout$drawOurSlots(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
|
if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
|
||||||
for (int i = ScoutUtil.SATCHEL_SLOT_START; i > ScoutUtil.BAG_SLOTS_END; i--) {
|
for (int i = ScoutUtil.SATCHEL_SLOT_START; i > ScoutUtil.BAG_SLOTS_END; i--) {
|
||||||
BagSlot slot = (BagSlot) ScoutUtil.getBagSlot(i, this.client.player.playerScreenHandler);
|
BagSlot slot = (BagSlot) ScoutUtil.getBagSlot(i, this.client.player.playerScreenHandler);
|
||||||
if (slot != null && slot.isEnabled()) {
|
if (slot != null && slot.isEnabled()) {
|
||||||
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
this.drawSlot(graphics, slot);
|
this.drawSlot(graphics, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,21 +2,25 @@ package pm.c7.scout.mixin.client;
|
||||||
|
|
||||||
import org.objectweb.asm.tree.*;
|
import org.objectweb.asm.tree.*;
|
||||||
import org.quiltmc.loader.api.QuiltLoader;
|
import org.quiltmc.loader.api.QuiltLoader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
|
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
public class HandledScreenTransformer implements ClassNodeTransformer {
|
public class HandledScreenTransformer implements ClassNodeTransformer {
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger("Scout:HandledScreenTransformer");
|
||||||
@Override
|
@Override
|
||||||
public void transform(String name, ClassNode node) {
|
public void transform(String name, ClassNode node) {
|
||||||
var resolver = QuiltLoader.getMappingResolver();
|
var drawSlot = "m_zioswvnu";
|
||||||
var namespace = "intermediary";
|
var Slot = "net/minecraft/unmapped/C_nhvqfffd";
|
||||||
|
var y = "f_tttqoodj";
|
||||||
|
|
||||||
var drawSlot = resolver.mapMethodName(namespace, name, "method_2385", "(Lnet/minecraft/class_332;Lnet/minecraft/class_1735;)V");
|
if (QuiltLoader.isDevelopmentEnvironment()) {
|
||||||
var Slot = resolver.mapClassName(namespace, "net.minecraft.class_1735");
|
drawSlot = "drawSlot";
|
||||||
var y = resolver.mapFieldName(namespace, Slot, "field_7872", "I");
|
Slot = "net/minecraft/screen/slot/Slot";
|
||||||
Slot = slash(Slot);
|
y = "y";
|
||||||
|
}
|
||||||
|
|
||||||
for (var mn : node.methods) {
|
for (var mn : node.methods) {
|
||||||
if (mn.name.equals(drawSlot)) {
|
if (mn.name.equals(drawSlot)) {
|
||||||
|
@ -28,19 +32,19 @@ public class HandledScreenTransformer implements ClassNodeTransformer {
|
||||||
LabelNode LnotBag = new LabelNode();
|
LabelNode LnotBag = new LabelNode();
|
||||||
int SAFE_REGISTER = 20;
|
int SAFE_REGISTER = 20;
|
||||||
mn.instructions.insert(vin, insns(
|
mn.instructions.insert(vin, insns(
|
||||||
ALOAD(2),
|
ALOAD(2),
|
||||||
INSTANCEOF("pm/c7/scout/screen/BagSlot"),
|
INSTANCEOF("pm/c7/scout/screen/BagSlot"),
|
||||||
IFEQ(LnotBag),
|
IFEQ(LnotBag),
|
||||||
ALOAD(2),
|
ALOAD(2),
|
||||||
CHECKCAST("pm/c7/scout/screen/BagSlot"),
|
CHECKCAST("pm/c7/scout/screen/BagSlot"),
|
||||||
ASTORE(SAFE_REGISTER),
|
ASTORE(SAFE_REGISTER),
|
||||||
ALOAD(SAFE_REGISTER),
|
ALOAD(SAFE_REGISTER),
|
||||||
INVOKEVIRTUAL("pm/c7/scout/screen/BagSlot", "getX", "()I"),
|
INVOKEVIRTUAL("pm/c7/scout/screen/BagSlot", "getX", "()I"),
|
||||||
ISTORE(vin.var - 1),
|
ISTORE(vin.var - 1),
|
||||||
ALOAD(SAFE_REGISTER),
|
ALOAD(SAFE_REGISTER),
|
||||||
INVOKEVIRTUAL("pm/c7/scout/screen/BagSlot", "getY", "()I"),
|
INVOKEVIRTUAL("pm/c7/scout/screen/BagSlot", "getY", "()I"),
|
||||||
ISTORE(vin.var),
|
ISTORE(vin.var),
|
||||||
LnotBag
|
LnotBag
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,23 +55,19 @@ public class HandledScreenTransformer implements ClassNodeTransformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String slash(String clazz) {
|
|
||||||
return clazz.replaceAll("\\.", "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private InsnList insns(AbstractInsnNode... insns) {
|
private InsnList insns(AbstractInsnNode... insns) {
|
||||||
var li = new InsnList();
|
var li = new InsnList();
|
||||||
for (var i : insns) li.add(i);
|
for (var i : insns) li.add(i);
|
||||||
return li;
|
return li;
|
||||||
}
|
}
|
||||||
private static JumpInsnNode IFEQ(LabelNode v) {
|
private static JumpInsnNode IFEQ(LabelNode var) {
|
||||||
return new JumpInsnNode(IFEQ, v);
|
return new JumpInsnNode(IFEQ, var);
|
||||||
}
|
}
|
||||||
private static VarInsnNode ALOAD(int v) {
|
private static VarInsnNode ALOAD(int var) {
|
||||||
return new VarInsnNode(ALOAD, v);
|
return new VarInsnNode(ALOAD, var);
|
||||||
}
|
}
|
||||||
private static VarInsnNode ASTORE(int v) {
|
private static VarInsnNode ASTORE(int var) {
|
||||||
return new VarInsnNode(ASTORE, v);
|
return new VarInsnNode(ASTORE, var);
|
||||||
}
|
}
|
||||||
private static TypeInsnNode INSTANCEOF(String desc) {
|
private static TypeInsnNode INSTANCEOF(String desc) {
|
||||||
return new TypeInsnNode(INSTANCEOF, desc);
|
return new TypeInsnNode(INSTANCEOF, desc);
|
||||||
|
@ -78,7 +78,7 @@ public class HandledScreenTransformer implements ClassNodeTransformer {
|
||||||
private static MethodInsnNode INVOKEVIRTUAL(String owner, String name, String desc) {
|
private static MethodInsnNode INVOKEVIRTUAL(String owner, String name, String desc) {
|
||||||
return new MethodInsnNode(INVOKEVIRTUAL, owner, name, desc);
|
return new MethodInsnNode(INVOKEVIRTUAL, owner, name, desc);
|
||||||
}
|
}
|
||||||
private static VarInsnNode ISTORE(int v) {
|
private static VarInsnNode ISTORE(int var) {
|
||||||
return new VarInsnNode(ISTORE, v);
|
return new VarInsnNode(ISTORE, var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
package pm.c7.scout.mixin.client;
|
package pm.c7.scout.mixin.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
|
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
|
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
|
||||||
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
|
import net.minecraft.client.gui.screen.recipe.book.RecipeBookProvider;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.PlayerScreenHandler;
|
import net.minecraft.screen.PlayerScreenHandler;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import pm.c7.scout.ScoutUtil;
|
import pm.c7.scout.ScoutUtil;
|
||||||
import pm.c7.scout.item.BaseBagItem;
|
import pm.c7.scout.item.BaseBagItem;
|
||||||
|
@ -18,45 +22,45 @@ import pm.c7.scout.item.BaseBagItem.BagType;
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
@Mixin(InventoryScreen.class)
|
@Mixin(InventoryScreen.class)
|
||||||
public abstract class InventoryScreenMixin extends AbstractInventoryScreen<PlayerScreenHandler> implements RecipeBookProvider {
|
public abstract class InventoryScreenMixin extends AbstractInventoryScreen<PlayerScreenHandler> implements RecipeBookProvider {
|
||||||
private InventoryScreenMixin() {
|
private InventoryScreenMixin() {
|
||||||
super(null, null, null);
|
super(null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "isClickOutsideBounds", at = @At("TAIL"), cancellable = true)
|
@Inject(method = "isClickOutsideBounds", at = @At("TAIL"), cancellable = true)
|
||||||
private void scout$adjustOutsideBounds(double mouseX, double mouseY, int left, int top, int button, CallbackInfoReturnable<Boolean> callbackInfo) {
|
private void scout$adjustOutsideBounds(double mouseX, double mouseY, int left, int top, int button, CallbackInfoReturnable<Boolean> callbackInfo) {
|
||||||
if (this.client != null && this.client.player != null) {
|
if (this.client != null && this.client.player != null) {
|
||||||
ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BagType.SATCHEL, false);
|
ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BagType.SATCHEL, false);
|
||||||
if (!backStack.isEmpty()) {
|
if (!backStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) backStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) backStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
int rows = (int) Math.ceil(slots / 9);
|
int rows = (int) Math.ceil(slots / 9);
|
||||||
|
|
||||||
if (mouseY < (top + this.backgroundHeight) + 8 + (18 * rows) && mouseY >= (top + this.backgroundHeight) && mouseX >= left && mouseY < (left + this.backgroundWidth)) {
|
if (mouseY < (top + this.backgroundHeight) + 8 + (18 * rows) && mouseY >= (top + this.backgroundHeight) && mouseX >= left && mouseY < (left + this.backgroundWidth)) {
|
||||||
callbackInfo.setReturnValue(false);
|
callbackInfo.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
|
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
|
||||||
if (!leftPouchStack.isEmpty()) {
|
if (!leftPouchStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
int columns = (int) Math.ceil(slots / 3);
|
int columns = (int) Math.ceil(slots / 3);
|
||||||
|
|
||||||
if (mouseX >= left - (columns * 18) && mouseX < left && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
|
if (mouseX >= left - (columns * 18) && mouseX < left && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
|
||||||
callbackInfo.setReturnValue(false);
|
callbackInfo.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack rightPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, true);
|
ItemStack rightPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, true);
|
||||||
if (!rightPouchStack.isEmpty()) {
|
if (!rightPouchStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) rightPouchStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
int columns = (int) Math.ceil(slots / 3);
|
int columns = (int) Math.ceil(slots / 3);
|
||||||
|
|
||||||
if (mouseX >= (left + this.backgroundWidth) && mouseX < (left + this.backgroundWidth) + (columns * 18) && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
|
if (mouseX >= (left + this.backgroundWidth) && mouseX < (left + this.backgroundWidth) + (columns * 18) && mouseY >= (top + this.backgroundHeight) - 90 && mouseY < (top + this.backgroundHeight) - 22) {
|
||||||
callbackInfo.setReturnValue(false);
|
callbackInfo.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,36 +19,36 @@ import pm.c7.scout.item.BaseBagItem.BagType;
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
@Mixin(value = RecipeBookWidget.class, priority = 950)
|
@Mixin(value = RecipeBookWidget.class, priority = 950)
|
||||||
public class RecipeBookWidgetMixin {
|
public class RecipeBookWidgetMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
protected MinecraftClient client;
|
protected MinecraftClient client;
|
||||||
@Shadow
|
@Shadow
|
||||||
private int leftOffset;
|
private int leftOffset;
|
||||||
|
|
||||||
@Inject(method = "findLeftEdge", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
|
@Inject(method = "findLeftEdge", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
|
||||||
private void scout$modifyRecipeBookPosition(int width, int backgroundWidth, CallbackInfoReturnable<Integer> callbackInfo, int x) {
|
private void scout$modifyRecipeBookPosition(int width, int backgroundWidth, CallbackInfoReturnable<Integer> callbackInfo, int x) {
|
||||||
if (this.client != null && this.client.player != null && this.isOpen()) {
|
if (this.client != null && this.client.player != null && this.isOpen()) {
|
||||||
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
|
ItemStack leftPouchStack = ScoutUtil.findBagItem(this.client.player, BagType.POUCH, false);
|
||||||
if (!leftPouchStack.isEmpty()) {
|
if (!leftPouchStack.isEmpty()) {
|
||||||
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
BaseBagItem bagItem = (BaseBagItem) leftPouchStack.getItem();
|
||||||
int slots = bagItem.getSlotCount();
|
int slots = bagItem.getSlotCount();
|
||||||
|
|
||||||
int columns = (int) Math.ceil(slots / 3);
|
int columns = (int) Math.ceil(slots / 3);
|
||||||
|
|
||||||
// Realign as best we can when "Keep crafting screens centered" is enabled in Better Recipe Book
|
// Realign as best we can when "Keep crafting screens centered" is enabled in Better Recipe Book
|
||||||
if (this.leftOffset != 86) {
|
if (this.leftOffset != 86) {
|
||||||
int diff = this.leftOffset - 86;
|
int diff = this.leftOffset - 86;
|
||||||
x -= diff;
|
x -= diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
x += 18 * columns;
|
x += 18 * columns;
|
||||||
|
|
||||||
callbackInfo.setReturnValue(x);
|
callbackInfo.setReturnValue(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import pm.c7.scout.ScoutConfig;
|
import pm.c7.scout.config.ScoutConfigHandler;
|
||||||
import pm.c7.scout.item.BaseBagItem;
|
import pm.c7.scout.item.BaseBagItem;
|
||||||
|
|
||||||
public class BagSlot extends Slot {
|
public class BagSlot extends Slot {
|
||||||
|
@ -38,7 +38,7 @@ public class BagSlot extends Slot {
|
||||||
|
|
||||||
if (stack.getItem() instanceof BlockItem blockItem) {
|
if (stack.getItem() instanceof BlockItem blockItem) {
|
||||||
if (blockItem.getBlock() instanceof ShulkerBoxBlock)
|
if (blockItem.getBlock() instanceof ShulkerBoxBlock)
|
||||||
return enabled && inventory != null && ScoutConfig.CONFIG.allowShulkers.value();
|
return (boolean) ScoutConfigHandler.getConfigValue("allowShulkers").value();
|
||||||
}
|
}
|
||||||
|
|
||||||
return enabled && inventory != null;
|
return enabled && inventory != null;
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 229 B |
|
@ -55,6 +55,16 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"breaks": [
|
"breaks": [
|
||||||
|
{
|
||||||
|
"id": "roughlyenoughitems",
|
||||||
|
"versions": "*",
|
||||||
|
"reason": "API constantly rewritten for no reason, arrogant mod author, features stolen from EMI."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "inventoryprofilesnext",
|
||||||
|
"versions": "*",
|
||||||
|
"reason": "Crashes with no intent to fix on their end."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "infinitory",
|
"id": "infinitory",
|
||||||
"versions": "*",
|
"versions": "*",
|
||||||
|
@ -74,16 +84,6 @@
|
||||||
"id": "inventory_backpack",
|
"id": "inventory_backpack",
|
||||||
"versions": "*",
|
"versions": "*",
|
||||||
"reason": "Infinite/Incompatible inventory mod."
|
"reason": "Infinite/Incompatible inventory mod."
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "realistic-inventory",
|
|
||||||
"versions": "*",
|
|
||||||
"reason": "Infinite/Incompatible inventory mod."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "inventorymod",
|
|
||||||
"versions": "*",
|
|
||||||
"reason": "Infinite/Incompatible inventory mod."
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue