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

e2rifia

Members
  • Posts

    28
  • Joined

  • Last visited

Everything posted by e2rifia

  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); } }
  14. One step ahead? @SubscribeEvent public void clientTickEnd(TickEvent.PlayerTickEvent event){ if (event.phase != Phase.START || event.player == null) return; 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); } Should I move it out of @EventBusSubscriber to somewhere else?
  15. I fiddled around, trying to somehow get onPlayerTick to do something. This is when I tried to make my head a flamethrower, but it doesn't spawn fireballs. What did I do wrong? Please point it out. @Mod(the class below) @Mod.EventBusSubscriber(modid = the class below) a public class { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) 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); }
  16. Is (LazyOptional)instance better?
  17. LazyOptional<T> is used for a return value. How can I cast the output to LazyOptional? public class IHaveMana implements ICapabilitySerializable<INBT> { @CapabilityInject(IState.class) public static final Capability<IState> STATE_CAPABILITY = null; private IState instance = STATE_CAPABILITY.getDefaultInstance(); @Override public <T> LazyOptional<T> getCapability(Capability<T> capability, Direction side) { return capability == STATE_CAPABILITY ? STATE_CAPABILITY.<T>cast(this.instance) : null; //this part. } //override, override, override... }
  18. I tried to follow this page to create a capability. https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ This is what I have so far. NBTBase and EnumFacing are not found to be imported. If they are out of date, what should I use instead? import com.e2rifia.chants.util.IState; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; public class IHaveMana implements ICapabilitySerializable<NBTBase> { @CapabilityInject(IState.class) public static final Capability<IState> STATE_CAPABILITY = null; private IState instance = STATE_CAPABILITY.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == STATE_CAPABILITY; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == STATE_CAPABILITY ? STATE_CAPABILITY.<T>cast(this.instance) : null; } @Override public NBTBase serializeNBT() { return STATE_CAPABILITY.getStorage().writeNBT(STATE_CAPABILITY, this.instance, null); } @Override public void deserializeNBT(NBTBase nbt) { STATE_CAPABILITY.getStorage().readNBT(STATE_CAPABILITY, this.instance, null, nbt); }
  19. I want to use enum Keyboard.KEY. I want to achieve making a new KeyBinding. as: keybindTeleport = new KeyBinding("Teleport", Keyboard.KEY_X, "Teleports");
  20. lwjgl didn't have input.Keyboard. Did it change to something else?
  21. Nevermind, adding this below addVelocity made it work. Sorry to interrupt! player.velocityChanged = true;
  22. I want the player to move a bit to where it's looking at. ServerPlayerEntity player = command.getSource().asPlayer(); Vector3d v3 = player.getLookVec(); player.addPotionEffect(new EffectInstance(Effect.get(25), 13)); player.addVelocity(v3.x, v3.y, v3.z); return 1; addVelocity() didn't work. How do I use this?
×
×
  • Create New...

Important Information

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