Jump to content

Recommended Posts

Posted
33 minutes ago, Distinct Soul said:

Then why was I told to create it? And what am I supposed to do with it now then?

By whom? When? Where?

Because you were not told to do that anywhere in this thread.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
3 hours ago, Distinct Soul said:

In Cadiboo's tutorials, he says to look at Cubicoder's one for 1.12.2, and it has it there: https://cubicoder.github.io/tutorials/1-12-2/2018-06-20-first-block/

image.png.41132ea46464c3e3e56bd91175456725.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Oh in that case.

 

BlockFirstBlock is not BlockBase.

 

BlockFirstBlock is a literal "here's how you write your own block class." It is not the class you extend all your blocks from.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You do not need BlockBase. If you don't need it, what do you do with it?

(This is intentionally pedantic because the question you asked is self-answering)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I just realised, I also have a class called 'ItemBase', should I also remove this, or is this needed?

This is it's contents:

public class ItemBase extends Item {
	
	public ItemBase() {
		
		setCreativeTab(ModItems.SOUL_FORGERY);
	}
	
	public void registerModels() {
		
		IProxy.registerItemRenderer(this, 0, "inventory");
	}
}

 

Posted
4 hours ago, Distinct Soul said:

should I also remove this

Yes, same reasons. There's already a base item class, called Item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ooohhh... A lot of things just made sense to me; but I can't be asked to explain what. Regardless, I still have the error referring to line 41 of my EventSubscriber class.

 

Here's the class that I believe actually initializes it:

public class BlockIgrianOre extends Block {
	
	public BlockIgrianOre() {
		super(Material.ROCK);
		setCreativeTab(ModItems.SOUL_FORGERY);
		setSoundType(SoundType.STONE);
		setHardness(4.0F);
		setResistance(25.0F);
		setHarvestLevel("pickaxe", 3);
		setLightLevel(0.1F);
		// setLightOpacity(1);
		// setBlockUnbreakable();
	}
	
	@Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
		return ModItems.IGRIAN_SHARDS;
	}
	
	@Override
	public int quantityDropped(Random random) {	
		return 1 + random.nextInt(2);
	}
	
	@Override
	public int quantityDroppedWithBonus(int fortune, Random random) {
		return this.quantityDropped(random) + random.nextInt(fortune + 1);
	}
}

 

Posted
44 minutes ago, Distinct Soul said:

Regardless, I still have the error referring to line 41 of my EventSubscriber class.

See:

On 8/5/2019 at 4:31 PM, diesieben07 said:

The fields in ModBlocks are null. How are you initializing them?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

When you put in your mod blocks class fields and then don't assign those fields values, they stay null forever. Yet you are trying to reference them as if they were not null.

 

Unfortunately you haven't posted enough code in one place to adequately tell you what you've done wrong, only what has gone wrong.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

So, I've been looking more at Cubicoder's tutorials, and I've been changing my code a lot to fit with what he has. I apologise sincerely for this, as I'm sure it infuriates you trying to help someone who keeps changing their code that has nothing to do with your advice. At first, I was going off Cadiboo's example mod as he was the first to give help me on this matter; but I felt like it would make more sense to follow a proper tutorial (more specifically, Cubidocoder's, which Cadiboo links himself), as my mod had problems all over, and I found just following classes wasn't very useful, as I wasn't understanding why things were like they were.

It should help though that you know I'm following the format of Cubicoder's tutorials. Just so you know, I still do have an error, which is completely different from the previous one. I have no idea what it means; but I'm almost 100% sure it's because I still have some code from Cadiboo's example mod that doesn't work with Cubicoder's code. Here's the error log:

Spoiler

---- Minecraft Crash Report ----
// Don't do that.

Time: 8/9/19 4:02 PM
Description: Initializing game

java.lang.RuntimeException: One of more entry values did not copy to the correct id. Check log for details!
    at net.minecraftforge.registries.ForgeRegistry.sync(ForgeRegistry.java:543)
    at net.minecraftforge.registries.GameData.loadRegistry(GameData.java:490)
    at net.minecraftforge.registries.GameData.freezeData(GameData.java:225)
    at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:730)
    at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:352)
    at net.minecraft.client.Minecraft.init(Minecraft.java:581)
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:25)


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

-- Head --
Thread: Client thread
Stacktrace:
    at net.minecraftforge.registries.ForgeRegistry.sync(ForgeRegistry.java:543)
    at net.minecraftforge.registries.GameData.loadRegistry(GameData.java:490)
    at net.minecraftforge.registries.GameData.freezeData(GameData.java:225)
    at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:730)
    at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:352)
    at net.minecraft.client.Minecraft.init(Minecraft.java:581)

-- Initialization --
Details:
Stacktrace:
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:25)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_181, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 619194224 bytes (590 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP 9.42 Powered by Forge 14.23.3.2655 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State  | ID          | Version      | Source                           | Signature |
    |:------ |:----------- |:------------ |:-------------------------------- |:--------- |
    | UCHIJA | minecraft   | 1.12.2       | minecraft.jar                    | None      |
    | UCHIJA | mcp         | 9.42         | minecraft.jar                    | None      |
    | UCHIJA | FML         | 8.0.99.99    | forgeSrc-1.12.2-14.23.3.2655.jar | None      |
    | UCHIJA | forge       | 14.23.3.2655 | forgeSrc-1.12.2-14.23.3.2655.jar | None      |
    | UCHIJA | soulforgery | 0.0.1        | bin                              | None      |

    Loaded coremods (and transformers): 
    GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 430.86' Renderer: 'GeForce GTX 1050 Ti/PCIe/SSE2'
    Launched Version: 1.12.2
    LWJGL: 2.9.4
    OpenGL: GeForce GTX 1050 Ti/PCIe/SSE2 GL version 4.6.0 NVIDIA 430.86, NVIDIA Corporation
    GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

    Using VBOs: Yes
    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Packs: 
    Current Language: English (US)
    Profiler Position: N/A (disabled)
    CPU: 12x AMD Ryzen 5 1600X Six-Core Processor 

I have no idea what class(es) I'm supposed to send, as I don't see it reference any of my classes anywhere in there, and I don't want to send all my classes because of it. Do you know what class or classes might help you with problem here?

Posted

How am I supposed to debug your code? You didn't post it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Post it on github.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 1 month later...
Posted

Alright, I've spent a long time looking all over trying to figure out how to create some sort of custom furnace (more specifically, for my situation, I want a kind of alloy smelter that uses glowstone and glowstone blocks for fuel (glowstone blocks of course giving more fuel), and both of the 2 inputs can also be the same to get a different output; but only for certain items.) for 1.12; and I've not found any kind of tutorial on how to do the 'right' way (without using IInventory). Harry's Tech Reviews goes over doing it the 'wrong' way for the TileEntity class, fixes it in the next episode; but he doesn't go over at all, what he did to fix it. I've also tried looking at the TileEntityFurnace class, and while I do understand a little bit of it (sometimes lines within certain blocks of code; but not exactly what the block of code does itself; and other times, the other way around), I find it doesn't help when I don't understand the rest of it. Another thing I did, was look at the Forge Documentation on tile entities; but I didn't find that really helped either.

Just to let you know, I don't have any experience with creating a block that's interact-able or that has a GUI (if you couldn't tell by what I've said up to this point), so I will need quite a bit of help on it. Also, without a doubt, from my experience with being helped out on here, I definitely understand easier on what to do through clear examples and videos (ideally voiced over ones); though I'm sure a video is too much to ask for.

Posted
36 minutes ago, Distinct Soul said:

and I've not found any kind of tutorial on how to do the 'right' way (without using IInventory)

This is pretty simple. Don't implement IInventory on your TileEntity. Instead store an instance of IItemHandler in your TileEntity. You can initialize it using ItemStackHandler. 

 

The next step is to override getCapability and hasCapability. In your case hasCapability can just compare the Capability parameter against CapabilityItemHandler.ITEM_HANDLER_CAPABILITY(just using ==). And in a case where it isn't that one return the super. Then in getCapability do the same thing except you need to return your IItemHandler instance. I believe what you had to do here was use Capability#cast(value).

42 minutes ago, Distinct Soul said:

Just to let you know, I don't have any experience with creating a block that's interact-able or that has a GUI

The worst thing I've seen a tutorial do wrong for something like this was have the Block class implement ITileEntityProvider. I haven't seen anything wrong with the way they set up the Gui and Container.

 

44 minutes ago, Distinct Soul said:

more specifically, for my situation, I want a kind of alloy smelter that uses glowstone and glowstone blocks for fuel (glowstone blocks of course giving more fuel), and both of the 2 inputs can also be the same to get a different output; but only for certain items.)

This part is just the logic behind what you want to do. Simply figure out the conditions for when you want it to consume fuel. And when those conditions are true consume fuel. The same can be said for the processing part. Figure out when you want the furnace to process, then once it is done consume the ingredients and give the output.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • 2 weeks later...
Posted

I believe I followed what you said. However, I ended up following Harry's tutorials for this, and it turns out, that I didn't have to change much, as my machine turns out to have almost an identical function to his - turning 2 items into 1. Though; it's a little confusing with his tutorials being different to his github which I've been told is more up to date and reliable than his videos... The problem is, or shall I say problems in this case, are that my machine doesn't actually work... and you can input items into the output slot. What I mean by 'that my machine doesn't work' is, putting a fuel into the fuel slot, then the correct items in the input slots, results in the fuel being consumed, the fuel meter goes down; but the input items are consumed immediately and nothing ends up actually being outputted. What's even weirder, is that the second time, it 'kinda' works better than the first time, as the input items this time stay until processed, and the output actually outputs something; however, that turns out to be a ghost item, or at at least about 90% of the time it is. Then after this, the machine simply will no longer work at all. All slots can have items inside them; but nothing will happen even if the right items are placed in the right slots. And this applies to all instances of the machine, so placing another one down will also just not function. What's just as weird, is that the only error I see that I'm not even sure relates to the machine's function is saying this:

Spoiler

com.mojang.authlib.exceptions.AuthenticationException: The client has sent too many requests within a certain amount of time
	at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:79) ~[YggdrasilAuthenticationService.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillGameProfile(YggdrasilMinecraftSessionService.java:180) [YggdrasilMinecraftSessionService.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:60) [YggdrasilMinecraftSessionService$1.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:57) [YggdrasilMinecraftSessionService$1.class:?]
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache.get(LocalCache.java:4154) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147) [guava-21.0.jar:?]
	at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153) [guava-21.0.jar:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillProfileProperties(YggdrasilMinecraftSessionService.java:170) [YggdrasilMinecraftSessionService.class:?]
	at net.minecraft.client.Minecraft.getProfileProperties(Minecraft.java:3177) [Minecraft.class:?]
	at net.minecraft.client.resources.SkinManager$3.run(SkinManager.java:138) [SkinManager$3.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_181]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_181]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_181]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_181]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]

 

Though this might be because it's a Java test environment.

I'm not sure what class/classes could be causing these problems, so I don't really know what code to post; but you should be able to find out if you take a look at my code. I've just now uploaded it to GitHub, and there should be a link to it here in my 'About Me' section.

 

Another problem is that, my block model no longer has it's texture when placed down, and I do realise that there is information on this that I don't understand in the log when I launch the game; however, right now I wanna focus on the machines functionality working rather than what it looks like.

Posted
1 hour ago, Distinct Soul said:

you can input items into the output slot

You need to specify that in the Container as a different subclass of Slot.

 

1 hour ago, Distinct Soul said:

AuthenticationException

Completely and utterly unrelated to any of your code. All that error is is the player account being used in dev can't be authenticated with Mojang's servers (i.e. the "account" doesn't exist). This is a non-issue.

1 hour ago, Distinct Soul said:

What I mean by 'that my machine doesn't work' is, putting a fuel into the fuel slot, then the correct items in the input slots, results in the fuel being consumed, the fuel meter goes down; but the input items are consumed immediately and nothing ends up actually being outputted. What's even weirder, is that the second time, it 'kinda' works better than the first time, as the input items this time stay until processed, and the output actually outputs something; however, that turns out to be a ghost item, or at at least about 90% of the time it is.

That sounds like nothing is happening on the server and everything you're seeing is on the client.

But you haven't posted any code, so who knows.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • 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() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
  • Topics

×
×
  • Create New...

Important Information

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