Jump to content

20ChenM

Members
  • Posts

    49
  • Joined

  • Last visited

Posts posted by 20ChenM

  1. player.PlaySound?

     

    im not sure i understand your question. Ive set up the Sound Event I think in this code:

    Class SoundInit.java:

    package com.Michael.TutorialMod2.init;
    
    import com.Michael.TutorialMod2.Tutorial;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.SoundEvent;
    import net.minecraftforge.fml.RegistryObject;
    import net.minecraftforge.registries.ForgeRegistries;
    import com.Michael.TutorialMod2.util.RegistryHandler;
    import net.minecraftforge.registries.DeferredRegister;
    
    public class SoundInit {
    
        public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS,Tutorial.MOD_ID);
    
        public static final RegistryObject<SoundEvent> AMBEINT = SOUNDS.register(
                "russia.ambient_sound",()-> new SoundEvent(new ResourceLocation(Tutorial.MOD_ID,"russia.ambient_sound")));
    
        ResourceLocation location = new ResourceLocation("examplemod", "item.russia_sound");
        SoundEvent events1 = new SoundEvent(location);
    
    }

    and i also made the sound.json file:

    "item.russia_sound": {
                "category": "item",
    "subtitle": "russia.ambient.sub",
      "sounds": [{
        "name":"examplemod:item/russia_sound",
        "stream": true}
        ]
       }
    }

    so im just confused on how to call the method to play the sound.

     

    heres the code i have to play the sound:

    if(player.getHeldItemMainhand().getItem() == RegistryHandler.Vodka.get()) {
       Tutorial.LOGGER.info("testing");
    
    
          player.playSound( I DONT KNOW WHAT TO PUT HERE, 1.0f, 1.0f);
    
    
    
    
            }
    
            }
    }
    

    Im not sure what to put in the player.playSound section. All the tutorials ive seen are for 1.15 but my mod is 1.16

     

    Its asking for(Sound Event, soudln. volume, pitch)

    I dont know what corresponds to which variable int he Sound Event

  2. Ive created a class called ModClientEvents which manages my events. in it, I have the following code:

     

    ackage com.Michael.TutorialMod2.events;
    
    
    import com.Michael.TutorialMod2.Tutorial;
    import com.Michael.TutorialMod2.items.Vodka;
    import com.Michael.TutorialMod2.util.RegistryHandler;
    import net.minecraft.entity.LivingEntity;
    import net.minecraft.item.Items;
    import net.minecraftforge.api.distmarker.Dist;
    import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
    import net.minecraftforge.fml.common.Mod;
    import  net.minecraftforge.event.entity.EntityEvent;
    
    @Mod.EventBusSubscriber(modid = Tutorial.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public class ModClientEvents {
    
    
        public static void onPlayerEat(LivingEntityUseItemEvent event) {
    
    
        LivingEntity player = event.getEntityLiving();
    
        if(player.getHeldItemMainhand().getItem() == RegistryHandler.Vodka.get()) {
       Tutorial.LOGGER.info("test");
    //code to play a 3rd party sound file
    
    
            }
    
            }
    }
    

     

     

    How can I play a 3rd party sound after I finish using the item vodka?

  3. I want to use the following code(

    public int getExpDrop(Blockstate state, IWorldReader reader, BlockPos pos, int Fortune, int silktouch){
        return 1;}
    

    )

     

    to allow my oreblock to give exp when broken. However, even after importing 

    import net.minecraft.block.BlockState;

     

    the text above is gray which means it is unused and the word Block state in the first code is red and gives the error: Cannot resolve symbol 'Blockstate'

     

    Can anyone help?

  4. I just moved my 1.15.2 mod to 1.16.1 by replacing the build.gradle with a 1.16.1 build.gradle from the 1.16.1 mdk. I then recreated the workspace. For some reason though, the .set commands dont work and I get an error saying:Cannot resolve method 'setLightLevel' in 'Properties'

     

     

    My Code:

    package com.Michael.TutorialMod2.blocks;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraftforge.common.ToolType;
    
    public class RubyBlock extends Block {
    
    
        public RubyBlock() {
            super(Block.Properties.create(Material.IRON)
            .hardnessAndResistance(5.0f,6.0f)
                            .sound(SoundType.METAL)
                    .harvestLevel(3)
                    .harvestTool(ToolType.PICKAXE)
                    .setLightLevel(value ->1)
            );
        }
    }
  5. I have a friend who wants to make a mod that places blocks beneath your feet but his code has errors. I do not know how to help him since i am new to 1.15.2 modding so I am coming to the forums asking for help.

     

     

     

    His Code:

     

    Locate class:

    import net.minecraft.block.Block;

    import net.minecraft.block.BlockState;

    import net.minecraft.block.Blocks;

    import net.minecraft.block.material.Material;

    import net.minecraft.client.Minecraft;

    import net.minecraft.entity.LivingEntity;

    import net.minecraft.fluid.IFluidState;

    import net.minecraft.util.math.BlockPos;

    import net.minecraft.entity.Entity;

    import net.minecraft.entity.player.*;

    import net.minecraft.item.Item;

    import net.minecraft.world.World;

    import net.minecraftforge.fml.RegistryObject;

    import net.minecraftforge.registries.DeferredRegister;

    import net.minecraftforge.registries.ForgeRegistries;

     

    public class Locate {

       public void isAirBelow(BlockPos pos)

       {

           EntityPlayer player = event.player;

           BlockPos posBelow = player.getPosition().down();

           BlockState blockStateBelow = player.world.getBlockState(posBelow);

           Block below = blockStateBelow.getBlock();

     

           if(below.equals(Material.AIR)) {

               world.setBlock(blockStateBelow, Blocks.COBBLESTONE);

           }

       }

    }

     

    main class:

     

    import java.util.stream.Collectors;

     

    // The value here should match an entry in the META-INF/mods.toml file

    @Mod("Scaffold")

    public class Scaffold

    {

       // Directly reference a log4j logger.

       private static final Logger LOGGER = LogManager.getLogger();

     

       public Scaffold() {

           // Register the setup method for modloading

           FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);

           FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

     

           // Register ourselves for server and other game events we are interested in

           MinecraftForge.EVENT_BUS.register(this);

       }

     

       private void setup(final FMLCommonSetupEvent event)

       {

           // some preinit code

           LOGGER.info("HELLO FROM PREINIT");

           LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());

       }

     

       private void doClientStuff(final FMLClientSetupEvent event) {

           // do something that can only be done on the client

           LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);

       }

    }

     

×
×
  • Create New...

Important Information

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