Jump to content

Recommended Posts

Posted
33 minutes ago, fuzzybat23 said:

Oh, the full path as it appears in the config.cfg file, then?

 

Yes.

 

17 minutes ago, fuzzybat23 said:

Ok... I did something and I have no idea what, but the game crashes as Forge begins to load.  It generates the cfg file, but it's blank.

 


net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Custom Selection Box Revised (csbr)
Caused by: net.minecraftforge.fml.common.LoaderException: java.lang.RuntimeException: Error syncing field 'Red' of class 'com.fuzzybat23.csbr.ModConfig$Frame'!
	at net.minecraftforge.common.config.ConfigManager.sync(ConfigManager.java:192)
	at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:609)
	...
Caused by: java.lang.RuntimeException: Error syncing field 'Red' of class 'com.fuzzybat23.csbr.ModConfig$Frame'!
	...
Caused by: java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 8
general.1) custom selection box frame.
        ^
	at java.util.regex.Pattern.error(Pattern.java:1955)
	at java.util.regex.Pattern.compile(Pattern.java:1700)
	at java.util.regex.Pattern.<init>(Pattern.java:1351)
	at java.util.regex.Pattern.compile(Pattern.java:1028)
	at java.lang.String.replaceFirst(String.java:2178)
	at net.minecraftforge.common.config.ConfigManager.sync(ConfigManager.java:252)
	... 45 more

 

Forge uses your category names in a regular expression (for String#replaceFirst), so they can't contain any characters that have a special meaning in regular expressions (e.g parentheses).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

BAsically, those first @Name calls only name the buttons.  I was thinking I could use the 1) 2) and 3) to sort them properly on the screen.  Instead I'll have to just alphabetize the frameRender, blinkAnimation and breakAnimation

Posted

Well, whatever it was I did with those (), that was keeping the cycle string box from saving.  Everything in my config file saves as it should, now.  Weird.  Anyway,

 

        ConfigCategory cat = config.getCategory("general.aFrame");
        Property prop = cat.get("Red");

 

for getting the category and prop, right, if the ModConfig is structured as so

 

@Config(modid = CSBR.MODID)
@LangKey("csbr.config.title")
public class ModConfig
{
    @Name("Custom Selection Box Frame")
    @Comment("Color and opacity for custom selection box wire frame.")
    public static final Frame aFrame = new Frame();

    @Name("Custom Selection Box Cube")
    @Comment("Color and opacity for custom selection box inner cube.")
    public static final BlinkAnimation bBlink = new BlinkAnimation();

    @Name("Custom Selection Box Animation")
    @Comment({"Break animation style and toggle the depth", "buffer for the custom selection box wire frame.."})
    public static final BreakAnimation cBreak = new BreakAnimation();

    public static class Frame
    {
        @Name("1) Red")
        @Comment("Choose a value for red between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Red = 255;

        @Name("2) Green")
        @Comment("Choose a value for green between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Green = 255;

        @Name("3) Blue")
        @Comment("Choose a value for blue between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Blue = 255;

        @Name("4) Alpha Channel")
        @Comment("Choose a value for the opacity between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Alpha = 255;

        @Name("5) Wire Thickness")
        @Comment("Choose a value for the wire frame thickness between 1 and 7.")
        @RangeInt(min = 1, max = 7)
        public int Width = 2;
    }

    public static class BlinkAnimation
    {
        @Name("1) Red")
        @Comment("Choose a value for red between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Red = 255;

        @Name("2) Green")
        @Comment("Choose a value for green between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Green = 255;

        @Name("3) Blue")
        @Comment("Choose a value for blue between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Blue = 255;

        @Name("4) Alpha Channel")
        @Comment("Choose a value for the opacity between 0 and 255.")
        @RangeInt(min = 0, max = 255)
        public int Alpha = 255;
    }

    public static class BreakAnimation
    {
        @Name("2) Break Animation")
        @Comment("Break Animation")
        public enumAnimation animation = enumAnimation.NONE;

        @Name("2) Blink Animation Speed")
        @Comment("Choose how fast the custom selection box blinks.")
        @RangeInt(min = 0, max = 100)
        public int Speed = 0;

        @Name("3) Depth Buffer")
        @Comment("Enable or disable the depth buffer for the custom selection box wire frame.")
        public boolean dBuffer = false;

        public enum enumAnimation
        {
            NONE,
            SHRINK,
            DOWN,
            ALPHA
        }
    }

 

Posted
30 minutes ago, fuzzybat23 said:

Weird.  Anyway,

 


        ConfigCategory cat = config.getCategory("general.aFrame");
        Property prop = cat.get("Red");

 

for getting the category and prop, right, if the ModConfig is structured as so

 

That looks correct, yes.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

And if I want all the props in aFrame to have the slider, I'd need to set it up more like this, right?

 

	ConfigCategory cat = config.getCategory("general.aFrame");
	Property propRed = cat.get("Red");
	Property propGreen = cat.get("Green");
	Property propBlue = cat.get("Blue");
	Property propAlpha = cat.get("Alpha");
	Property propWidth = cat.get("Width");

 

Posted
2 minutes ago, fuzzybat23 said:

Now that we have the prop, how do we set NumberSliderEntry as its config GUI entry type?

 

Call Property#setConfigEntryClass with NumberSliderEntry.class as the argument.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
1 minute ago, fuzzybat23 said:

And if I want all the props in aFrame to have the slider, I'd need to set it up more like this, right?

 


	ConfigCategory cat = config.getCategory("general.aFrame");
	Property propRed = cat.get("Red");
	Property propGreen = cat.get("Green");
	Property propBlue = cat.get("Blue");
	Property propAlpha = cat.get("Alpha");
	Property propWidth = cat.get("Width");

 

You'll need to call Property#setConfigEntryClass on each of those Property objects, yes.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I'm going to try to get a little fancy here.  Like this, right?

        ConfigCategory cat = config.getCategory("general.aFrame");
        Property propaFrame[] = new Property[5];
        propaFrame[0] = cat.get("Red");
        propaFrame[1] = cat.get("Green");
        propaFrame[2] = cat.get("Blue");
        propaFrame[3] = cat.get("Alpha");
        propaFrame[4] = cat.get("Width");

        for(Property p:propaFrame)
        {
            p.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

Posted (edited)
8 minutes ago, fuzzybat23 said:

I'm going to try to get a little fancy here.  Like this, right?


        ConfigCategory cat = config.getCategory("general.aFrame");
        Property propaFrame[] = new Property[5];
        propaFrame[0] = cat.get("Red");
        propaFrame[1] = cat.get("Green");
        propaFrame[2] = cat.get("Blue");
        propaFrame[3] = cat.get("Alpha");
        propaFrame[4] = cat.get("Width");

        for(Property p:propaFrame)
        {
            p.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

 

That should work, yes. You can also use ConfigCategory#getValues to get an immutable copy of the category's property names and properties (and use Map#getValues to get a collection of the Map's values) or ConfigCategory#getOrderedValues to get an ordered immutable copy of the category's properties.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I don't have much experience with the immutable..  Something like this?

 

        List<Property> props = new ArrayList<Property>(cat.getOrderedValues());
        for(Property p:props)
        {
            p.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

Posted
Just now, fuzzybat23 said:

I don't have much experience with the immutable..  Something like this?

 


        List<Property> props = new ArrayList<Property>(cat.getOrderedValues());
        for(Property p:props)
        {
            p.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

 

You don't need to create a new List, ConfigCategory#getOrderedValues already returns a List; just iterate through it directly.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

I don't suppose there's a way to get a block at the bottom, under Wire Thickness, that will change colors according to the slider values? ;D  Kind of like the chat color picker.  In that case, I'd probably drop the red green blue entirely and just go with the basic, what is it.. 16 colors that Minecraft uses?  Either way, this is exactly what I was looking for.  Thanks!  More in depth tutorials on the @config system need to me made for this reason xD 

 

I did find the source for that, too.  I guess if I went that route, it would be a cycle value button instead of a number slider.  The number slider would still be used for the animation speed, frame thickness and alpha channels, though.

 

 

/**
 * ChatColorEntry
 *
 * Provides a GuiButton that cycles through the list of chat color codes.
 */
public static class ChatColorEntry extends CycleValueEntry
{
    ChatColorEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement)
    {
        super(owningScreen, owningEntryList, configElement);
        this.btnValue.enabled = enabled();
        updateValueButtonText();
    }

    @Override
    public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partial)
    {
        this.btnValue.packedFGColour = GuiUtils.getColorCode(this.configElement.getValidValues()[currentIndex].charAt(0), true);
        super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partial);
    }

    @Override
    public void updateValueButtonText()
    {
        this.btnValue.displayString = I18n.format(configElement.getValidValues()[currentIndex]) + " - " + I18n.format("fml.configgui.sampletext");
    }
}

Capture.JPG

Edited by fuzzybat23
Posted
48 minutes ago, fuzzybat23 said:

I think I see.


        for(int i = 0; i < cat.getOrderedValues().size(); i++)
        {
            cat.getOrderedValues().get(i).setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

Why are you using an indexed for loop? Use a for-each/enhanced for loop like you were before, but iterate through the returned List directly instead of creating a new one.

 

Each call to ConfigCategory#getOrderedValues creates a new copy of the List, so you should call it once and store the result in a local variable rather than calling it every iteration of the loop.

 

 

33 minutes ago, fuzzybat23 said:

I don't suppose there's a way to get a block at the bottom, under Wire Thickness, that will change colors according to the slider values? ;D

 

You'd need to implement this yourself, I can't really help you with much GUI-related stuff. Using ChatColorEntry is probably easier.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

It didn't work before xD  I just tried this again and tested it and it does seem to work.  Little cleaner looking, too, I think.

        for(Property p: cat.getOrderedValues())
        {
            p.setConfigEntryClass(GuiConfigEntries.NumberSliderEntry.class);
        }

 

Anyway, yeah, I was thinking about ChatColorEntry too.  I tried to test it with the enum I already had setup.

 ConfigCategory cat2 = config.getCategory("general.custom selection box animation");
 Property prop = cat2.get("animation");
 prop.setConfigEntryClass(GuiConfigEntries.ChatColorEntry.class);

 

but all that did was throw an error.

Time: 7/15/17 9:23 AM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Custom Selection Box Revised (csbr)
Caused by: java.lang.NullPointerException
	at com.fuzzybat23.csbr.CSBR.preInit(CSBR.java:82)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:630)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:252)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:230)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:266)
	at net.minecraft.client.Minecraft.init(Minecraft.java:508)
	at net.minecraft.client.Minecraft.run(Minecraft.java:416)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
	Minecraft Version: 1.12
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_131, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 891752248 bytes (850 MB) / 1135607808 bytes (1083 MB) up to 3808428032 bytes (3632 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.40 Powered by Forge 14.21.1.2387 6 mods loaded, 6 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCH	minecraft{1.12} [Minecraft] (minecraft.jar) 
	UCH	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCH	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.12-14.21.1.2387.jar) 
	UCH	forge{14.21.1.2387} [Minecraft Forge] (forgeSrc-1.12-14.21.1.2387.jar) 
	UCE	csbr{1.0} [Custom Selection Box Revised] (CSBR_main) 
	UCH	squeedometer{1.0.3} [Squeedometer] (Squeedometer-mc1.12.x-1.0.3.jar) 
	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 384.76' Renderer: 'GeForce GTX 770/PCIe/SSE2'
[09:23:11] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: #@!@# Game crashed! Crash report saved to: #@!@# E:\Users\RigAlpha\Documents\My Projects\Minecraft\Git\CSBR\run\.\crash-reports\crash-2017-07-15_09.23.11-client.txt

Process finished with exit code -1

 

Posted (edited)

Instead of an Enum, I should instead use an array

@Name("2) Break Animation")
@Comment("Break Animation")
public String[] animation = new String[] {"NONE", "SHRINK", "DOWN", "ALPHA"};

 

and use GuiConfigEntries.ChatColorEntry.class on that?

Edited by fuzzybat23
Posted (edited)
1 hour ago, fuzzybat23 said:

Caused by: java.lang.NullPointerException

at com.fuzzybat23.csbr.CSBR.preInit(CSBR.java:82)

 

Something was null on line 82 of CSBR (in the preInit method). If line 82 is the Property#setConfigEntryClass call, the Property is null. This is probably because you renamed it with @Config.Name, so it's not called animation.

 

1 hour ago, fuzzybat23 said:

Instead of an Enum, I should instead use an array


@Name("2) Break Animation")
@Comment("Break Animation")
public String[] animation = new String[] {"NONE", "SHRINK", "DOWN", "ALPHA"};

 

and use GuiConfigEntries.ChatColorEntry.class on that?

 

No. You want a single value chosen from a fixed set, so use an enum. If you wanted an arbitrary number of Strings, you'd use a String array.

 

 

I've just discovered that Property#setConfigEntryClass doesn't actually work with GuiConfigEntries.ChatColorEntry because the constructor isn't public. I'll report this shortly, so hopefully it will be fixed.

 

I've reported this here.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Well crap, this was doomed to failure from the start then xD  Hope they do get that fixed soon.  For now, I'll just keep it in the rgb slider system.  Now I need to plug in the main guts of my mod to test it out fully.  Thanks again :>  Hopefully this thread will help out anyone else looking up the annotation system.  There really should be a section in Docs detailing everything that the annotation @Config system can do.  Doesn't make sense to introduce a powerful and simple modding tool and not tell anyone about it :P

Posted

Oh yeah!  There was one other thing I just thought of.  With the enum control (None, shrink, down, alpha)  If any but NONE are selected, how can I force it to set DepthBuffer boolean to true in real time.  Say, the cycle button is on NONE by default.  You click it to SHRINK and the button for Depth Buffer immediately greens with true being set.

Caputure 1.JPG

Capture 2.JPG

Posted
9 hours ago, fuzzybat23 said:

There really should be a section in Docs detailing everything that the annotation @Config system can do.  Doesn't make sense to introduce a powerful and simple modding tool and not tell anyone about it :P

 

Forge is documented by the community, you can submit a Pull Request here to add/modify documentation.

 

 

9 hours ago, fuzzybat23 said:

If any but NONE are selected, how can I force it to set DepthBuffer boolean to true in real time.  Say, the cycle button is on NONE by default.  You click it to SHRINK and the button for Depth Buffer immediately greens with true being set.

 

I think you'd need to make your own IConfigEntry for this.

 

If the Depth Buffer setting is solely controlled by the Break Animation setting, is there any reason to have it user-configurable at all?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Depth Buffer turned off essentially lets you see the entire wireframe through the block itself.  It's kind of a neat effect.  Sometimes i use it with no break animation set.  So what would this IConfigEntry look like?

Posted
6 minutes ago, fuzzybat23 said:

So what would this IConfigEntry look like?

 

You could copy CycleValueEntry (since you can't extend it) and override CycleValueEntry#valueButtonPressed and CycleValueEntry#setToDefault to call the super methods and then modify the Depth Buffer setting. I'm not sure exactly how you'd do this, you'd need to work this out yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

I suppose that when I load the values from the config file into the variables located in my main class, I could have it set the value of the config file to true if any animation is selected but NONE.  That way, no matter what is picked in the config file, for the depth buffer, it will default to having the depth buffer disabled for those animations.

public class CSBR
{
    public static float Red;
    public static float Green;
    public static float Blue;
    public static float Alpha;
    public static float Width;

    public static float bRed;
    public static float bGreen;
    public static float bBlue;
    public static float bAlpha;
    public static float Speed;

    public static int Animation;
    public static boolean DepthBuffer;

	@Mod.EventHandler
    @SideOnly(Side.CLIENT)
    public void preInit(FMLPreInitializationEvent event) throws InvocationTargetException, IllegalAccessException
    {
        Red = ModConfig.aFrame.Red;
        Green = ModConfig.aFrame.Green;
        Blue = ModConfig.aFrame.Blue;
        Alpha = ModConfig.aFrame.Alpha;
        Width = ModConfig.aFrame.Width;

        bRed = ModConfig.bBlink.Red;
        bGreen = ModConfig.bBlink.Green;
        bBlue = ModConfig.bBlink.Blue;
        bAlpha = ModConfig.bBlink.Alpha;

		ConfigCategory csba = config.getCategory("general.custom selection box animation");
        Property csba_depth_prop = csba.get("3) Depth Buffer");
        switch(ModConfig.cBreak.Animation)
        {
            case NONE:
                Animation = 0;
                break;

            case SHRINK:
			{
                Animation = 1;
				csba_depth_prop.setValue(true);
				break;

            case DOWN:
                Animation = 2;
				csba_depth_prop.setValue(true);
                break;

            case ALPHA:
                Animation = 3;
				csba_depth_prop.setValue(true);
                break;

            default:
                Animation = 0;
        }

        DepthBuffer = ModConfig.cBreak.dBuffer;
        Speed = ModConfig.cBreak.Speed;
}

 

It wouldn't change the state of the Depth Buffer button on the config screen as the animation is picked, but I don't really care about that.  As long as the internal code knows to turn it off if those animations are set is what's important.

Edited by fuzzybat23

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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