Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

e2rifia

Members
  • Posts

    28
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

e2rifia's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. It worked! Thank you for guiding me, diesieben07. If I have @EventBusSubscriber for my client-only event handlers, do I still have to call them in my Chants2 constructor? I'll paste my code here for when I have to look back. @Mod(Chants2.MODID) public class Chants2 { public static final String MODID = "chants2"; public Chants2(){ final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); final ClientSideOnlyModEventRegistrar clientSideOnlyModEventRegistrar = new ClientSideOnlyModEventRegistrar(modEventBus); registerCommonEvents(modEventBus); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> clientSideOnlyModEventRegistrar::registerClientOnlyEvents); } public void registerCommonEvents(IEventBus eventBus) { //eventBus.register(GuiHandler.class); } } //@Mod.EventBusSubscriber(Dist.CLIENT) public class ClientSideOnlyModEventRegistrar { private final IEventBus eventBus; public ClientSideOnlyModEventRegistrar(IEventBus eventBus) { this.eventBus = eventBus; } public void registerClientOnlyEvents() { eventBus.register(GuiHandler.class); } } //@Mod.EventBusSubscriber(Dist.CLIENT) public class GuiHandler { static String text = "Hello world!"; @SubscribeEvent public static void onRenderGui(FMLClientSetupEvent event) { OverlayRegistry.registerOverlayBottom("hello", new IIngameOverlay() { @Override public void render(ForgeIngameGui gui, PoseStack mStack, float partialTicks, int width, int height) { drawString(mStack, Minecraft.getInstance().font, text, width / 2, height / 2, Integer.parseInt("33AA66", 16)); } }); } }
  2. I think I registered the GuiHandler event handler here. public class ClientSideOnlyModEventRegistrar { private final IEventBus eventBus; public ClientSideOnlyModEventRegistrar(IEventBus eventBus) { this.eventBus = eventBus; } public void registerClientOnlyEvents() { eventBus.register(GuiHandler.class); } } I called the registrar above here. @Mod(Chants2.MODID) public class Chants2 { public static final String MODID = "chants2"; public Chants2(){ final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); final ClientSideOnlyModEventRegistrar clientSideOnlyModEventRegistrar = new ClientSideOnlyModEventRegistrar(modEventBus); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> clientSideOnlyModEventRegistrar::registerClientOnlyEvents); } } I guessed from reading the documentation on FMLClientSetupEvent that said to use Dist.CLIENT.
  3. "Call from net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent." I found it. One step further! I don't think FMLClientSetupEvent is reached. The other classes are untouched. What did I do wrong this time? public class GuiHandler { String text = "Hello world!"; @SubscribeEvent public void onRenderGui(FMLClientSetupEvent event) {System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); OverlayRegistry.registerOverlayBottom("hello", new IIngameOverlay() { @Override public void render(ForgeIngameGui gui, PoseStack mStack, float partialTicks, int width, int height) { drawString(mStack, Minecraft.getInstance().font, text, width / 2, height / 2, Integer.parseInt("33AA66", 16)); } }); } }
  4. The text doesn't show. What did I do wrong this time? public class GuiHandler { String text = "Hello world!"; @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { OverlayRegistry.registerOverlayTop("hello", new IIngameOverlay() { @Override public void render(ForgeIngameGui gui, PoseStack mStack, float partialTicks, int width, int height) { drawString(mStack, Minecraft.getInstance().font, text, width / 2, height / 2, Integer.parseInt("33AA66", 16)); } }); } }
  5. This is my code. How can I change it to have "Hello world!" show on the screen? @Mod(Chants2.MODID) public class Chants2 { public static final String MODID = "chants2"; public Chants2(){ final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); final ClientSideOnlyModEventRegistrar clientSideOnlyModEventRegistrar = new ClientSideOnlyModEventRegistrar(modEventBus); registerCommonEvents(modEventBus); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> clientSideOnlyModEventRegistrar::registerClientOnlyEvents); } public void registerCommonEvents(IEventBus eventBus) { //eventBus.register(GuiHandler.class); } } public class ClientSideOnlyModEventRegistrar { private final IEventBus eventBus; public ClientSideOnlyModEventRegistrar(IEventBus eventBus) { this.eventBus = eventBus; } public void registerClientOnlyEvents() { eventBus.register(GuiHandler.class); } } public class GuiHandler { String text = "Hello world!"; @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { drawString(event.getMatrixStack(), Minecraft.getInstance().font, text, event.getWindow().getWidth() / 2, event.getWindow().getHeight() / 2, Integer.parseInt("33AA66", 16)); } }
  6. @Mod(Main.MODID) //@Mod.EventBusSubscriber(modid = Main.MODID) public class Main{ public static final String MODID = "main"; @SubscribeEvent public static void setup(final FMLCommonSetupEvent event) { System.out.println("I'm setting up!"); MinecraftForge.EVENT_BUS.register(new CapabilityAttatcher()); MagicCapability.register(); } }
  7. Is @EventBusSubscriber what's getting in the way of setup? It didn't work...
  8. I should separate @Mod and @EventBusSubscriber?
  9. @Mod(Main.MODID) @Mod.EventBusSubscriber(modid = Main.MODID) public class Main{ public static final String MODID = "main"; @SubscribeEvent public static void setup(final FMLCommonSetupEvent event) { System.out.println("I'm setting up!"); MinecraftForge.EVENT_BUS.register(new CapabilityAttatcher()); MagicCapability.register(); } }
  10. @Mod(Main.MODID) @Mod.EventBusSubscriber(modid = Main.MODID) public class Main { public static final String MODID = "main"; @SubscribeEvent public static void onServerStarting(FMLServerStartingEvent event) { CommandDispatcher<CommandSource> d = event.getServer().getCommandManager().getDispatcher(); d.register(Commands.literal("tellme").requires(source -> { try { return source.asPlayer() != null; } catch(CommandSyntaxException e) { return false; } }).executes(command -> { ServerPlayerEntity player = command.getSource().asPlayer(); System.out.println(player.getCapability(MagicCape.MAGIC).orElse(null) == null); return 1; })); I see that @SubscribeEvent setup() is not called at all.
  11. When I asked console: System.out.println(player.getCapability(MagicCapability.MAGIC).orElse(null) == null); "true" What did I do or not do, that made this capability not loaded? Please point it out. I have no clue. public static void setup (final FMLCommonSetupEvent event){ MinecraftForge.EVENT_BUS.register(new Fool()); MagicCapability.register(); } public class MagicCapability { @CapabilityInject(IMaxMP.class) public static Capability<IMaxMP> MAGIC = null; public static void register() { CapabilityManager.INSTANCE.register(IMaxMP.class, new IStorage<IMaxMP>() { @Override public INBT writeNBT(Capability<IMaxMP> capability, IMaxMP instance, Direction side) { return IntNBT.valueOf(instance.getManaStored()); } @Override public void readNBT(Capability<IMaxMP> capability, IMaxMP instance, Direction side, INBT nbt) { ((MaxMP)instance).addMana(((IntNBT)nbt).getInt()); } }, () -> new MaxMP(null)); } } public interface IMaxMP { public int getManaStored(); public void addMana(int amount); public void setMana(int amount); public boolean useMana(int amount); public int getMaxMana(); public void addMaxMana(int amount); public void setMaxMana(int amount); } public class Fool { @SubscribeEvent public void attatchCapability(AttachCapabilitiesEvent <Entity> event) { ServerPlayerEntity player; if (event.getObject() instanceof ServerPlayerEntity) { player = (ServerPlayerEntity) event.getObject(); } else { return; } LazyOptional<IMaxMP> optPlayer = player.getCapability(MagicCape.MAGIC); if (!optPlayer.isPresent()) { event.addCapability(new ResourceLocation(Chants.MODID, "magic_capability"), new Maou(player)); } } } public class Maou implements ICapabilityProvider, ICapabilitySerializable<CompoundNBT> { IMaxMP storage; public Maou (ServerPlayerEntity serverPlayerEntity) { storage = new MaxMP(serverPlayerEntity); } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == MagicCape.MAGIC) return (LazyOptional<T>) LazyOptional.of(() -> storage); return LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { CompoundNBT ret = new CompoundNBT(); ret.putInt("magicStored", storage.getManaStored()); return ret; } @Override public void deserializeNBT(CompoundNBT nbt) { int magic = nbt.getInt("magicStored"); storage.addMana(magic); } }
  12. I have a capability STATE_CAPABILITY in IHaveMana, of class IState. I want to take out the IState an entity has, probably using getCapability. As below. But, I couldn't find a way to convert LazyOptional<IState> to IState. @Nullable public static IState getIStates(Entity entityliving) { if (entityliving instanceof LivingEntity) return (IState) entityliving.getCapability(IHaveMana.STATE_CAPABILITY, null).cast(); return null; } Should I give more detail?
  13. It works! It works! public static void onPlayerTick(TickEvent.PlayerTickEvent event){ if (event.phase != Phase.START || event.player == null) return; if (!event.player.world.isRemote) { PlayerEntity player = event.player; Vector3d v3 = player.getLook(1); SmallFireballEntity fireball = new SmallFireballEntity(player.getEntityWorld(), player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ(), v3.x, v3.y, v3.z); fireball.setShooter(player); player.getEntityWorld().addEntity(fireball); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.