mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Create event for overriding mob griefing flag based on entity. (#4710)
This commit is contained in:
1 parent
247d4cb5a8
commit
b8e411674b
19 files changed
+278
-3
No files matched your search
@@ -82,6 +82,7 @@ import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.brewing.PlayerBrewedPotionEvent;
|
||||
import net.minecraftforge.event.brewing.PotionBrewEvent;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.EntityMobGriefingEvent;
|
||||
import net.minecraftforge.event.entity.EntityMountEvent;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
||||
@@ -756,4 +757,13 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(new GetCollisionBoxesEvent(world, entity, aabb, outList));
|
||||
return outList.isEmpty();
|
||||
}
|
||||
|
||||
public static boolean getMobGriefingEvent(World world, Entity entity)
|
||||
{
|
||||
EntityMobGriefingEvent event = new EntityMobGriefingEvent(entity);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
Result result = event.getResult();
|
||||
return result == Result.DEFAULT ? world.getGameRules().getBoolean("mobGriefing") : result == Result.ALLOW;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 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.entity;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
|
||||
/**
|
||||
* EntityMobGriefingEvent is fired when mob griefing is about to occur and allows an event listener to specify whether it should or not.<br>
|
||||
* This event is fired when ever the {@code mobGriefing} game rule is checked.<br>
|
||||
* <br>
|
||||
* This event has a {@link HasResult result}:
|
||||
* <li>{@link Result#ALLOW} means this instance of mob griefing is allowed.</li>
|
||||
* <li>{@link Result#DEFAULT} means the {@code mobGriefing} game rule is used to determine the behaviour.</li>
|
||||
* <li>{@link Result#DENY} means this instance of mob griefing is not allowed.</li><br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@HasResult
|
||||
public class EntityMobGriefingEvent extends EntityEvent
|
||||
{
|
||||
public EntityMobGriefingEvent(Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user