Advanced help with MCreator!

Started by Yolo_ on Mon, 06/27/2022 - 14:32

Topic category: Advanced modding

Last seen on 09:28, 6. Aug 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Advanced help with MCreator!
Mon, 06/27/2022 - 14:32

BEFORE YOU REPLY

I searched for it and i really guys i didn't see anything useful

so i hope someone pro at MCreator coding or even the moderators help me at that

The Problem:

I made a block like juke box but it have GUI that have slot 0 it plays the music when i put the music disc in it all of that is done in Procedures but the problem here is...

i need this work with other music discs from other mods 

not just the vanilla music discs or my discs in the same mod

anyway i made another mod to test and i make a music disc on the mod

so i tried hundred of times on this two mods and nothing happens

The only thing that success is playing a music from another mod is working

but how to edit the code of the procedure to (DETECT!)

a music disc from another mod on slot 0 if that work then the music will play

IF YOU WANT ME TO EXPLAIN MORE THAN THAT TELL ME 

At the end i know there is tag to use but i don't know how to use it on something like that

 

 

here's the old topic that was talking about something like this but its not important!

Instead of checking for a…
Wed, 06/29/2022 - 22:31

Instead of checking for a spceific item, check if the given item is an instance of the Music disc item class (ReocrdItem in 1.18.2). Another solution is to use a custom tag, but both require custom coding though.

Last seen on 09:28, 6. Aug 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
thats what i talking about i…
Fri, 07/01/2022 - 13:06

thats what i talking about i said a pro coder that can tell me how to do that

Last seen on 02:47, 17. Jul 2022
Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So, as it turns out,…
Mon, 07/04/2022 - 06:40

So, as it turns out, minecraft actually has a common tag for music discs. To add onto what Goldorion was saying - I will give you my idea of how I would go about this:

Below is the generated code from a procedure block containing "player left clicks on block trigger -> play sound at x,y,z". I have highighted certain sections so that I can reference them easily in my explainations:

Section A will be your trigger and conditional statements - this would be more easily done in the procedure editor. For your purposes, you would have the trigger be "on block right clicked" for the juke box, and under it add the following conditional statement:

if (is [Get a copy of item from slot {0} of block at {x} {y} {z} if it has inventory] tagged in item tags as "minecraft:music_discs"

    OR

    is [Get a copy of item from slot {0} of block at {x} {y} {z} if it has inventory] tagged in item tags as "forge:music_discs") do

within the if-do block, put a "play sound at x,y,z" block (I have set the sound to music_disc.mall)

Section B will contain the rest of the logic - after the code for the tag checks and before the play sound calls, assign a String variable to the following block of code with:

String anyName =

((new Object() {
                        public ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slotid) {
                            AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
                            BlockEntity _ent = world.getBlockEntity(pos);
                            if (_ent != null)
                                _ent.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)
                                        .ifPresent(capability -> _retval.set(capability.getStackInSlot(slotid).copy()));
                            return _retval.get();
                        }
                    }.getItemStack(world, new BlockPos(x, y, z), 0)).getDisplayName().getString().toLowerCase());

This should assign the new variable anyName to the display name of the item in slot 0 of the blocks inventory and makes it lowercase. All you need to do now is to use string concatenation in both of the fields underlined by "C". It will look something like this:

ResourceLocation("music_disc." + anyName)

code

SOME NOTES ABOUT USING THIS METHOD:

This will asuume that the mod author has added their disc to tags in the forge or minecraft namespace and has registered the sound event via forge registries. To extend the functionality to the mod's namespace, you might be able to call the getNameSpace() on the item's resourceLocation prior to the if statement, and use string concatentation similarly to fill in "namespace" + ":music_discs" when checking if the item is tagged as a music disc.

Also, I have only recently starting to learn Java, and have only been using C for the past 6-7 months so there will definitely be wiggle room in the logic and syntax department of the method I have come up with aha