Jump to content

[1.7.10] Calling Achievements


EsvDefcon

Recommended Posts

Hi,

 

So, I have to custom method to call achievements. I want my achievements to unlock when the player builds a ship of a certain size, with certain weapons, or with a certain cargo capacity (this is for my airship mod). So, this is the code I use to get the type of ship that the player has built:

 

public static String getShipType(ItemCraftedEvent event) {
	if(passengerCapacity > actualCargoCapacity && passengerCapacity > actualWeaponCount) {
		event.player.addStat(Skyline.achievementCivilianCaptain, 1);
		if(passengerCapacity >= 50) {
			return "Passenger- Skyliner";
		} else if(passengerCapacity < 50 && passengerCapacity >= 25) {
			return "Passenger- Airship";
		} else if(passengerCapacity < 25 && passengerCapacity >= 15) {
			return "Passenger- Large Ship";
		} else if(passengerCapacity < 15 && passengerCapacity >= 10) {
			return "Passenger- Medium Ship";
		} else if(passengerCapacity < 10 && passengerCapacity >= 2) {
			return "Passenger- Small Ship";
		}
	} else if(actualCargoCapacity > passengerCapacity && actualCargoCapacity > actualWeaponCount) {
		event.player.addStat(Skyline.achievementCivilianCaptain, 1);
		if(actualCargoCapacity >= 50) {
			return "Transport- Freighter";
		} else if(actualCargoCapacity < 50 && actualCargoCapacity >= 25) {
			return "Transport- Cargo Ship";
		} else if(actualCargoCapacity < 25 && actualCargoCapacity >= 10) {
			return "Transport- Trade Ship";
		}
	} else if(actualWeaponCount > passengerCapacity && actualWeaponCount > actualCargoCapacity) {
		event.player.addStat(Skyline.achievementMilitaryCaptain, 1);
		if(actualWeaponCount >= 25) {
			return "Military- Dreadnought";
		} else if(actualWeaponCount < 25 && actualWeaponCount >= 20) {
			return "Military- Battleship";
		} else if(actualWeaponCount < 20 && actualWeaponCount >= 15) {
			return "Military- Battlecruiser";
		} else if(actualWeaponCount < 15 && actualWeaponCount >= 10) {
			return "Military- Cruiser";
		} else if(actualWeaponCount < 10 && actualWeaponCount >= 5) {
			return "Military- Destroyer";
		} else if(actualWeaponCount < 5 && actualWeaponCount >= 3) {
			return "Military- Frigate";
		} else if(actualWeaponCount < 3 && actualWeaponCount >= 1) {
			return "Military- Fighter";
		}	
	}
	return null;
}

Now, this is just for aesthetic purposes. But, I have an achievement for each type of ship. So, am I right in thinking that I should be able to unlock the achievements by doing this? Because it crashes.

 

@SubscribeEvent
public static String getShipType(ItemCraftEvent event) {
	if(passengerCapacity > actualCargoCapacity && passengerCapacity > actualWeaponCount) {
		event.player.addStat(Skyline.achievementCivilianCaptain, 1);

 

And so on, obviously I'd do this for the rest of the achievements as well. I've used @SubscribeEvent, and registered it using the FMLCommonHandler. I've used ItemCraftEvent because you need an Event to use this with, so I presumed (and I'm guessing this is where I've gone wrong) that I can just use any event here to add the achievement. When I call this method ingame (by opening the GUI), it crashes, and i get this:

 

---- Minecraft Crash Report ----
// There are four lights!

Time: 28/08/14 18:03
Description: Rendering screen

java.lang.NullPointerException: Rendering screen
at esvdefcon.skyline.chunk.AssembleResult.getShipType(AssembleResult.java:244)
at esvdefcon.skyline.gui.GuiHelm.drawGuiContainerForegroundLayer(GuiHelm.java:218)
at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:138)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1145)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067)
at net.minecraft.client.Minecraft.run(Minecraft.java:961)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at GradleStart.bounce(GradleStart.java:107)
at GradleStart.startClient(GradleStart.java:100)
at GradleStart.main(GradleStart.java:55)


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

-- Head --
Stacktrace:
at esvdefcon.skyline.chunk.AssembleResult.getShipType(AssembleResult.java:244)
at esvdefcon.skyline.gui.GuiHelm.drawGuiContainerForegroundLayer(GuiHelm.java:218)
at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:138)

-- Screen render details --
Details:
Screen name: esvdefcon.skyline.gui.GuiHelm
Mouse location: Scaled: (213, 119). Absolute: (427, 240)
Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['ForgeDevName'/334, l='MpServer', x=50.09, y=75.91, z=421.87]]
Chunk stats: MultiplayerChunkCache: 103, 103
Level seed: 0
Level generator: ID 00 - default, ver 1. Features enabled: false
Level generator options: 
Level spawn location: World: (88,64,256), Chunk: (at 8,4,0 in 5,16; contains blocks 80,0,256 to 95,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 43402 game time, 4241 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 95 total; [EntityZombie['Zombie'/137, l='MpServer', x=9.50, y=37.00, z=436.50], EntityZombie['Zombie'/136, l='MpServer', x=3.50, y=38.00, z=439.50], EntityPig['Pig'/139, l='MpServer', x=7.25, y=64.00, z=432.34], EntityPig['Pig'/138, l='MpServer', x=15.13, y=64.00, z=433.97], EntityHorse['Horse'/141, l='MpServer', x=4.91, y=64.00, z=453.44], EntityPig['Pig'/140, l='MpServer', x=2.09, y=63.00, z=459.03], EntitySkeleton['Skeleton'/129, l='MpServer', x=12.22, y=60.00, z=370.63], EntitySpider['Spider'/128, l='MpServer', x=15.03, y=19.00, z=375.88], EntityZombie['Zombie'/131, l='MpServer', x=15.91, y=44.00, z=414.59], EntitySkeleton['Skeleton'/130, l='MpServer', x=5.47, y=60.00, z=371.78], EntityZombie['Zombie'/133, l='MpServer', x=0.50, y=27.00, z=440.50], EntityHorse['Horse'/132, l='MpServer', x=15.16, y=67.00, z=423.56], EntityZombie['Zombie'/135, l='MpServer', x=1.50, y=38.00, z=437.50], EntityCreeper['Creeper'/134, l='MpServer', x=2.03, y=43.00, z=440.44], EntitySkeleton['Skeleton'/154, l='MpServer', x=29.50, y=28.00, z=379.50], EntityCreeper['Creeper'/155, l='MpServer', x=21.03, y=34.00, z=371.53], EntityBat['Bat'/156, l='MpServer', x=17.25, y=61.10, z=377.34], EntityBat['Bat'/157, l='MpServer', x=29.44, y=35.13, z=393.13], EntityPig['Pig'/158, l='MpServer', x=30.94, y=69.00, z=394.97], EntityClientPlayerMP['ForgeDevName'/334, l='MpServer', x=50.09, y=75.91, z=421.87], EntityPig['Pig'/159, l='MpServer', x=27.84, y=69.00, z=396.53], EntityPig['Pig'/163, l='MpServer', x=30.13, y=64.00, z=419.59], EntitySkeleton['Skeleton'/162, l='MpServer', x=20.91, y=43.00, z=417.34], EntityCreeper['Creeper'/161, l='MpServer', x=20.50, y=46.00, z=426.50], EntitySkeleton['Skeleton'/160, l='MpServer', x=22.00, y=48.00, z=412.69], EntityPig['Pig'/166, l='MpServer', x=17.88, y=64.00, z=450.16], EntityPig['Pig'/165, l='MpServer', x=23.03, y=64.00, z=443.88], EntityPig['Pig'/164, l='MpServer', x=21.50, y=64.00, z=419.50], EntityItem['item.item.rottenFlesh'/178, l='MpServer', x=45.50, y=66.13, z=365.44], EntityBat['Bat'/179, l='MpServer', x=32.25, y=49.10, z=413.75], EntityHorse['Horse'/182, l='MpServer', x=42.28, y=62.00, z=445.22], EntityZombie['Zombie'/183, l='MpServer', x=39.41, y=49.00, z=435.00], EntityBat['Bat'/180, l='MpServer', x=39.47, y=37.16, z=429.58], EntityZombie['Zombie'/181, l='MpServer', x=38.31, y=49.00, z=433.31], EntityCreeper['Creeper'/205, l='MpServer', x=49.00, y=27.00, z=462.56], EntitySquid['Squid'/204, l='MpServer', x=56.50, y=58.25, z=431.96], EntitySquid['Squid'/201, l='MpServer', x=56.01, y=58.65, z=428.50], EntitySquid['Squid'/200, l='MpServer', x=58.37, y=58.00, z=428.50], EntitySquid['Squid'/203, l='MpServer', x=57.23, y=58.28, z=429.08], EntityEnderman['Enderman'/336, l='MpServer', x=47.53, y=14.61, z=500.53], EntityCreeper['Creeper'/202, l='MpServer', x=60.38, y=61.72, z=420.41], EntityBat['Bat'/197, l='MpServer', x=48.42, y=37.23, z=376.72], EntityPig['Pig'/196, l='MpServer', x=61.81, y=68.00, z=353.63], EntitySkeleton['Skeleton'/199, l='MpServer', x=55.09, y=50.00, z=430.44], EntityCow['Cow'/198, l='MpServer', x=56.09, y=67.00, z=377.13], EntityZombie['Zombie'/345, l='MpServer', x=97.78, y=20.85, z=496.53], EntitySkeleton['Skeleton'/326, l='MpServer', x=74.50, y=19.00, z=478.16], EntitySkeleton['Skeleton'/327, l='MpServer', x=71.09, y=21.00, z=493.50], EntityCreeper['Creeper'/325, l='MpServer', x=64.00, y=25.00, z=477.63], EntityCreeper['Creeper'/216, l='MpServer', x=70.22, y=28.00, z=452.09], EntitySpider['Spider'/323, l='MpServer', x=30.56, y=67.00, z=490.63], EntityPig['Pig'/321, l='MpServer', x=-15.78, y=65.00, z=473.19], EntityZombie['Zombie'/93, l='MpServer', x=-27.50, y=12.00, z=406.50], EntityBat['Bat'/212, l='MpServer', x=69.43, y=32.76, z=387.74], EntityZombie['Zombie'/92, l='MpServer', x=-24.50, y=12.00, z=407.50], EntityZombie['Zombie'/335, l='MpServer', x=62.69, y=11.85, z=500.13], EntityBat['Bat'/213, l='MpServer', x=66.71, y=41.70, z=389.02], EntityCreeper['Creeper'/95, l='MpServer', x=-22.35, y=12.00, z=406.78], EntityPig['Pig'/214, l='MpServer', x=65.03, y=64.00, z=408.09], EntitySquid['Squid'/332, l='MpServer', x=90.03, y=59.19, z=470.71], EntityZombie['Zombie'/94, l='MpServer', x=-27.50, y=12.00, z=411.50], EntityZombie['Zombie'/333, l='MpServer', x=91.16, y=23.00, z=491.78], EntityBat['Bat'/215, l='MpServer', x=77.31, y=23.10, z=442.75], EntityPig['Pig'/89, l='MpServer', x=-25.47, y=67.00, z=364.50], EntityCreeper['Creeper'/330, l='MpServer', x=83.50, y=24.00, z=473.97], EntityZombie['Zombie'/331, l='MpServer', x=82.09, y=25.00, z=478.22], EntityCreeper['Creeper'/328, l='MpServer', x=75.41, y=22.00, z=481.84], EntityBat['Bat'/90, l='MpServer', x=-27.25, y=52.05, z=371.63], EntityCreeper['Creeper'/329, l='MpServer', x=76.69, y=22.00, z=483.91], EntitySkeleton['Skeleton'/211, l='MpServer', x=66.50, y=50.00, z=382.50], EntitySkeleton['Skeleton'/100, l='MpServer', x=-26.50, y=32.00, z=403.50], EntityCreeper['Creeper'/98, l='MpServer', x=-27.50, y=27.00, z=408.50], EntitySkeleton['Skeleton'/99, l='MpServer', x=-23.47, y=35.00, z=410.84], EntityCreeper['Creeper'/96, l='MpServer', x=-21.41, y=12.00, z=406.48], EntitySquid['Squid'/233, l='MpServer', x=89.56, y=61.85, z=456.02], EntityBat['Bat'/97, l='MpServer', x=-20.85, y=13.57, z=406.30], EntitySquid['Squid'/232, l='MpServer', x=88.97, y=62.47, z=460.96], EntitySkeleton['Skeleton'/231, l='MpServer', x=94.50, y=22.00, z=453.50], EntityEnderman['Enderman'/110, l='MpServer', x=-8.75, y=40.00, z=417.31], EntityBat['Bat'/230, l='MpServer', x=83.25, y=21.10, z=439.63], EntitySpider['Spider'/111, l='MpServer', x=-10.66, y=64.00, z=428.00], EntityCreeper['Creeper'/108, l='MpServer', x=-13.50, y=40.00, z=414.50], EntityZombie['Zombie'/229, l='MpServer', x=84.44, y=50.00, z=416.44], EntityCow['Cow'/228, l='MpServer', x=87.72, y=63.00, z=380.59], EntitySpider['Spider'/109, l='MpServer', x=-13.44, y=40.00, z=418.13], EntityCreeper['Creeper'/107, l='MpServer', x=-7.94, y=20.00, z=392.41], EntityZombie['Zombie'/112, l='MpServer', x=-6.03, y=39.00, z=437.50], EntityZombie['Zombie'/127, l='MpServer', x=8.50, y=14.00, z=369.50], EntityZombie['Zombie'/126, l='MpServer', x=8.50, y=14.00, z=371.50], EntityBat['Bat'/244, l='MpServer', x=102.08, y=25.48, z=458.59], EntityZombie['Zombie'/125, l='MpServer', x=7.50, y=14.00, z=373.50], EntityZombie['Zombie'/124, l='MpServer', x=6.50, y=14.00, z=374.50], EntityItem['item.item.rottenFlesh'/242, l='MpServer', x=101.78, y=65.13, z=360.78], EntityCreeper['Creeper'/123, l='MpServer', x=10.22, y=23.00, z=365.91], EntityCreeper['Creeper'/243, l='MpServer', x=108.69, y=20.00, z=458.59]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2568)
at net.minecraft.client.Minecraft.run(Minecraft.java:982)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at GradleStart.bounce(GradleStart.java:107)
at GradleStart.startClient(GradleStart.java:100)
at GradleStart.main(GradleStart.java:55)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8 (amd64) version 6.2
Java Version: 1.7.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 873090064 bytes (832 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
skyline{1.0.0 Pre-Alpha} [EsvDefcon's Skyline Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: AMD Radeon HD 7500G GL version 4.2.11764 Compatibility Profile Context, ATI Technologies Inc.
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

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)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

So, is there another way entirely that I should be doing this? Or, if I can do it in this method, what should I replace the current event with to fix this?

 

Thanks :)

Link to comment
Share on other sites

Well, reading your errorlog always helps:

 

java.lang.NullPointerException: Rendering screen
at esvdefcon.skyline.chunk.AssembleResult.getShipType(AssembleResult.java:244)

 

Have a look at the line 244 of the file. It should be within the method getShipType.

One of variables or methods you call there return a null. E.g. what they contain or return is empty.

Check which one it is (by substituting the others until you find which one crashes for instance) and then look at what that method or variable actually does and why it returns null.

 

And you weren't really wrong with ItemCraftEvent. It's just that it's only going to trigger when you have crafted something.

Link to comment
Share on other sites

Thanks :)

 

Line 244 is the line which actually adds the achievement. i tried it with the crafting event (event.player.addstat), and it crashed. So, I got rid of the ItemCraftedEvent altogether (not the method has no parameters), and registered this at the top of my class;

 

public static EntityPlayer entityplayer;

 

Now I can use entityplayer.addStat instead of the method. I also had to replace @SubscribeEvent with @EventHandler.

 

Anyway, like you said, there's a NPE at line 244, which is where the achievement is added. I got the same crash when I used entityplayer. So, from what you're saying, when I go to add the achievement, it's returning null, right? I don't know where to go from here, but I thought that I should mention that I had to return something because it's a string. That's why I returned null at the bottom of the method. I doubt that this is linked, but it's probably worth noting.

 

EDIT: While I'm waiting to see if anyone has any further ideas, I'm going to try calling another method to trigger the achievements, instead of just calling them directly from there.

 

EDIT 2: I get the exact same error, at the line where I trigger the achievement (although it's now inside of a different method). It's definitely a problem with the actual triggering of the achievement. So, I got rid of the new methods, and went back to just adding the achievements from inside of the getShipType method.

Link to comment
Share on other sites

Alright, so now you know which line is returning null. What you have to do now is deduce what is returning a null.

 

Let us analyse the different possibilities.

 

event.player.addStat(Skyline.achievementCivilianCaptain, 1)

 

We clearly only have 2. The addStat and the achievement itself. One of them is null, why?

Looking at addStat we only have 3 possibilities: Either you didn't register it correctly, you're calling the method from somewhere which shouldn't be done(the game calls the method itself when something is crafted, that's what the event is for), or the event doesn't return the player. Of the three, the most likely are 1 & 2.

 

Looking at the achievement itself, well as long as the achievement was created and registered correctly it should be work.

 

So have a look at those two different things. I personally believe you are calling the method instead of letting the event handle it.

 

Or as a last option, I might be wrong as well since I haven't implemented an achievement yet(although I am going to create one now).

Link to comment
Share on other sites

Alright, I agree with you that the most likely is probably that it's because I'm calling it rather than the event calling it. Like I said before, however, I removed the event, and I replaced it with a reference to EntityPlayer. Should I call it differently maybe?

Link to comment
Share on other sites

The problem with declaring an EntityPlayer at the top is that it is empty so even if you add an achievement to that player object it won't show up in the game(if it doesn't crashes because of it, as that also would be a nullpointer because you didn't create a new player) because simply, that player object doesn't contain the current player, it is as simple as that.

 

If I were you I'd set up my event again in my custom eventHandler, choose the event correctly and register it.

If you want to know what all the events are, go to the event class (F3 on any type of event class and then F3 on the eventclass itself) and type ctrl+T for the type hierarchy. For instance, there is a playercontainer event, which is called when a player opens a container.

 

And secondly, don't call the method yourself.

 

 

Link to comment
Share on other sites

The parameter is your event, and I would create a new event handler class for it(don't forget to register it as you normally would). (no idea if it'll trigger with yours but it just might and otherwise there are plenty of other options, look through them)

Then check if the container is your ship inside this method, get the player and check his inventory etc.

Never use a null parameter, it serves no other purpose than to crash the game.

And don't call that event, it'll trigger once the player opens a container. That's how events work, you don't have to call them at a particular point, they trigger when an event happens.

Link to comment
Share on other sites

I've tried some different ways of doing it, but it just seems that the event isn't going to trigger. Here is my code:

 

package esvdefcon.skyline.achievementevent;

import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import esvdefcon.skyline.chunk.AssembleResult;
import esvdefcon.skyline.common.Skyline;

public class OnRegisterShipEvent {

@SubscribeEvent
public static void unlockShipTypeAchievements(PlayerOpenContainerEvent event) {
		if(AssembleResult.passengerCapacity > AssembleResult.actualCargoCapacity && AssembleResult.passengerCapacity > AssembleResult.actualWeaponCount) {
			event.entityPlayer.addStat(Skyline.achievementCivilianCaptain, 1);
			if(AssembleResult.passengerCapacity >= 50) {
				event.entityPlayer.addStat(Skyline.achievementSkylinerCaptain, 1);
			} else if(AssembleResult.passengerCapacity < 50 && AssembleResult.passengerCapacity >= 25) {
				event.entityPlayer.addStat(Skyline.achievementAirshipCaptain, 1);
			} else if(AssembleResult.passengerCapacity < 25 && AssembleResult.passengerCapacity >= 15) {
				event.entityPlayer.addStat(Skyline.achievementLargeShipCaptain, 1);
			} else if(AssembleResult.passengerCapacity < 15 && AssembleResult.passengerCapacity >= 10) {
				event.entityPlayer.addStat(Skyline.achievementMediumShipCaptain, 1);
			} else if(AssembleResult.passengerCapacity < 10 && AssembleResult.passengerCapacity > 0) {
				event.entityPlayer.addStat(Skyline.achievementSmallShipCaptain, 1);
			}
		} else if(AssembleResult.actualCargoCapacity > AssembleResult.passengerCapacity && AssembleResult.actualCargoCapacity > AssembleResult.actualWeaponCount) {
			event.entityPlayer.addStat(Skyline.achievementCivilianCaptain, 1);
			if(AssembleResult.actualCargoCapacity >= 50) {
				event.entityPlayer.addStat(Skyline.achievementFreighterCaptain, 1);
			} else if(AssembleResult.actualCargoCapacity < 50 && AssembleResult.actualCargoCapacity >= 25) {
				event.entityPlayer.addStat(Skyline.achievementCargoShipCaptain, 1);
			} else if(AssembleResult.actualCargoCapacity < 25 && AssembleResult.actualCargoCapacity > 0) {
				event.entityPlayer.addStat(Skyline.achievementTradeShipCaptain, 1);
			}
		} else if(AssembleResult.actualWeaponCount > AssembleResult.passengerCapacity && AssembleResult.actualWeaponCount > AssembleResult.actualCargoCapacity) {
			event.entityPlayer.addStat(Skyline.achievementMilitaryCaptain, 1);
			if(AssembleResult.actualWeaponCount >= 25) {
				event.entityPlayer.addStat(Skyline.achievementDreadnoughtCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 25 && AssembleResult.actualWeaponCount >= 20) {
				event.entityPlayer.addStat(Skyline.achievementBattleshipCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 20 && AssembleResult.actualWeaponCount >= 15) {
				event.entityPlayer.addStat(Skyline.achievementBattlecruiserCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 15 && AssembleResult.actualWeaponCount >= 10) {
				event.entityPlayer.addStat(Skyline.achievementDestroyerCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 10 && AssembleResult.actualWeaponCount >= 5) {
				event.entityPlayer.addStat(Skyline.achievementCruiserCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 5 && AssembleResult.actualWeaponCount >= 3) {
				event.entityPlayer.addStat(Skyline.achievementFrigateCaptain, 1);
			} else if(AssembleResult.actualWeaponCount < 3 && AssembleResult.actualWeaponCount > 0) {
				event.entityPlayer.addStat(Skyline.achievementFighterCaptain, 1);
			}
		}
}
}

I realised that my GUI blocks actually extended BlockDirectional, so I changed it to BlockContainer. However, it's still not triggering everything else is working fine after changing it to BlockContainer, but there's nothing actually happening.

Link to comment
Share on other sites

Well, first of all add a system.out.println("test"); just inside the function (before the if statement).

That way, if it is triggered you'll see it in the console printing test.

Or it might just be that this isn't the correct event you need, in which case you can also make sure the event triggers by opening a chest, which is a container. However, I've told you before how to find the list of events and it is up to you to look through them and find the event that fits your needs perfectly. You'll learn more that way than if I spoon feed you everything.

 

Secondly, have you registered your event in your main class? It won't trigger if isn't registered correctly.

And if you don't know how, look up minecraft forge events in google, I'm sure you'll find the correct line of code for it.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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