Added PotionBrewEvent.Pre/Post. To allow for modification and cancelation of Brewing.
This commit is contained in:
parent
44b21681e2
commit
27524a02ae
4 changed files with 127 additions and 6 deletions
|
@ -9,7 +9,14 @@
|
|||
{
|
||||
int j = this.field_145945_j[i].func_77960_j();
|
||||
int k = this.func_145936_c(j, itemstack);
|
||||
@@ -157,7 +157,7 @@
|
||||
@@ -151,13 +151,14 @@
|
||||
|
||||
private void func_145940_l()
|
||||
{
|
||||
+ if (net.minecraftforge.event.ForgeEventFactory.onPotionAttemptBreaw(field_145945_j)) return;
|
||||
if (this.func_145934_k())
|
||||
{
|
||||
ItemStack itemstack = this.field_145945_j[3];
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
|
@ -18,7 +25,7 @@
|
|||
{
|
||||
int j = this.field_145945_j[i].func_77960_j();
|
||||
int k = this.func_145936_c(j, itemstack);
|
||||
@@ -178,9 +178,9 @@
|
||||
@@ -178,9 +179,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,15 +37,15 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
@@ -191,6 +191,7 @@
|
||||
@@ -191,6 +192,7 @@
|
||||
this.field_145945_j[3] = null;
|
||||
}
|
||||
}
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.brewing.PotionBrewedEvent(field_145945_j));
|
||||
+ net.minecraftforge.event.ForgeEventFactory.onPotionBrewed(field_145945_j);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@
|
||||
@@ -306,7 +308,7 @@
|
||||
|
||||
public boolean func_94041_b(int p_94041_1_, ItemStack p_94041_2_)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@ import net.minecraftforge.common.ForgeHooks;
|
|||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.event.brewing.PotionBrewEvent;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
||||
|
@ -385,4 +386,30 @@ public class ForgeEventFactory
|
|||
LivingHealEvent event = new LivingHealEvent(entity, amount);
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.amount);
|
||||
}
|
||||
|
||||
public static boolean onPotionAttemptBreaw(ItemStack[] stacks)
|
||||
{
|
||||
ItemStack[] tmp = new ItemStack[stacks.length];
|
||||
for (int x = 0; x < tmp.length; x++)
|
||||
tmp[x] = stacks[x].copy();
|
||||
|
||||
PotionBrewEvent.Pre event = new PotionBrewEvent.Pre(tmp);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
boolean changed = false;
|
||||
for (int x = 0; x < stacks.length; x++)
|
||||
{
|
||||
changed |= ItemStack.areItemStacksEqual(tmp[x], stacks[x]);
|
||||
stacks[x] = event.getItem(x);
|
||||
}
|
||||
onPotionBrewed(stacks);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onPotionBrewed(ItemStack[] brewingItemStacks)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PotionBrewEvent.Post(brewingItemStacks));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package net.minecraftforge.event.brewing;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
|
||||
|
||||
|
||||
public class PotionBrewEvent extends Event
|
||||
{
|
||||
private ItemStack[] stacks;
|
||||
|
||||
protected PotionBrewEvent(ItemStack[] stacks)
|
||||
{
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
public ItemStack getItem(int index)
|
||||
{
|
||||
if (index >= stacks.length) return null;
|
||||
return stacks[index];
|
||||
}
|
||||
|
||||
public void setItem(int index, ItemStack stack)
|
||||
{
|
||||
if (index < stacks.length)
|
||||
{
|
||||
stacks[index] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
return stacks.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* PotionBrewEvent.Pre is fired before vanilla brewing takes place.
|
||||
* All changes made to the event's array will be made to the TileEntity if the event is canceled.
|
||||
* <br>
|
||||
* The event is fired during the TileEntityBrewingStand#brewPotions() method invocation.<br>
|
||||
* <br>
|
||||
* {@link #brewingStacks} contains the itemstack array from the TileEntityBrewer holding all items in Brewer.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the vanilla brewing will take place instead of modded brewing.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* If this event is canceled, and items have been modified, PotionBrewEvent.Post will automatically be fired.
|
||||
**/
|
||||
@Cancelable
|
||||
public static class Pre extends PotionBrewEvent
|
||||
{
|
||||
public Pre(ItemStack[] stacks)
|
||||
{
|
||||
super(stacks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PotionBrewEvent.Post is fired when a potion is brewed in the brewing stand.
|
||||
* <br>
|
||||
* The event is fired during the TileEntityBrewingStand#brewPotions() method invocation.<br>
|
||||
* <br>
|
||||
* {@link #brewingStacks} contains the itemstack array from the TileEntityBrewer holding all items in Brewer.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class Post extends PotionBrewedEvent
|
||||
{
|
||||
public Post(ItemStack[] stacks)
|
||||
{
|
||||
super(stacks);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,14 +16,18 @@ import net.minecraft.item.ItemStack;
|
|||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class PotionBrewedEvent extends Event
|
||||
@Deprecated
|
||||
public class PotionBrewedEvent extends PotionBrewEvent
|
||||
{
|
||||
/**
|
||||
* The brewing stacks in the brewing stand. Each index has the possibility to be null, so make sure you check.
|
||||
* Changing this array to another one has no effect.
|
||||
*/
|
||||
@Deprecated
|
||||
public ItemStack[] brewingStacks;
|
||||
public PotionBrewedEvent(ItemStack[] brewingStacks)
|
||||
{
|
||||
super(brewingStacks);
|
||||
this.brewingStacks = brewingStacks;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue