mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 19:05:16 +00:00
Add cancellable CorporeaIndexRequestEvent
This commit is contained in:
1 parent
bbbfac82f3
commit
0eaab9a52c
2 files changed
+43
-5
No files matched your search
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* This class was created by <quaternary>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.api.corporea;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* CorporeaIndexRequestEvent is fired when a player attempts to request an item from a corporea index.
|
||||
* If the event is cancelled, the request will not be performed.
|
||||
* */
|
||||
@Cancelable
|
||||
public class CorporeaIndexRequestEvent extends Event {
|
||||
public final EntityPlayerMP requester;
|
||||
public String request;
|
||||
public int requestCount;
|
||||
public ICorporeaSpark indexSpark;
|
||||
|
||||
public CorporeaIndexRequestEvent(EntityPlayerMP requester, String request, int requestCount, ICorporeaSpark indexSpark) {
|
||||
this.requester = requester;
|
||||
this.request = request;
|
||||
this.requestCount = requestCount;
|
||||
this.indexSpark = indexSpark;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -27,6 +28,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.CorporeaIndexRequestEvent;
|
||||
import vazkii.botania.api.corporea.ICorporeaAutoCompleteController;
|
||||
import vazkii.botania.api.corporea.ICorporeaRequestor;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
@@ -269,11 +271,14 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ
|
||||
if(!stack.isEmpty())
|
||||
name = stack.getDisplayName().toLowerCase().trim();
|
||||
}
|
||||
|
||||
index.doCorporeaRequest(name, count, spark);
|
||||
|
||||
event.getPlayer().sendMessage(new TextComponentTranslation("botaniamisc.requestMsg", count, WordUtils.capitalizeFully(name), CorporeaHelper.lastRequestMatches, CorporeaHelper.lastRequestExtractions).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE)));
|
||||
CorporeaRequestTrigger.INSTANCE.trigger(event.getPlayer(), event.getPlayer().getServerWorld(), index.getPos(), CorporeaHelper.lastRequestExtractions);
|
||||
|
||||
CorporeaIndexRequestEvent indexReqEvent = new CorporeaIndexRequestEvent(event.getPlayer(), name, count, spark);
|
||||
if(!MinecraftForge.EVENT_BUS.post(indexReqEvent)) {
|
||||
index.doCorporeaRequest(name, count, spark);
|
||||
|
||||
event.getPlayer().sendMessage(new TextComponentTranslation("botaniamisc.requestMsg", count, WordUtils.capitalizeFully(name), CorporeaHelper.lastRequestMatches, CorporeaHelper.lastRequestExtractions).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE)));
|
||||
CorporeaRequestTrigger.INSTANCE.trigger(event.getPlayer(), event.getPlayer().getServerWorld(), index.getPos(), CorporeaHelper.lastRequestExtractions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user