Search in sources :

Example 1 with StructureItem

use of com.wuest.prefab.structures.items.StructureItem in project MC-Prefab by Brian-Wuest.

the class ClientEventHandler method KeyInput.

@SubscribeEvent(priority = EventPriority.NORMAL)
@OnlyIn(Dist.CLIENT)
public static void KeyInput(InputEvent.KeyInputEvent event) {
    for (KeyMapping binding : ClientEventHandler.keyBindings) {
        if (binding.isDown()) {
            if (StructureRenderHandler.currentStructure != null) {
                ItemStack mainHandStack = Minecraft.getInstance().player.getMainHandItem();
                ItemStack offHandStack = Minecraft.getInstance().player.getOffhandItem();
                boolean foundCorrectStructureItem = false;
                if (mainHandStack != ItemStack.EMPTY || offHandStack != ItemStack.EMPTY) {
                    StructureTagMessage.EnumStructureConfiguration structureConfigurationEnum = StructureTagMessage.EnumStructureConfiguration.getByConfigurationInstance(StructureRenderHandler.currentConfiguration);
                    if (mainHandStack != ItemStack.EMPTY && mainHandStack.getItem() instanceof StructureItem) {
                        // Check main hand.
                        foundCorrectStructureItem = ClientEventHandler.checkIfStackIsCorrectGui(structureConfigurationEnum, mainHandStack);
                    }
                    if (!foundCorrectStructureItem && offHandStack != ItemStack.EMPTY && offHandStack.getItem() instanceof StructureItem) {
                        // Main hand is not correct item; check off-hand
                        foundCorrectStructureItem = ClientEventHandler.checkIfStackIsCorrectGui(structureConfigurationEnum, offHandStack);
                    }
                }
                if (foundCorrectStructureItem) {
                    Prefab.network.sendToServer(new StructureTagMessage(StructureRenderHandler.currentConfiguration.WriteToCompoundTag(), StructureTagMessage.EnumStructureConfiguration.getByConfigurationInstance(StructureRenderHandler.currentConfiguration)));
                }
                StructureRenderHandler.currentStructure = null;
            }
            break;
        }
    }
}
Also used : StructureItem(com.wuest.prefab.structures.items.StructureItem) KeyMapping(net.minecraft.client.KeyMapping) ItemStack(net.minecraft.world.item.ItemStack) StructureTagMessage(com.wuest.prefab.structures.messages.StructureTagMessage) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with StructureItem

use of com.wuest.prefab.structures.items.StructureItem in project MC-Prefab by Brian-Wuest.

the class ClientProxy method openGuiForItem.

@Override
public void openGuiForItem(UseOnContext itemUseContext) {
    for (Map.Entry<StructureItem, GuiStructure> entry : ClientProxy.ModGuis.entrySet()) {
        if (entry.getKey() == itemUseContext.getItemInHand().getItem()) {
            GuiStructure screen = entry.getValue();
            screen.pos = itemUseContext.getClickedPos();
            Minecraft.getInstance().setScreen(screen);
        }
    }
}
Also used : GuiStructure(com.wuest.prefab.structures.gui.GuiStructure) StructureItem(com.wuest.prefab.structures.items.StructureItem) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StructureItem (com.wuest.prefab.structures.items.StructureItem)2 GuiStructure (com.wuest.prefab.structures.gui.GuiStructure)1 StructureTagMessage (com.wuest.prefab.structures.messages.StructureTagMessage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 KeyMapping (net.minecraft.client.KeyMapping)1 ItemStack (net.minecraft.world.item.ItemStack)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1