Add a few events pertaining to villages (#5302)

This commit is contained in:
Thanh-Phuong authored and tterrag committed 2019-04-24 01:07:02 -04:00
1 parent a4cf5951ca
commit cb0cf2f04f
8 files changed
+338 -1

No files matched your search

@@ -35,6 +35,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityZombie;
@@ -62,6 +63,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.village.Village;
import net.minecraft.world.Explosion;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
@@ -118,6 +121,7 @@ import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.event.terraingen.ChunkGeneratorEvent;
import net.minecraftforge.event.village.MerchantTradeOffersEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent;
@@ -695,4 +699,17 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event.getResult() != Result.DENY;
}
public static MerchantRecipeList listTradeOffers(IMerchant merchant, EntityPlayer player, @Nullable MerchantRecipeList list)
{
MerchantRecipeList dupeList = null;
if (list != null)
{
dupeList = new MerchantRecipeList();
dupeList.addAll(list);
}
MerchantTradeOffersEvent event = new MerchantTradeOffersEvent(merchant, player, dupeList);
MinecraftForge.EVENT_BUS.post(event);
return event.getList();
}
}
@@ -0,0 +1,80 @@
/*
* 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.village;
import javax.annotation.Nullable;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
/**
* MerchantTradeOffersEvent is fired when a list of villager trade offers is presented in
* {@link IMerchant#getRecipes(EntityPlayer)}, allowing mods to modify trade offers depending
* on the player. Be warned that this event is fired on both server and client; thus, modders
* should ensure that they sync the needed data for this event themselves.<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}.
*/
public class MerchantTradeOffersEvent extends Event
{
private final IMerchant merchant;
private final EntityPlayer player;
private @Nullable MerchantRecipeList list;
public MerchantTradeOffersEvent(IMerchant merchant, EntityPlayer player, @Nullable MerchantRecipeList list)
{
this.merchant = merchant;
this.player = player;
this.list = list;
}
/**
* The recipe list (if not {@code null}) returned from this function may be modified.
* @return the recipe list
*/
public @Nullable MerchantRecipeList getList()
{
return list;
}
public void setList(@Nullable MerchantRecipeList list)
{
this.list = list;
}
public IMerchant getMerchant()
{
return merchant;
}
public EntityPlayer getPlayer()
{
return player;
}
}
@@ -0,0 +1,83 @@
/*
* 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.village;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.Vec3d;
import net.minecraft.village.Village;
import net.minecraft.village.VillageSiege;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
/**
* VillageSiegeEvent is fired just before a zombie siege finds a successful location in
* {@link VillageSiege#trySetupSiege}, to give mods the chance to stop the siege.<br>
* <br>
* This event is {@link Cancelable}; canceling stops the siege.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@Cancelable
public class VillageSiegeEvent extends Event
{
private final VillageSiege siege;
private final World world;
private final EntityPlayer player;
private final Village village;
private final Vec3d attemptedSpawnPos;
public VillageSiegeEvent(VillageSiege siege, World world, EntityPlayer player, Village village, Vec3d attemptedSpawnPos)
{
this.siege = siege;
this.world = world;
this.player = player;
this.village = village;
this.attemptedSpawnPos = attemptedSpawnPos;
}
public VillageSiege getSiege()
{
return siege;
}
public World getWorld()
{
return world;
}
public EntityPlayer getPlayer()
{
return player;
}
public Village getVillage()
{
return village;
}
public Vec3d getAttemptedSpawnPos()
{
return attemptedSpawnPos;
}
}