Jump to content

Angercraft

Members
  • Posts

    35
  • Joined

  • Last visited

Posts posted by Angercraft

  1. I've increased the amount of damage the player does, but this results in the damage indicator particles spawning in very large numbers.

    Any ideas on how I can reduce the number of these particles spawned? They're spawned in the PlayerEntity#attackTargetEntityWithCurrentItem line 1209.

    Only way I can think of is modifying the base class, but that is a bad idea.

  2. 17 hours ago, Draco18s said:

    I think you mean Vanilla. Forge does almost nothing to the save system, except provide hooks for mod-added content (including capabilities).

    Dunno.

    Yeah I meant the capabilities.

     

    So no argument against using, for example MongoDB, to persist data?

  3. I'm just curious, I've seen some few places, people trying to use databases such as MySQL to persist data for their mods.

    I know forge already has systems to save data, but would there be a use case, in which you can argue for using a database?

     

    From wow private servers I always see the data for items, creatures, and so on saved in a MySQL table, mongodb or something similar.

    I'd guess this is because there's a lot of data, in which case, could I argue for using a database, if I have a lot of data to save, for example about players?

    Just curious, and for now the normal systems are great, but for future reference, I would like to know if it is a bad idea to use 3rd party databases, to not make that mistake.

     

    Thanks in advance!

  4. 31 minutes ago, diesieben07 said:
    • You should make timeUntilNextMusic final.
    • That's not how you handle exceptions. Ever.
    • The proper way to stop the vanilla music from playing would be PlaySoundEvent.

    Yeah, sorry about the exception, I know about that one, but when just testing I don't worry too much about them.

    Thank you for the help, I still need to figure out how to check if my custom track is done playing.

  5. Alright, got it all to work, and so far I've got a hacky solution to stop the normal music from playing.

    But how would I go about detecting when the song is done playing? As I need to return the timeUntilNextMusic to its normal value.

     

    private static Field timeUntilNextMusic = null;
    
        public static void playTrack() {
            Minecraft mc = Minecraft.getInstance();
            MusicTicker musicTicker = mc.getMusicTicker();
            if(timeUntilNextMusic == null) {
                timeUntilNextMusic = ObfuscationReflectionHelper.findField(MusicTicker.class, "field_147676_d");
            }
            musicTicker.stop();
            try {
                timeUntilNextMusic.setInt(musicTicker, 10000);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            mc.player.playSound(PostCreditsMusic.sound, 1.0F, 1.0F);
        }

     

  6. 58 minutes ago, diesieben07 said:
    • Don't store a static reference to Minecraft.
    • SoundEvent is a registry entry, it must be registered like all other registry entries. It must also not be created in a static initializer.
    • Look at MusicTicker. You'll have to hack around it's internals to make it stop playing music.

    Thank you for your help.

    Regarding the SoundEvent, will the following be good manners, or should it be registered differently?

    public static SoundEvent sound;
    
    @SubscribeEvent
    public void registerMusic(RegistryEvent.Register<SoundEvent> event) {
          sound = new SoundEvent(new ResourceLocation(PostCreditsMusic.MOD_ID, "track"));
          event.getRegistry().register(sound);
    }

     

  7. I'm trying to play a custom piece of music, but would like to not have the background music from the game play, whilst my track is playing.

    I would like for other sounds, such as mob sounds, doors, and all other sounds than music to still play.

    As seen below, I tried using the soundhandler, but this doesn't seem to pause the sounds, whilst I play my own track.

    Any ideas for how I can pause only the background music, only while my own track is playing?

     

    import angercraft.postcreditsmusic.PostCreditsMusic;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.SoundHandler;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.SoundEvent;
    
    public class ClientHandler {
    
         static Minecraft mc = Minecraft.getInstance();
         static SoundEvent sound = new SoundEvent(new ResourceLocation(PostCreditsMusic.MOD_ID, "track"));
    
        public static void playTrack() {
            SoundHandler soundHandler = mc.getSoundHandler();
            soundHandler.pause();
            mc.player.playSound(sound, 1.0F, 1.0F);
        }
    }

     

  8. 5 hours ago, Animefan8888 said:

    What version of forge do you have? Is it really old, have you tried updating?

    I'm using the recommended 1.14.4 - 28.1.0.

    I just tried with the latest 1.14.4 - 28.1.17, and the problem seems to be fixed now.

    It probably fixed it, by reimporting the Gradle project, so I will keep that in mind next time.

     

    Thank you for your help!

  9. @Mod.EventBusSubscriber(modid = Reference.MOD_ID)
    public class Eventlistener {
    
        @SubscribeEvent
        public static void onRenderGui(GuiOpenEvent event) {
            if(event.getGui() instanceof EditSignScreen) {
                if(Keybinds.noSignGui.isKeyDown()) {
                    event.setCanceled(true);
                }
            }
        }
        
        @SubscribeEvent
        public static void onRightClickEmpty(PlayerInteractEvent.RightClickEmpty event) {
            System.out.println("Empty event");
        }
    
        @SubscribeEvent
        public static void onRightClicked(PlayerInteractEvent.RightClickBlock event) {
            System.out.println("Right click block");
        }
    }

     

    The first method onRenderGui(GuiOpenEvent event) does trigger correctly, but I cannot seem to get the other two to trigger, no matter what I do.

    I tried having it as an object method and registrering it manually, I've tried registering the class with static methods manually, and I've tried the above.

  10. 6 minutes ago, Animefan8888 said:

    Once you're done rendering you need to bind the ICONS resource because it expects it.

    Fantastic, thank you so much for the help.

    If you have time, could you answer what the best way is to disable the rendering of the original healthbar?

    Right now I use the event to check if the ElementType is of HEALTH, as can be seen in RPGHUD.java above.

     

    But I can see you can set

    GuiIngameForge.renderHealth = false;

    which I tried in my FMLPostInitializationEvent for the client side, and this seems to work. But does one of them have a downside, which should deter me from using them?

  11. I'm trying various things whilst modding and thought it would be fun to create a new health bar, like the one found in Diablo 2.

     

    https://imgur.com/a/Glwv8pZ

     

    The problem is the food bar doesn't render it's textures.

     

    Both the code for the Gui class, which is what seems to be breaking the food bar when calling renderHealthBar(), and the code from where I call the method is found below.

     

    GuiRPGHealth.java

    Spoiler
    
    public class GuiRPGHealth extends Gui {
    
        private static final Minecraft mc = Minecraft.getMinecraft();
    
        private final int healthGlobeWidth = 60;
        private final int healthGlobeHeight = 60;
    
        private static final ResourceLocation GUI_RESOURCES = new ResourceLocation(Reference.MOD_ID, "textures/gui/hud/health_globe.png");
    
        public void renderHealthBar() {
    
            EntityPlayerSP player = mc.player;
    
            float healthMax = player.getMaxHealth();
            float healthCurr = player.getHealth();
            float healthPercent = healthCurr/healthMax;
    
            ScaledResolution scaledResolution = new ScaledResolution(mc);
    
            int containerCornerX = 20;
            int containerCornerY = scaledResolution.getScaledHeight()-healthGlobeHeight-20;
    
            mc.getTextureManager().bindTexture(GUI_RESOURCES);
    
            GlStateManager.enableBlend();
    
            this.drawTexturedModalRect(containerCornerX, containerCornerY, 60, 0, healthGlobeWidth, healthGlobeHeight);
    
            int offset = (int) (healthGlobeHeight-(healthGlobeHeight*healthPercent));
    
            this.drawTexturedModalRect(containerCornerX, containerCornerY + offset, 0, offset, healthGlobeWidth, (int) (healthGlobeHeight*healthPercent)+1);
    
            GlStateManager.disableBlend();
    
            String healthText = (int)healthCurr+"/"+(int)healthMax;
    
            GL11.glPushMatrix();
            GL11.glScalef(1.2f, 1.2f, 1.2f);
            this.drawCenteredString(mc.fontRenderer, healthText, containerCornerX + healthGlobeWidth/2, containerCornerY + healthGlobeHeight/2-mc.fontRenderer.FONT_HEIGHT, 0xffffffff);
            GL11.glPopMatrix();
        }
    }

     

    RPGHud.java

    Spoiler
    
    public class RPGHud extends Gui {
    
        private static GuiRPGHealth guiRPGHealth = new GuiRPGHealth();
    
        private static void renderRPGHud(float partialTicks) {
            guiRPGHealth.renderHealthBar();
        }
    
        @SubscribeEvent
        public static void afterRenderGui(RenderGameOverlayEvent.Post event) {
            renderRPGHud(event.getPartialTicks());
        }
    
        @SubscribeEvent
        public static void onRenderGui(RenderGameOverlayEvent.Pre event) {
            if(event.getType() == RenderGameOverlayEvent.ElementType.HEALTH) {
                event.setCanceled(true);
            }
        }
    }

     

     

    And the RPGHud is registered on the event bus, on the client side.

     

    Thank you in advance!

  12. Okay, I've tried various things, and the only thing I got to work was the following:

     

    private static Minecraft minecraft = Minecraft.getMinecraft();
    private static Method renderFire1st = ObfuscationReflectionHelper.findMethod(ItemRenderer.class, "func_78442_d", void.class);
    
    @SubscribeEvent
    public static void renderFirstPersonEffect(RenderHandEvent event) {
        if(minecraft.gameSettings.thirdPersonView == 0) {
            if (!net.minecraftforge.event.ForgeEventFactory.renderFireOverlay(minecraft.player, event.getPartialTicks())) {
                try {
                    renderFire1st.invoke(minecraft.getItemRenderer());
                } catch (IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
    }

     

    But this seems like a hacky solution, and I would like to know if I should use an alternative way to do this. Maybe another event to subscribe to.

  13. I've found the method 

    ItemRenderer#renderFireInFirstPerson()

    and using reflection I can use it, but the fire is not actually shown on the screen.

     

    Should I use a different way to render the fire?

     

    This is what I have done so far:

    private static Minecraft minecraft = Minecraft.getMinecraft();
    private static Method renderFire1st = ObfuscationReflectionHelper.findMethod(minecraft.getItemRenderer().getClass(), "func_78442_d", void.class);
    
    @SubscribeEvent
    public static void renderEffect(RenderLivingEvent.Post event) {
        try {
            if (!net.minecraftforge.event.ForgeEventFactory.renderFireOverlay(minecraft.player, event.getPartialRenderTick()))
                    renderFire1st.invoke(minecraft.getItemRenderer());
        } catch (IllegalAccessException | InvocationTargetException e) {
                System.out.println("Forge was not present.");
        }
    }

     

    Thank you in advance!

  14. On 6/24/2019 at 10:18 PM, diesieben07 said:

    Subscribe to RenderLivingEvent.Post. If you want the entity to render on fire, call Render#renderEntityOnFire on the entity (you'll need reflection).

    Okay I've gotten it to work, thank you very much! Now I don't have much experience with reflection in Java as it is not covered in my university, but I've read about it and would just like to know if this is considered good practice.

     

    @SubscribeEvent
        @SideOnly(Side.CLIENT)
        public static void renderEffect(RenderLivingEvent.Post event) {
            if(affected.contains(event.getEntity())) {
                Class c = Render.class;
                try {
                    Method method = c.getDeclaredMethod("renderEntityOnFire", Entity.class, double.class, double.class, double.class, float.class);
                    method.setAccessible(true);
                    method.invoke(event.getRenderer(), event.getEntity(), event.getX(), event.getY(), event.getZ(), event.getPartialRenderTick());
                } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                    System.out.println("Forge was not present, or method name 'renderEntityOnFire' was changed.");
                }
            }
        }

     

    I know the exception handling is not proper, but I would like to know if I've handled the reflection properly?

  15. I've seen loads of examples and looked at the documentation found here but I just can't figure out how to play a sound with this.

     

    To test with, I've tried the following:

    @SubscribeEvent
        public static void brokeBlock(BlockEvent.BreakEvent event) {
            double x = event.getPlayer().posX;
            double y = event.getPlayer().posY;
            double z = event.getPlayer().posZ;
            event.getWorld().playSound(null, x,y,z, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F);

    Which may not trigger on both sides, and if not, how would I go about triggering this on both sides?

     

    My final goal is having the extinguish sound effect play with certain conditions, but for now I would be happy just getting any sound to play...

     

    Thank you in advance!

     

    EDIT:

     

    Apparently the above works, somehow the changes just didn't make it into the game, until after I restarted...

  16. 19 hours ago, Cadiboo said:

    If you want them in your developer environment put them in ./libs or use maven. If you want them packaged with your mod in a production environment use forges jar-in-jar system

    How do you do this? I tried reading the guide at https://mcforge.readthedocs.io/en/latest/gettingstarted/dependencymanagement/ but I can't really figure it out.

    It says we have to drop the jar into our own jar, but where should we place it?

    The ContainedDeps manifest attribute should hold a list of our .jar dependencies, but should we manually add this to our builded mods manifest, inside the mod jar, or how do we handle this?

     

    Thank you in advance!

  17. I tried a bit, both with a maven repository as a dependency, but also using a jdbc jar file in the root of the file, and it seems that neither of those solutions build the mod with the dependency included. I'm not sure how to solve this and perhaps someone else have a solution, as I couldn't find anyone with quite the same problem as you.

    • Like 1
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.