mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 13:09:42 +00:00
Merge pull request #2691 from quat1024/eventsAndExtents
Add some events and make things a bit more extensible
This commit is contained in:
3 files changed
+47
-9
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;
|
||||
@@ -281,11 +283,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ import vazkii.botania.api.corporea.InvWithLocation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WrappedIInventory extends WrappedInventoryBase{
|
||||
public class WrappedIInventory extends WrappedInventoryBase {
|
||||
|
||||
private final InvWithLocation inv;
|
||||
protected final InvWithLocation inv;
|
||||
|
||||
private WrappedIInventory(InvWithLocation inv, ICorporeaSpark spark) {
|
||||
protected WrappedIInventory(InvWithLocation inv, ICorporeaSpark spark) {
|
||||
super(spark);
|
||||
this.inv = inv;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class WrappedIInventory extends WrappedInventoryBase{
|
||||
return iterateOverSlots(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit) {
|
||||
protected List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
|
||||
for (int i = inv.handler.getSlots() - 1; i >= 0; i--) {
|
||||
|
||||
Reference in new issue
Block a user