Jump to content

[1.11.2] Checking if the world is paused or not


Recommended Posts

Posted
Minecraft#isGamePaused

will tell you if the game is paused. This can only be called on the client side.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

The

IntegratedServer#isGamePaused

field will also tell you this, but you'll need to access it via reflection.

 

This can only be accessed from the logical server on the physical client. You can read more about sides here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

How do I get the integrated server from a player?

 

Get the player's

World

from the

Entity#world

field, check that

World#isRemote

is

false

(i.e. you're on the logical server), then get the server with

World#getMinecraftServer

.

 

You can check if a server is dedicated or integrated using

MinecraftServer#isDedicatedServer

.

 

Since

IntegratedServer

is a client-only class, you'll need to create a method in your proxy to get the value of

IntegratedServer#isGamePaused

. Return

false

from the server proxy and only reference

IntegratedServer

from the client proxy.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Since

IntegratedServer

is a client-only class, you'll need to create a method in your proxy to get the value of

IntegratedServer#isGamePaused

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 now have this:

	@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
	EntityPlayer player = event.player;
	ICheese cheese = player.getCapability(CheeseProvider.CHEESE_CAP, null);
	Random random = new Random();
	World world = player.world;
	if (!world.isRemote) {
		MinecraftServer server = player.getServer();
		if (!server.isDedicatedServer()) {
			boolean isGamePaused = DeGeweldigeMod.proxy.isGamePaused();
			if (random.nextInt(100) == 0 && !player.isCreative()
					&& world.getWorldInfo().getDifficulty() != EnumDifficulty.PEACEFUL
					&& world.getBiome(player.getPosition()) != CheeseBiomes.CHEESE_BIOME && !isGamePaused) {
				cheese.remove(1);
			}
			if (cheese.get() <= 0 && random.nextInt(25) == 0 && !player.isCreative()
					&& world.getWorldInfo().getDifficulty() != EnumDifficulty.PEACEFUL
					&& world.getBiome(player.getPosition()) != CheeseBiomes.CHEESE_BIOME && !isGamePaused) {
				player.attackEntityFrom(DamageSource.STARVE, 1.5F);
				cheese.set(0);
			}
			if (world.getWorldInfo().getDifficulty() == EnumDifficulty.PEACEFUL && random.nextInt(5) == 0
					&& !isGamePaused) {
				cheese.add(random.nextInt(2));
			}
		}
	}
}

But now it doesn't remove anything... my proxys: Client

	public boolean isGamePaused() {
	IntegratedServer server = Minecraft.getMinecraft().getIntegratedServer();
	return (Boolean) CheeseUtils.getField(IntegratedServer.class, server, "isGamePaused");
}

Common

	public boolean isGamePaused() {
	return false;
}

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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