Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
keybindings
package transfarmer.adventureitems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import transfarmer.adventureitems.capabilities.ISoulWeapon;
import transfarmer.adventureitems.capabilities.Provider;
@EventBusSubscriber(value = Dist.CLIENT, modid = Main.MODID, bus = EventBusSubscriber.Bus.FORGE)
public class Keybindings {
public static final KeyBinding[] keybindings = new KeyBinding[1];
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event) {
Minecraft.getInstance().player.sendChatMessage("key pressed");
if (Keybindings.keybindings[0].isPressed()) {
Minecraft.getInstance().player.sendChatMessage("key pressed");
ISoulWeapon type = (ISoulWeapon) Minecraft.getInstance().player.getCapability(Provider.TYPE);
if (type.getCurrentType() != null) {
Minecraft.getInstance().displayGuiScreen(new AttributeScreen(new TranslationTextComponent("menu.adventureitems.attributes")));
} else {
Minecraft.getInstance().displayGuiScreen(new AttributeScreen(new TranslationTextComponent("menu.adventureitems.weapons")));
}
}
}
public static void register() {
keybindings[0] = new KeyBinding("key.attributes", 'R', "adventure items");
for (KeyBinding keybinding : keybindings) {
ClientRegistry.registerKeyBinding(keybinding);
}
}
}
package transfarmer.adventureitems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryManager;
import transfarmer.adventureitems.capabilities.ISoulWeapon;
import transfarmer.adventureitems.capabilities.Provider;
import transfarmer.adventureitems.capabilities.SoulWeapon;
import transfarmer.adventureitems.capabilities.Storage;
import transfarmer.adventureitems.items.*;
@EventBusSubscriber(modid = Main.MODID, bus = EventBusSubscriber.Bus.MOD)
public class ModEventSubscriber {
@SubscribeEvent
public static void onRegisterItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(setup(new SoulBigsword(), "soul_bigsword"),
setup(new SoulSword(), "soul_sword"),
setup(new SoulDagger(), "soul_dagger"));
}
public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final String name) {
return setup(entry, new ResourceLocation(Main.MODID, name));
}
public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final ResourceLocation registryName) {
entry.setRegistryName(registryName);
return entry;
}
@SubscribeEvent
public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
if (event.getObject() instanceof PlayerEntity) {
event.addCapability(new ResourceLocation(Main.MODID, "type"), new Provider());
}
}
@SubscribeEvent
public void onCommonSetup(FMLCommonSetupEvent event) {
CapabilityManager.INSTANCE.register(ISoulWeapon.class, new Storage(), SoulWeapon::new);
}
@SubscribeEvent
public void onClientSetup(FMLClientSetupEvent event) {
Keybindings.register();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.