Jump to content

Adding and playing custom sounds


PlatonCraft

Recommended Posts

Hello there! I want to add my custom sound to game and then play it. I have .ogg file (vorbis 2.0 codec) in assets.flintstonetools.sound folder in project.

 

 

[spoiler=My Base of mod]

package platon.mods.flintstonetools;

import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetServerHandler;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod (modid = FlintBase.modid, name = "Flintstone Tools", version = "1.1.1a") 
@NetworkMod (clientSideRequired = true, serverSideRequired = false)

public class FlintBase {
public static final String modid = "flintstonetools";
@Instance(FlintBase.modid)
public static FlintBase instance;
public static Item flintpickaxe;
static int flintpickaxeid;
public static Item flintshovel;
static int flintshovelid;
public static Item flintaxe;
static int flintaxeid;
public static Item flinthoe;
static int flinthoeid;
public static Item flintsword;
static int flintswordid;
@EventHandler
public void reg(FMLPreInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new SoundLoader());
}
@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
config.defaultEncoding="windows-1251";
flintpickaxeid = config.get("Mod IDs", "flintpickaxeid", 650).getInt();
flintshovelid = config.get("Mod IDs", "flintshovelid", 651).getInt();
flintaxeid = config.get("Mod IDs", "flintaxeid", 652).getInt();
flinthoeid = config.get("Mod IDs", "flinthoeid", 653).getInt();
flintswordid = config.get("Mod IDs", "flintswordid", 654).getInt();
SetBlockOnFire.fireableids = config.get("flintstonetools", "fireableids", SetBlockOnFire.deffireableids).getIntList();
config.addCustomCategoryComment("flintstonetools", "Here is the list of IDs of blocks that can be setted on fire by the flint pickaxe.\nThat list can be modified. Just add the Ids you want in column.\n\nЗдесь в столбик указаны ID блоков, которые можно поджигать кремневой киркой.\nВы можете изменять его. Просто добавьте свои ID в колонку с новой строки");
config.save();
}
@EventHandler
public void load(FMLInitializationEvent event)
{
flintpickaxe = new ItemFlintPickAxe(flintpickaxeid).setUnlocalizedName("flintpickaxe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintpickaxe, 1), new Object[]{ "XXX", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintpickaxe, "en_US", "Flint Pickaxe");
LanguageRegistry.instance().addNameForObject(flintpickaxe, "ru_RU", "Кремневая Кирка");

flintshovel = new ItemFlintShovel(flintshovelid).setUnlocalizedName("flintshovel");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintshovel, 1), new Object[]{ " X ", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintshovel, "en_US", "Flint Shovel");
LanguageRegistry.instance().addNameForObject(flintshovel, "ru_RU", "Кремневая Лопата");

flintaxe = new ItemFlintAxe(flintaxeid).setUnlocalizedName("flintaxe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintaxe, 1), new Object[]{ " XX", " #X", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintaxe, "en_US", "Flint Axe");
LanguageRegistry.instance().addNameForObject(flintaxe, "ru_RU", "Кремневый Топор");

flinthoe = new ItemFlintHoe(flinthoeid).setUnlocalizedName("flinthoe");
GameRegistry.addRecipe(new ItemStack(FlintBase.flinthoe, 1), new Object[]{ " XX", " # ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flinthoe, "en_US", "Flint Hoe");
LanguageRegistry.instance().addNameForObject(flinthoe, "ru_RU", "Кремневая Мотыга");

flintsword = new ItemFlintSword(flintswordid).setUnlocalizedName("flintsword");
GameRegistry.addRecipe(new ItemStack(FlintBase.flintsword, 1), new Object[]{ " X ", " X ", " # ",
Character.valueOf('X'), Item.flint, ('#'), Item.stick});
LanguageRegistry.instance().addNameForObject(flintsword, "en_US", "Flint Sword");
LanguageRegistry.instance().addNameForObject(flintsword, "ru_RU", "Кремневый Меч");
}
static EnumToolMaterial FLINT = EnumHelper.addToolMaterial("FLINT", 2, 150, 5.0F, 2.0F, 10);
}

 

 

 

[spoiler=SoundLoader]

package platon.mods.flintstonetools;

import net.minecraft.client.audio.SoundManager;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class SoundLoader
{
@ForgeSubscribe
public void onSoundsLoaded(SoundLoadEvent event)
{

event.manager.soundPoolSounds.addSound("flintstonetools/sound/stonestrike.ogg");

}
}

 

 

 

[spoiler=My item i want to play this sound]

package platon.mods.flintstonetools;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.Property;

import java.util.Random;

public class ItemFlintPickAxe extends ItemPickaxe{

public ItemFlintPickAxe(int par1)
{
super(par1,FlintBase.FLINT);
	this.setCreativeTab(CreativeTabs.tabTools);
}
@Override
public void registerIcons(IconRegister reg){
this.itemIcon = reg.registerIcon("flintstonetools:ItemFlintPickAxe");
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{

par3World.playSoundAtEntity(par2EntityPlayer, "flintstonetools.sound.stonestrike", 1.0F, 1.0F);
return true;

}
}

 

 

 

Please help me!!! What should i do to make it work??? Minecraft 1.6.2 Forge 804

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I already tried this and its wasnt work but now i guessed that this is eclipse's problem i compiled my code and put it to minecraft mods folder and all get work but now in eclipse it doesn't works anyway.

When i use my tool, all sounds are disappearing and minecraft writes the error code:

2013-08-18 22:00:04 [iNFO] [sTDERR] Exception in thread "Thread-15" java.lang.NullPointerException
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

In what package in eclipe my sound must to be?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

maybe common package?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

There are tutorials on this, if you have trouble finding them you could try my website (self promoting, I know :P ):

mazetar.com/mctuts/displayTutorials.php

 

For sounds I wrote a tutorial which may aid you:

www.minecraftforum.net/topic/1886370-forge16x-mazs-tutorials-working-custom-sounds-w-random-sound-from-soundpool-190713/

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I already get mod works but not in eclipse. Where must assets/modname/sound directory must to be in eclipse, say please. I would be glad to some screenshot.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I just copied all i need to the src folder which in the mcp's home (where is files recomp and reobf). And it doesn't works and gives me an error described upper

hsWn6OW.png

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I already tried this and its wasnt work but now i guessed that this is eclipse's problem i compiled my code and put it to minecraft mods folder and all get work but now in eclipse it doesn't works anyway.

When i use my tool, all sounds are disappearing and minecraft writes the error code:

2013-08-18 22:00:04 [iNFO] [sTDERR] Exception in thread "Thread-15" java.lang.NullPointerException
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 22:00:04 [iNFO] [sTDERR] 	at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

In what package in eclipe my sound must to be?

Looks like a codec error.

Can you try with a .wav file ?

Link to comment
Share on other sites

If you mean code - yes, all the code here, too. in mcp/src/minecraft

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

@Gotolink

Just another error, and as I said if i compiling mod and put it to minecraft mods folder, all works

 

2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'CodecWav'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Error setting up audio input stream in method 'initialize'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     ERROR MESSAGE:
2013-08-18 23:24:30 [iNFO] [sTDOUT]         Stream closed
2013-08-18 23:24:30 [iNFO] [sTDOUT]     STACK TRACE:
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.getInIfOpen(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.fill(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         java.io.BufferedInputStream.read(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.RIFFReader.read(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.RIFFReader.<init>(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.internal_getAudioFileFormat(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.getAudioFileFormat(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.codecs.CodecWav.initialize(CodecWav.java:128)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-18 23:24:30 [iNFO] [sTDOUT]         paulscode.sound.CommandThread.run(CommandThread.java:121)
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'CodecWav'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Audio input stream null in method 'readAll'
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Sound buffer null in method 'loadSound'
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Source 'sound_29' was not created because an error occurred while loading flintstonetools:stonestrike.wav
2013-08-18 23:24:30 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2013-08-18 23:24:30 [iNFO] [sTDOUT]     Source 'sound_29' not found in method 'play'

 

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

In a sence? I just copied this sound to src. I tried to create package and folder named assets.flintstonetools.sound but the result is same - error

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

YEAH!!! I fixed it. I put the sound in mcp/eclipse folder.

My sound is very bad. I need the sound of flint scratching stone. Can anyone help me with that?

at least give me a link to site with different sounds.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have been working on a complex block for a mod I'm working on. This block is really unfinished right now, but there is this strange bug that is hindering progress. Basically, this block has a single slot where you put a specific item, then there are three "buttons" on the right like the Enchantment Table. Later on these buttons will have a special purpose so don't worry about them, but right now these buttons just increment a new property on the player as long as they have xp levels. The bug is that whenever you click on one of the three buttons, the items you put in are supposed to decrement, but when you take them out or you reopen the block's gui, the item stack mysteriously "resets", meaning that all the items that were consumed are present again. Here is the Block Entity class (do realize that I am developing this mod in IntelliJ IDEA 2024.1.4 Community Edition): package everyblu.ars_mythos.common.block.tiles; import com.github.alexthe666.iceandfire.item.IafItemRegistry; import everyblu.ars_mythos.client.menus.ArcaneScholarsAnalysisMenu; import everyblu.ars_mythos.common.block.ArcaneScholarsBlock; import everyblu.ars_mythos.common.block.ArsMythosBlockStateProperties; import everyblu.ars_mythos.common.registry.ArsMythosObjectRegistry; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.*; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import software.bernie.geckolib.animatable.GeoBlockEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.core.animation.AnimationController; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; public class ArcaneScholarsTile extends BlockEntity implements GeoBlockEntity, WorldlyContainer, MenuProvider { public final String variant; private final NonNullList<ItemStack> items = NonNullList.withSize(1, ItemStack.EMPTY); public ArcaneScholarsTile(BlockPos pPos, BlockState pBlockState) { super(ArsMythosObjectRegistry.NEW_ARCANE_SCHOLARS_TILE.get(), pPos, pBlockState); this.variant = switch (pBlockState.getValue(ArsMythosBlockStateProperties.ARCANE_SCHOLARS_VARIANT)) { case 1 -> "fire"; case 2 -> "ice"; default -> "lightning"; }; } @Override public void load(@NotNull CompoundTag tag) { super.load(tag); ContainerHelper.loadAllItems(tag, this.items); System.out.println("loaded"); } @Override protected void saveAdditional(@NotNull CompoundTag tag) { if (this.level == null) return; ContainerHelper.saveAllItems(tag, this.items); super.saveAdditional(tag); } private ArcaneScholarsTile getFootPart() { if (this.level == null) return this; BlockEntity nextEntity = this.level.getBlockEntity( this.getBlockPos().relative(this.getBlockState().getValue(ArcaneScholarsBlock.FACING))); if (nextEntity instanceof ArcaneScholarsTile arcaneScholarsTile) return arcaneScholarsTile; return this; } AnimationController<ArcaneScholarsTile> controller; AnimatableInstanceCache factory = GeckoLibUtil.createInstanceCache(this); @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllerRegistrar) { this.controller = new AnimationController<>(this, "controller", 1, (state) -> PlayState.CONTINUE); controllerRegistrar.add(this.controller); } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.factory; } @Override public @NotNull Component getDisplayName() { return Component.literal("Arcane Scholar's Table"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pPlayerInventory, @NotNull Player pPlayer) { BlockEntity entity = this.getFootPart(); return new ArcaneScholarsAnalysisMenu(pContainerId, pPlayerInventory, entity); } @Override public int @NotNull [] getSlotsForFace(@NotNull Direction pSide) { return new int[0]; } @Override public boolean canPlaceItemThroughFace(int pIndex, @NotNull ItemStack pItemStack, @Nullable Direction pDirection) { return pDirection == Direction.UP && pItemStack.is(IafItemRegistry.MANUSCRIPT.get()); } @Override public boolean canTakeItemThroughFace(int pIndex, @NotNull ItemStack pStack, @NotNull Direction pDirection) { return false; } @Override public int getContainerSize() { return 1; } @Override public boolean isEmpty() { return this.items.get(0).isEmpty(); } @Override public @NotNull ItemStack getItem(int pSlot) { return this.items.get(0); } @Override public @NotNull ItemStack removeItem(int pSlot, int pAmount) { ItemStack stack = ContainerHelper.removeItem(this.items, pSlot, pAmount); System.out.println(this.items.get(0).getCount()); return stack; } @Override public @NotNull ItemStack removeItemNoUpdate(int pSlot) { return ContainerHelper.takeItem(this.items, pSlot); } @Override public void setItem(int pSlot, @NotNull ItemStack pStack) { this.items.set(pSlot, pStack); if (pStack.getCount() > this.getMaxStackSize()) { pStack.setCount(this.getMaxStackSize()); } if (!pStack.isEmpty()) this.setChanged(); } @Override public boolean stillValid(@NotNull Player pPlayer) { return Container.stillValidBlockEntity(this, pPlayer); } @Override public void clearContent() { this.items.clear(); } } Here is the AbstractContainerMenu: package everyblu.ars_mythos.client.menus; import everyblu.ars_mythos.client.ArsMythosClientRegistry; import everyblu.ars_mythos.common.block.tiles.ArcaneScholarsTile; import everyblu.ars_mythos.common.capabilities.ArcaneResearchDataProvider; import everyblu.ars_mythos.common.helper.ContainerUtils; import everyblu.ars_mythos.common.registry.ArsMythosObjectRegistry; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; public class ArcaneScholarsAnalysisMenu extends AbstractContainerMenu { private final ArcaneScholarsTile tile; public ArcaneScholarsAnalysisMenu(int index, Inventory playerInventory, FriendlyByteBuf data) { this(index, playerInventory, playerInventory.player.level().getBlockEntity(data.readBlockPos())); } public ArcaneScholarsAnalysisMenu(int index, Inventory playerInventory, BlockEntity entity) { super(ArsMythosClientRegistry.AS_ANALYSIS.get(), index); this.tile = ((ArcaneScholarsTile) entity); ContainerUtils.addPlayerInventoryTo(this, playerInventory); ContainerUtils.addPlayerHotBarTo(this, playerInventory); this.addSlot(new Slot(this.tile, 0, 15, 47)); } @Override public boolean clickMenuButton(@NotNull Player player, int pId) { if (this.tile.isEmpty()) return false; if (player.experienceLevel < 1) return false; player.getCapability(ArcaneResearchDataProvider.RESEARCH_DATA_KEY).ifPresent(research -> research.addOrSubResearch(research.getFireResearch(), 1, 0, 0, true)); player.playSound(SoundEvents.VILLAGER_WORK_CARTOGRAPHER); if (!player.getAbilities().instabuild) { this.tile.removeItem(0, 1); player.experienceLevel--; } return super.clickMenuButton(player, pId); } @Override public @NotNull ItemStack quickMoveStack(@NotNull Player pPlayer, int pIndex) { return ContainerUtils.quickMoveStack(pPlayer, pIndex, this.slots, this, (data) -> this.moveItemStackTo(data.getLeft(), data.getMiddle(), data.getRight(), false), 1); } @Override public boolean stillValid(@NotNull Player pPlayer) { return stillValid( ContainerLevelAccess.create(pPlayer.level(), this.tile.getBlockPos()), pPlayer, ArsMythosObjectRegistry.ARCANE_SCHOLARS_TABLE_FIRE.get()); } public boolean manuscriptsEmpty() { return this.tile.isEmpty(); } } And finally, here is the AbstractContainerScreen (if needed): package everyblu.ars_mythos.client.screens; import com.mojang.blaze3d.systems.RenderSystem; import everyblu.ars_mythos.ArsMythos; import everyblu.ars_mythos.client.menus.ArcaneScholarsAnalysisMenu; import everyblu.ars_mythos.common.capabilities.ArcaneResearchDataProvider; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; public class ArcaneScholarsAnalysisScreen extends AbstractContainerScreen<ArcaneScholarsAnalysisMenu> { public static final ResourceLocation GUI_TEXTURE = ArsMythos.prefix("textures/gui/arcane_scholars_table_analysis.png"); public ArcaneScholarsAnalysisScreen(ArcaneScholarsAnalysisMenu pMenu, Inventory pPlayerInventory, Component pTitle) { super(pMenu, pPlayerInventory, pTitle); } @Override @SuppressWarnings("all") public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) { int x = (this.width - this.imageWidth) / 2; int y = (this.height - this.imageHeight) / 2; for(int k = 0; k < 3; ++k) { double d0 = pMouseX - (double)(x + 60); double d1 = pMouseY - (double)(y + 14 + 19 * k); if (d0 >= 0.0D && d1 >= 0.0D && d0 < 108.0D && d1 < 19.0D && this.menu.clickMenuButton(this.minecraft.player, k)) { this.minecraft.gameMode.handleInventoryButtonClick((this.menu).containerId, k); return true; } } return super.mouseClicked(pMouseX, pMouseY, pButton); } @Override @SuppressWarnings("all") protected void renderBg(@NotNull GuiGraphics guiGraphics, float pPartialTick, int pMouseX, int pMouseY) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_TEXTURE); int x = (this.width - this.imageWidth) / 2; int y = (this.height - this.imageHeight) / 2; guiGraphics.blit(GUI_TEXTURE, x, y, 0, 0, this.imageWidth, this.imageHeight); this.minecraft.player.getCapability(ArcaneResearchDataProvider.RESEARCH_DATA_KEY).ifPresent(research -> guiGraphics.drawString( this.minecraft.font, research.getFireResearch().getLeft().toString(), x + 160, y + 4, 255)); guiGraphics.drawString(this.minecraft.font, String.valueOf(this.minecraft.player.experienceLevel), x + 61, y + 74, 255); for (int k = 0; k < 3; ++k) { if (this.menu.manuscriptsEmpty() || this.minecraft.player.experienceLevel < 1) { guiGraphics.blit(GUI_TEXTURE, x + 60, y + 14 + (19 * k), 0, 185, 108, 19); continue; } guiGraphics.blit(GUI_TEXTURE, x + 60, y + 14 + (19 * k), 0, 166, 108, 19); double d0 = pMouseX - (double)(x + 60); double d1 = pMouseY - (double)(y + 14 + 19 * k); if (d0 >= 0.0D && d1 >= 0.0D && d0 < 108.0D && d1 < 19.0D) { guiGraphics.blit(GUI_TEXTURE, x + 60, y + 14 + (19 * k), 0, 204, 108, 19); } } } @Override public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { renderBackground(guiGraphics); super.render(guiGraphics, mouseX, mouseY, delta); renderTooltip(guiGraphics, mouseX, mouseY); } } Any help is appreciated.
    • I have this raport to lounch the game The game crashed whilst rendering screen Error: java.lang.NullPointerException: Cannot invoke "net.minecraft.client.gui.components.Button.m_252907_()" because "this.serverBrowser$grabbedMultiplayerButton" is null Kod zakończenia: -1 And full message:   https://ntpd.eu/N3gq6
    • EDIT: I had to declare the library like a mod (using the @Mod annotation and adding the mods.toml + pack.mcmeta files). By doing this it works now Hi everyone  I'm trying to create an internal library for all my mods, and inside it I have a method that registers an Item public static RegistryObject<Item> registerItem(final DeferredRegister<Item> registry, final String name, final Supplier<Item> itemSupplier) { return registry.register(name, itemSupplier); } When the method is called from a mod, Forge raises this error   Exception message: java.lang.LinkageError: loader constraint violation: loader 'SECURE-BOOTSTRAP' @6bedbc4d wants to load class net.minecraftforge.registries.DeferredRegister. A different class with the same name was previously loaded by 'TRANSFORMER' @6d672bd4. (net.minecraftforge.registries.DeferredRegister is in module [email protected] of loader 'TRANSFORMER' @6d672bd4, parent loader 'bootstrap') Both the version of Forge included in the library's build.gradle and the mod's build.gradle are the same. I've never done this, so there's a good chance I'm configuring something wrong. This is the build.gradle file of the library (which is part of a multi-module project)   plugins { id 'net.minecraftforge.gradle' version '[6.0.24,6.2)' } repositories { gradlePluginPortal() maven { name = 'MinecraftForge' url = 'https://maven.minecraftforge.net/' } } java.toolchain.languageVersion = JavaLanguageVersion.of(21) minecraft { mappings channel: 'official', version: minecraft_version reobf = false copyIdeResources = true } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } } } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' }  
    • Hello i wanna make a modded server for me and my friends and the game is crashing when i use items that pop-up and UI and we cannot place modded blocks.  Here is the video i take so it's more easy for you guys to see.   Help please! Thanks
  • Topics

×
×
  • Create New...

Important Information

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