Search in sources :

Example 1 with StructureTagMessage

use of com.wuest.prefab.structures.messages.StructureTagMessage 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)

Aggregations

StructureItem (com.wuest.prefab.structures.items.StructureItem)1 StructureTagMessage (com.wuest.prefab.structures.messages.StructureTagMessage)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