Skip to content

Commit

Permalink
Add a notification event for handling game rule changes (#5152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bs2609 authored and LexManos committed Oct 4, 2018
1 parent 0fb8844 commit 55a7c6d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/command/CommandGameRule.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/command/CommandGameRule.java
+++ ../src-work/minecraft/net/minecraft/command/CommandGameRule.java
@@ -73,6 +73,7 @@
entityplayermp.field_71135_a.func_147359_a(new SPacketEntityStatus(entityplayermp, b0));
}
}
+ net.minecraftforge.event.ForgeEventFactory.onGameRuleChange(p_184898_0_, p_184898_1_, p_184898_2_);
}

public List<String> func_184883_a(MinecraftServer p_184883_1_, ICommandSender p_184883_2_, String[] p_184883_3_, @Nullable BlockPos p_184883_4_)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Random;

import net.minecraft.block.BlockPortal;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
Expand All @@ -44,6 +43,7 @@
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
Expand All @@ -62,6 +62,7 @@
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.Village;
import net.minecraft.world.Explosion;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
Expand Down Expand Up @@ -793,4 +794,9 @@ public static boolean getMobGriefingEvent(World world, Entity entity)
Result result = event.getResult();
return result == Result.DEFAULT ? world.getGameRules().getBoolean("mobGriefing") : result == Result.ALLOW;
}

public static void onGameRuleChange(GameRules rules, String ruleName, MinecraftServer server)
{
MinecraftForge.EVENT_BUS.post(new GameRuleChangeEvent(rules, ruleName, server));
}
}
59 changes: 59 additions & 0 deletions src/main/java/net/minecraftforge/event/GameRuleChangeEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.event;

import net.minecraft.server.MinecraftServer;
import net.minecraft.world.GameRules;
import net.minecraftforge.fml.common.eventhandler.Event;

/**
* Fired when a game rule is changed,
* via {@link net.minecraft.command.CommandGameRule#notifyGameRuleChange(GameRules, String, MinecraftServer)}.
*
* This allows updating clients with the effects of server rule changes.
*/
public class GameRuleChangeEvent extends Event
{
private final GameRules rules;
private final String ruleName;
private final MinecraftServer server;

public GameRuleChangeEvent(GameRules rules, String ruleName, MinecraftServer server)
{
this.rules = rules;
this.ruleName = ruleName;
this.server = server;
}

public GameRules getRules()
{
return rules;
}

public String getRuleName()
{
return ruleName;
}

public MinecraftServer getServer()
{
return server;
}
}

0 comments on commit 55a7c6d

Please sign in to comment.