Skip to content

Commit

Permalink
try to support crafter
Browse files Browse the repository at this point in the history
try to support crafter
  • Loading branch information
17183248569 committed Nov 1, 2023
1 parent ff8fc87 commit 3c35adf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package carpet.mixins;

import net.minecraft.network.protocol.game.ServerboundContainerSlotStateChangedPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.inventory.CrafterMenu;
import net.minecraft.world.level.block.entity.CrafterBlockEntity;

import org.spongepowered.asm.mixin.Mixin;
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;

@Mixin(ServerGamePacketListenerImpl.class)
public abstract class ServerGamePacketListenerImpl_scarpetCrafterScreen
{

@Shadow
public ServerPlayer player;

@Inject(method = "handleContainerSlotStateChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/CrafterMenu;getContainer()Lnet/minecraft/world/Container;"))

private void injected(ServerboundContainerSlotStateChangedPacket serverboundContainerSlotStateChangedPacket,CallbackInfo ci) {
CrafterMenu cm =(CrafterMenu)this.player.containerMenu;
if(!(cm.getContainer() instanceof CrafterBlockEntity)){
cm.setSlotState(serverboundContainerSlotStateChangedPacket.slotId(), serverboundContainerSlotStateChangedPacket.newState());
};
}
}
13 changes: 13 additions & 0 deletions src/main/java/carpet/script/value/ScreenValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.ContainerListener;
import net.minecraft.world.inventory.CraftingMenu;
import net.minecraft.world.inventory.CrafterMenu;
import net.minecraft.world.inventory.DataSlot;
import net.minecraft.world.inventory.EnchantmentMenu;
import net.minecraft.world.inventory.FurnaceMenu;
Expand Down Expand Up @@ -102,6 +103,7 @@ public class ScreenValue extends Value
screenHandlerFactories.put("smithing", SmithingMenu::new);
screenHandlerFactories.put("smoker", SmokerMenu::new);
screenHandlerFactories.put("stonecutter", StonecutterMenu::new);
screenHandlerFactories.put("crafter_3x3", (x,y)->{var m =new CrafterMenu(x,y);m.addSlotListener(m);return m;});
}


Expand Down Expand Up @@ -348,6 +350,17 @@ private DataSlot getProperty(String propertyName)
case "enchantment_level_3" -> getPropertyForType(EnchantmentMenu.class, "enchantment", 9, propertyName);
case "banner_pattern" -> getPropertyForType(LoomMenu.class, "loom", 0, propertyName);
case "stonecutter_recipe" -> getPropertyForType(StonecutterMenu.class, "stonecutter", 0, propertyName);
case "crafter_slot_disable_0" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 0, propertyName);
case "crafter_slot_disable_1" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 1, propertyName);
case "crafter_slot_disable_2" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 2, propertyName);
case "crafter_slot_disable_3" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 3, propertyName);
case "crafter_slot_disable_4" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 4, propertyName);
case "crafter_slot_disable_5" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 5, propertyName);
case "crafter_slot_disable_6" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 6, propertyName);
case "crafter_slot_disable_7" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 7, propertyName);
case "crafter_slot_disable_8" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 8, propertyName);
case "crafter_enable" -> getPropertyForType(CrafterMenu.class, "crafter_3x3", 9, propertyName);

default -> throw new InternalExpressionException("Invalid screen property: " + propertyName);
};

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/carpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Villager_aiMixin",
"Player_fakePlayersMixin",
"ServerGamePacketListenerImpl_coreMixin",
"ServerGamePacketListenerImpl_scarpetCrafterScreen",
"MinecraftServer_scarpetMixin",
"ExperienceOrb_xpNoCooldownMixin",
"Player_xpNoCooldownMixin",
Expand Down

0 comments on commit 3c35adf

Please sign in to comment.