Jump to content

Recommended Posts

Posted

Hello I'm trying to add a music disc into Minecraft. I'm on forge 1.7.10-10.13.2.1291. I've been trying to add a music disc for quite some time and nothing, I've got it in the game with the proper name but theres no sound. I've added bunch of other stuff into Minecraft and had no problems. I only gave you everything that is connected with the music disc and if you know anything wrong with my setup, please tell me. :'(

 

This is my MusicDisc.java :: http://pastebin.com/TJ59fGjk

And this is my main class :: http://pastebin.com/jU6vJrMp

 

My sounds.json :

{

    "records.Kitten": {"category": "record", "sounds": [{"name": "records/kitten","stream": true }]}

}

 

And my en_US.lang :

item.record_Kitten.name=Music Disc

item.record_Kitten.desc=Music Disc Description Testing

 

Thanks for your time.    :)

Posted

This is my adddisc function for custom records. But I am using 1.8.0 so I am not sure whether it is work on 1.7.10 or not.

 

package net.extend.mod.functions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;

import net.extend.mod.ref;
import net.minecraft.block.BlockJukebox;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class adddisc extends ItemRecord {

public String music;
private static final Map RECORDS = new HashMap();
public adddisc(String name, String music) {
	super(music);

	this.setMaxStackSize(1);
        this.setCreativeTab(CreativeTabs.tabMisc);
        this.setUnlocalizedName(name);
        this.music = music;
        RECORDS.put("records." + music, this);
        GameRegistry.registerItem(this, name);
}

@Override
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (iblockstate.getBlock() == Blocks.jukebox && !((Boolean)iblockstate.getValue(BlockJukebox.HAS_RECORD)).booleanValue()) {
            if (worldIn.isRemote) { return true; }
            else {
            	((BlockJukebox)Blocks.jukebox).insertRecord(worldIn, pos, iblockstate, stack);
                worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1005, pos, Item.getIdFromItem(this));
                --stack.stackSize;
                return true;
            }
        } else { return false; }
    }

@Override
    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) {
        tooltip.add(this.getRecordNameLocal());
    }

@Override
    @SideOnly(Side.CLIENT)
    public String getRecordNameLocal() {
        return StatCollector.translateToLocal(this.getUnlocalizedName() + ".desc");
    }

@Override
public ResourceLocation getRecordResource(String record) {
	ResourceLocation location = super.getRecordResource(ref.uid + ":" + this.music);
	return location;
}

 @Override
 public EnumRarity getRarity(ItemStack itemStack) {
	 return EnumRarity.RARE;
 }

 @SideOnly(Side.CLIENT)
 public static adddisc getRecord(String name) {
	 return (adddisc)RECORDS.get(name);
     }
}

 

public static Item discWish;
public static Item discJingle;
public static Item discCarol;
public static Item discBirGorusKabininde;
public static Item discAhSensiz;
public static Item discKoNewYear;
public static Item discNumb;
public static Item discBeautifulMind;
public static Item discSomebodyToldMe;
public static Item discKids;
public static Item discGhostsNStuff;
public static Item discVivaLaVida;
public static Item discApplause;
public static Item discDiamonds;
public static Item discMovesLikeJagger;
public static Item discRapGod;
public static Item discSetFireToRain;
public static Item discSurvival;
public static Item discMusadenizleCocuklar;
public static Item discWeAreTheChampions;
public static Item discTheFinalCountdown;
public static Item discStill;

 

	discWish = new adddisc("discwish", "wish");
	discJingle = new adddisc("discjingle", "jingle");
	discCarol = new adddisc("disccarol", "carol");
	discBirGorusKabininde = new adddisc("discbirgoruskabininde", "birgoruskabininde");
	discAhSensiz = new adddisc("discahsensiz", "ahsensiz");
	discKoNewYear = new adddisc("disckonewyear", "konewyear");
	discNumb = new adddisc("discnumb", "numb");
	discBeautifulMind = new adddisc("discbeautifulmind", "beautifulmind");
	discSomebodyToldMe = new adddisc("discsomebodytoldme", "somebodytoldme");
	discKids = new adddisc("disckids", "kids");
	discGhostsNStuff = new adddisc("discghostsnstuff", "ghostsnstuff");
	discVivaLaVida = new adddisc("discvivalavida", "vivalavida");
	discApplause = new adddisc("discapplause", "applause");
	discDiamonds = new adddisc("discdiamonds", "diamonds");
	discMovesLikeJagger = new adddisc("discmoveslikejagger", "moveslikejagger");
	discRapGod = new adddisc("discrapgod", "rapgod");
	discSetFireToRain = new adddisc("discsetfiretorain", "setfiretorain");
	discSurvival = new adddisc("discsurvival", "survival");
	discMusadenizleCocuklar = new adddisc("discmusadenizlecocuklar", "musadenizlecocuklar");
	discWeAreTheChampions = new adddisc("discwearethechampions", "wearethechampions");
	discTheFinalCountdown = new adddisc("discthefinalcountdown", "thefinalcountdown");
	discStill = new adddisc("discstill", "still");

 

Json:

{
    "wish": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/wish",
            "stream": true
            }
        ]
    },
    
    "jingle": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/jingle",
            "stream": true
            }
        ]
    },

    "carol": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/carol",
            "stream": true
            }
        ]
    },

    "birgoruskabininde": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/birgoruskabininde",
            "stream": true
            }
        ]
    },
    
    "ahsensiz": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/ahsensiz",
            "stream": true
            }
        ]
    },
    
    "konewyear": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/konewyear",
            "stream": true
            }
        ]
    },
    
    "numb": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/numb",
            "stream": true
            }
        ]
    },

    "beautifulmind": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/beautifulmind",
            "stream": true
            }
        ]
    },

    "somebodytoldme": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/somebodytoldme",
            "stream": true
            }
        ]
    },

    "kids": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/kids",
            "stream": true
            }
        ]
    },

    "ghostsnstuff": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/ghostsnstuff",
            "stream": true
            }
        ]
    },

    "vivalavida": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/vivalavida",
            "stream": true
            }
        ]
    },

    "applause": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/applause",
            "stream": true
            }
        ]
    },   

    "diamonds": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/diamonds",
            "stream": true
            }
        ]
    },

    "moveslikejagger": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/moveslikejagger",
            "stream": true
            }
        ]
    },

    "rapgod": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/rapgod",
            "stream": true
            }
        ]
    },

    "setfiretorain": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/setfiretorain",
            "stream": true
            }
        ]
    },

    "survival": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/survival",
            "stream": true
            }
        ]
    },
    
    "musadenizlecocuklar": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/musadenizlecocuklar",
            "stream": true
            }
        ]
    },
    
    "wearethechampions": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/wearethechampions",
            "stream": true
            }
        ]
    },
    
    "thefinalcountdown": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/thefinalcountdown",
            "stream": true
            }
        ]
    },
    
    "still": {
        "category": "record",
        "sounds": [
            {
            "name": "extend:records/still",
            "stream": true
            }
        ]
    }
}

 

And my ogg files in

C:\Users\Hamit\Desktop\Minecraft\1.8.0\src\main\resources\assets\extend\sounds\records

 

I am not sure, but maybe help you.

Posted

Glistre, your modid can be anything, with numbers and can have as many as you want characters.

I'll be trying the code xwerswoodx gave and see if that works. Will post my result.

Posted

Doesn't work...

When I copied the code there was a lot of errors, I fixed all of them and still nothing.

I got the item in game, I can put it in the jukebox but there still isn't any sound. :/  :'(

I wish there was a straightforward tutorial for 1.7.10.

If anyone knows something more, please let me know.

  • 2 weeks later...
Posted

I'm still working on this I solved it for 1.6.4 but not 1.7.10 ...cannot seem to get the sound to play which I believe must be done using @SubscribeEvent instead of @ForgeSubscribe but the same methods no longer work

 

This works in 1.6.4

public class SoundLoadHandler {
@SideOnly(Side.CLIENT)
@ForgeSubscribe
public void onSoundsLoaded(SoundLoadEvent event) {
	SoundManager src = event.manager;
	src.soundPoolStreaming.addSound("glistremod:wolf_howl.ogg");
/*		src.soundPoolStreaming.addSound(ref.uid + ":jingle.ogg");
	*/
}
/*	@ForgeSubscribe 
public void onSound(SoundLoadEvent event)
        {
            event.manager.soundPoolStreaming.addSound("glistremod:wolf_howl");         
    }*/

@SideOnly(Side.CLIENT)
@ForgeSubscribe
public void onPlayStreaming(PlayStreamingEvent event) {
	boolean isCont;
	isCont = event.name.contains("glistremod");
	if (!isCont) {
		FMLClientHandler.instance().getClient().sndManager.playStreaming("glistremod:" +  event.name, event.x + 0.5F, event.y + 0.5F, event.z + 0.5F);
	}
}

}

 

and put on the Event bus with :

        MinecraftForge.EVENT_BUS.register(new SoundLoadHandler());

 

maybe you can work with that

 

Posted

This is all I have and it works fine:

 

public class CustomRecord extends ItemRecord
{

 private static final Map records = new HashMap();

 public final String recordName;

 public CustomRecord(String recordName)
 {
	 super(recordName);

	 this.recordName = recordName;
	 this.maxStackSize = 1;

	 records.put(recordName, this);
 }


 @Override
 public void registerIcons(IIconRegister iconRegister)
 {
	 itemIcon = iconRegister.registerIcon(Main.modid + ":" + "record");
 }


 @Override
 public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
 {
	 if (world.getBlock(x, y, z) == Blocks.jukebox && world.getBlockMetadata(x, y, z) == 0)
    	 {
		 if (world.isRemote)
		 {
			 return true;
		 }
		 else
		 {
			 ((BlockJukebox)Blocks.jukebox).func_149926_b(world, x, y, z, itemStack);
			 world.playAuxSFXAtEntity((EntityPlayer)null, 1005, x, y, z, Item.getIdFromItem(this));
			 --itemStack.stackSize;
			 return true;
     	}
    	 } 
	 else
 	{
	 	return false;
 	}
 }


 @Override
 public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
 {
	 par3List.add(this.getRecordNameLocal());
 }


 @Override
 //TODO: getRecordTitle()
 public String getRecordNameLocal()
 {
	 return StatCollector.translateToLocal(this.getUnlocalizedName() + ".desc");
 }


 @Override
 public EnumRarity getRarity(ItemStack itemStack)
 {
	 return EnumRarity.rare;
 }


 public static RecordHorror getRecord(String par0Str)
 {
	 return (RecordHorror)records.get(par0Str);
 }


 @Override
 public ResourceLocation getRecordResource(String name)
 {
	 return new ResourceLocation(Main.modid + ":" + name);
 }
}

 

None of that needs to be edited except for the icon texture name near the top.

As for the making the item itself:

 

record_name = new CustomRecord("Record Title").setUnlocalizedName("record_name ").setCreativeTab(CreativeTabs.tabMisc).setTextureName(Main.modid + ":" + "record");
GameRegistry.registerItem(record_name , "record_name ");

 

And lastly in the sounds.json file:

{
  "RecordTitle": {
    "category": "record",
    "sounds": [{"name": "RecordTitle",
    "stream": true}]
  }
}

Posted

I got an error Unable to play Unknown soundEvent unless I had this:

 @Override
@SubscribeEvent
public ResourceLocation getRecordResource(String name)
{
 return new ResourceLocation(GlistreMod.MODID +":"+ name);
}

 

and my sounds json did not have "records. ' in front of wolf_howl

{
  "records.wolf_howl": {
    "category": "record",
    "sounds": [
      {
        "name": "wolf_howl",
        "stream": true
      }
    ]
  }
}

 

mine now works

  • 1 month later...
Posted

This is all I have and it works fine:

 

public class CustomRecord extends ItemRecord
{

 private static final Map records = new HashMap();

 public final String recordName;

 public CustomRecord(String recordName)
 {
	 super(recordName);

	 this.recordName = recordName;
	 this.maxStackSize = 1;

	 records.put(recordName, this);
 }


 @Override
 public void registerIcons(IIconRegister iconRegister)
 {
	 itemIcon = iconRegister.registerIcon(Main.modid + ":" + "record");
 }


 @Override
 public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
 {
	 if (world.getBlock(x, y, z) == Blocks.jukebox && world.getBlockMetadata(x, y, z) == 0)
    	 {
		 if (world.isRemote)
		 {
			 return true;
		 }
		 else
		 {
			 ((BlockJukebox)Blocks.jukebox).func_149926_b(world, x, y, z, itemStack);
			 world.playAuxSFXAtEntity((EntityPlayer)null, 1005, x, y, z, Item.getIdFromItem(this));
			 --itemStack.stackSize;
			 return true;
     	}
    	 } 
	 else
 	{
	 	return false;
 	}
 }


 @Override
 public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
 {
	 par3List.add(this.getRecordNameLocal());
 }


 @Override
 //TODO: getRecordTitle()
 public String getRecordNameLocal()
 {
	 return StatCollector.translateToLocal(this.getUnlocalizedName() + ".desc");
 }


 @Override
 public EnumRarity getRarity(ItemStack itemStack)
 {
	 return EnumRarity.rare;
 }


 public static RecordHorror getRecord(String par0Str)
 {
	 return (RecordHorror)records.get(par0Str);
 }


 @Override
 public ResourceLocation getRecordResource(String name)
 {
	 return new ResourceLocation(Main.modid + ":" + name);
 }
}

 

None of that needs to be edited except for the icon texture name near the top.

As for the making the item itself:

 

record_name = new CustomRecord("Record Title").setUnlocalizedName("record_name ").setCreativeTab(CreativeTabs.tabMisc).setTextureName(Main.modid + ":" + "record");
GameRegistry.registerItem(record_name , "record_name ");

 

And lastly in the sounds.json file:

{
  "RecordTitle": {
    "category": "record",
    "sounds": [{"name": "RecordTitle",
    "stream": true}]
  }
}

 

Erm, is it possible for you to give me all the imports. There are multiply one I can select when I about to import and I'm not too sure which one is the right one.

  • 7 months later...
Posted

Yeah i am looking to add new music disks to my minecraft without using the more disks mod for Minecraft 1.7.10 i suck at Java coding and would like someone to help me out adding my music to my minecraft as the orginal disks are boring now, however i do not want to overwrite the disks already in minecraft so how can i add my music in music disks without overwriting the original Minecraft music disks?

Posted

You're gonna need to compromise somewhere, and it's gonna take some work.

 

1) Find a mod that will add disc items to the game and allow you to insert your own music files for those discs to play. I just happen to have such a project on my to-do list. I might even get to it before the end of 2016, but don't hold your breath. However, you'd still need to get your music into ogg format (prolly require conversion, which will require an app like VLC and learning how to use it). Then the ogg files would prolly need special names, and they'd need to be moved to a special place so that the mod would use them.

 

2) Go learn Java. This forum assumes you already know Java and just need a little help to understand a Forge feature, so you'll need to look beyond. Fortunately, there are many online tutorials and manuals and forum discussions. Java's essential-level features are also amazingly easy to acquire if you have experience in another O-O language, esp once you come up to speed in Eclipse for Java (an IDE).

 

3) Hire a professional. When "between contracts" (i.e. unemployed), we can be had for about $50/hr (or you could hire an amateur for $30/hr, maybe even less, but he would take forever and still get it wrong). I estimate this project will take about 1 week coding and another of debugging. So basically, you're asking for about $4000 worth of help here. Scrape together $4000, and you'll find help coming out of the woodwork.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

So if i want help on adding my own music to mincraft i am expected to pay £2775.98 just for a small bit of coding?

I guess i need to learn Java then oh well; thanks for the help but I think that £2775.98 is way too much to pay just for some lines of code

Posted

... a small bit of coding... just for some lines of code

You really underestimate the amount of code needed. It is just not 'some lines of code'.

 

BTW, next time, please don't reply to a thread which is 6 months old, thank you.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

So if i want help on adding my own music to mincraft i am expected to pay £2775.98...?

No, you just need to get a hell of a lot closer to the finished product before you ask for the tip that sets you free.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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

    • 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() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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