2016-06-23 03:49:47 +00:00
/ *
* Minecraft Forge
2020-07-02 17:49:11 +00:00
* Copyright ( c ) 2016 - 2020 .
2016-06-23 03:49:47 +00:00
*
* 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
* /
2012-08-06 02:15:13 +00:00
package net.minecraftforge.common ;
2018-09-21 06:50:50 +00:00
import java.lang.reflect.Field ;
2014-12-23 23:04:41 +00:00
import java.net.URI ;
2015-02-17 06:46:55 +00:00
import java.net.URISyntaxException ;
2018-09-21 22:50:37 +00:00
import java.util.Collection ;
2016-05-09 21:15:59 +00:00
import java.util.Deque ;
2019-09-16 21:04:32 +00:00
import java.util.HashMap ;
2016-05-09 21:15:59 +00:00
import java.util.HashSet ;
2013-06-30 12:50:11 +00:00
import java.util.List ;
2019-04-11 12:33:12 +00:00
import java.util.Map ;
2013-12-13 07:32:36 +00:00
import java.util.Set ;
2014-12-23 23:04:41 +00:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2018-09-21 06:50:50 +00:00
import com.google.common.base.Throwables ;
2017-04-07 23:24:59 +00:00
import com.google.common.collect.Lists ;
2016-05-09 21:15:59 +00:00
import com.google.common.collect.Queues ;
import com.google.common.collect.Sets ;
import com.google.gson.Gson ;
2019-01-15 03:23:36 +00:00
import com.google.gson.JsonElement ;
2016-05-09 21:15:59 +00:00
import com.google.gson.JsonObject ;
import com.google.gson.JsonParseException ;
2020-09-15 00:43:01 +00:00
import com.mojang.serialization.codecs.RecordCodecBuilder ;
2019-05-23 23:02:15 +00:00
import javax.annotation.Nonnull ;
import javax.annotation.Nullable ;
2020-11-20 18:23:50 +00:00
import it.unimi.dsi.fastutil.longs.LongSet ;
2017-06-27 22:18:52 +00:00
import net.minecraft.advancements.Advancement ;
2012-12-13 07:27:57 +00:00
import net.minecraft.block.Block ;
2020-09-28 18:01:59 +00:00
import net.minecraft.block.material.Material ;
2019-09-11 14:00:32 +00:00
import net.minecraft.fluid.* ;
2020-06-19 14:58:45 +00:00
import net.minecraft.loot.LootContext ;
import net.minecraft.loot.LootTable ;
import net.minecraft.loot.LootTableManager ;
2020-06-25 01:25:55 +00:00
import net.minecraft.tags.ITag ;
2020-06-19 14:58:45 +00:00
import net.minecraft.util.* ;
2019-05-23 23:02:15 +00:00
import net.minecraft.block.BlockState ;
2016-03-03 10:57:38 +00:00
import net.minecraft.client.Minecraft ;
2019-05-23 23:02:15 +00:00
import net.minecraft.client.gui.screen.Screen ;
2016-10-30 15:53:50 +00:00
import net.minecraft.enchantment.EnchantmentHelper ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
import net.minecraft.entity.Entity ;
2019-05-23 23:02:15 +00:00
import net.minecraft.entity.MobEntity ;
2019-09-03 22:15:48 +00:00
import net.minecraft.entity.SpawnReason ;
2019-05-23 23:02:15 +00:00
import net.minecraft.entity.LivingEntity ;
import net.minecraft.entity.item.ItemEntity ;
import net.minecraft.entity.item.minecart.ContainerMinecartEntity ;
import net.minecraft.entity.player.PlayerEntity ;
import net.minecraft.entity.player.ServerPlayerEntity ;
import net.minecraft.entity.player.PlayerInventory ;
import net.minecraft.block.Blocks ;
import net.minecraft.inventory.container.RepairContainer ;
2014-04-03 01:33:13 +00:00
import net.minecraft.inventory.IInventory ;
2018-03-27 06:25:27 +00:00
import net.minecraft.item.Item ;
2019-05-23 23:02:15 +00:00
import net.minecraft.item.AxeItem ;
import net.minecraft.item.BucketItem ;
import net.minecraft.item.EnchantedBookItem ;
2020-08-04 00:06:36 +00:00
import net.minecraft.item.HoeItem ;
2019-05-23 23:02:15 +00:00
import net.minecraft.item.PickaxeItem ;
import net.minecraft.item.PotionItem ;
import net.minecraft.item.ShovelItem ;
import net.minecraft.item.SpawnEggItem ;
2012-12-13 07:27:57 +00:00
import net.minecraft.item.ItemStack ;
2019-05-23 23:02:15 +00:00
import net.minecraft.item.TippedArrowItem ;
2019-04-24 00:42:08 +00:00
import net.minecraft.item.ItemUseContext ;
2019-05-23 23:02:15 +00:00
import net.minecraft.nbt.CompoundNBT ;
import net.minecraft.nbt.ListNBT ;
import net.minecraft.network.play.ServerPlayNetHandler ;
import net.minecraft.network.IPacket ;
import net.minecraft.network.datasync.IDataSerializer ;
import net.minecraft.network.play.server.SChangeBlockPacket ;
import net.minecraft.potion.Potion ;
2018-03-27 06:25:27 +00:00
import net.minecraft.potion.PotionUtils ;
2019-05-23 23:02:15 +00:00
import net.minecraft.stats.Stats ;
2020-06-19 14:58:45 +00:00
import net.minecraft.util.math.vector.Vector3d ;
import net.minecraft.util.text.* ;
2020-11-20 18:23:50 +00:00
import net.minecraft.world.chunk.IChunk ;
import net.minecraft.world.gen.feature.structure.Structure ;
2019-05-23 23:02:15 +00:00
import net.minecraft.world.spawner.AbstractSpawner ;
2019-09-16 21:04:32 +00:00
import net.minecraft.tileentity.FurnaceTileEntity ;
2013-10-09 00:00:02 +00:00
import net.minecraft.tileentity.TileEntity ;
2020-06-19 17:34:50 +00:00
import net.minecraft.util.SoundEvents ;
2016-03-02 09:44:41 +00:00
import net.minecraft.util.math.AxisAlignedBB ;
2016-03-01 08:31:58 +00:00
import net.minecraft.util.math.BlockPos ;
2016-03-02 09:44:41 +00:00
import net.minecraft.util.math.MathHelper ;
2016-03-03 10:57:38 +00:00
import net.minecraft.util.math.RayTraceResult ;
2019-05-23 23:02:15 +00:00
import net.minecraft.util.math.BlockRayTraceResult ;
import net.minecraft.util.math.EntityRayTraceResult ;
2016-03-02 07:38:31 +00:00
import net.minecraft.util.text.event.ClickEvent ;
2019-05-23 23:02:15 +00:00
import net.minecraft.world.Difficulty ;
2016-06-23 06:39:36 +00:00
import net.minecraft.world.GameType ;
2018-09-21 06:50:50 +00:00
import net.minecraft.world.IBlockReader ;
2018-12-11 06:19:43 +00:00
import net.minecraft.world.IWorld ;
2019-05-23 23:02:15 +00:00
import net.minecraft.world.IWorldReader ;
import net.minecraft.world.World ;
2020-09-15 00:43:01 +00:00
import net.minecraft.world.biome.Biome ;
import net.minecraft.world.biome.BiomeAmbience ;
import net.minecraft.world.biome.BiomeGenerationSettings ;
import net.minecraft.world.biome.MobSpawnInfo ;
2020-07-06 19:41:57 +00:00
import net.minecraftforge.common.loot.IGlobalLootModifier ;
import net.minecraftforge.common.loot.LootModifierManager ;
2019-04-24 00:42:08 +00:00
import net.minecraftforge.common.util.BlockSnapshot ;
2020-09-15 00:43:01 +00:00
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder ;
2020-11-27 23:57:15 +00:00
import net.minecraftforge.common.world.ForgeWorldType ;
2020-09-15 00:43:01 +00:00
import net.minecraftforge.common.world.MobSpawnInfoBuilder ;
2014-04-03 01:33:13 +00:00
import net.minecraftforge.event.AnvilUpdateEvent ;
2017-02-24 02:12:27 +00:00
import net.minecraftforge.event.DifficultyChangeEvent ;
2014-08-27 02:47:22 +00:00
import net.minecraftforge.event.ForgeEventFactory ;
2013-06-30 12:50:11 +00:00
import net.minecraftforge.event.ServerChatEvent ;
2016-01-03 14:21:33 +00:00
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent ;
2012-09-11 22:27:34 +00:00
import net.minecraftforge.event.entity.item.ItemTossEvent ;
2013-06-30 12:50:11 +00:00
import net.minecraftforge.event.entity.living.LivingAttackEvent ;
2017-10-31 22:29:19 +00:00
import net.minecraftforge.event.entity.living.LivingDamageEvent ;
2013-06-30 12:50:11 +00:00
import net.minecraftforge.event.entity.living.LivingDeathEvent ;
import net.minecraftforge.event.entity.living.LivingDropsEvent ;
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent ;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent ;
import net.minecraftforge.event.entity.living.LivingFallEvent ;
import net.minecraftforge.event.entity.living.LivingHurtEvent ;
2017-12-17 02:03:45 +00:00
import net.minecraftforge.event.entity.living.LivingKnockBackEvent ;
2013-06-30 12:50:11 +00:00
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent ;
2016-07-03 13:19:31 +00:00
import net.minecraftforge.event.entity.living.LootingLevelEvent ;
2019-05-23 23:02:15 +00:00
import net.minecraftforge.event.entity.player.AdvancementEvent ;
2014-08-04 20:54:35 +00:00
import net.minecraftforge.event.entity.player.AnvilRepairEvent ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
import net.minecraftforge.event.entity.player.AttackEntityEvent ;
2017-08-01 19:13:37 +00:00
import net.minecraftforge.event.entity.player.CriticalHitEvent ;
2016-11-16 23:10:14 +00:00
import net.minecraftforge.event.entity.player.PlayerEvent ;
2016-04-05 00:58:46 +00:00
import net.minecraftforge.event.entity.player.PlayerInteractEvent ;
2020-09-15 00:43:01 +00:00
import net.minecraftforge.event.world.BiomeLoadingEvent ;
2013-10-09 00:00:02 +00:00
import net.minecraftforge.event.world.BlockEvent ;
2014-06-02 23:57:04 +00:00
import net.minecraftforge.event.world.NoteBlockEvent ;
2018-12-11 06:19:43 +00:00
import net.minecraftforge.eventbus.api.Event.Result ;
2019-09-11 14:00:32 +00:00
import net.minecraftforge.fluids.FluidAttributes ;
2020-07-20 22:56:21 +00:00
import net.minecraftforge.fml.packs.ResourcePackLoader ;
2019-04-11 12:33:12 +00:00
import net.minecraftforge.registries.DataSerializerEntry ;
2019-05-23 23:02:15 +00:00
import net.minecraftforge.registries.ForgeRegistries ;
2019-04-11 12:33:12 +00:00
import net.minecraftforge.registries.ForgeRegistry ;
import net.minecraftforge.registries.GameData ;
2019-09-16 21:04:32 +00:00
import net.minecraftforge.registries.IRegistryDelegate ;
2018-06-21 19:37:32 +00:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
import org.apache.logging.log4j.Marker ;
import org.apache.logging.log4j.MarkerManager ;
2018-09-21 06:50:50 +00:00
import org.apache.logging.log4j.util.TriConsumer ;
2017-06-27 22:18:52 +00:00
2012-08-06 02:15:13 +00:00
public class ForgeHooks
{
2018-08-27 17:10:07 +00:00
private static final Logger LOGGER = LogManager . getLogger ( ) ;
2020-08-14 19:04:55 +00:00
@SuppressWarnings ( " unused " )
2018-06-21 19:37:32 +00:00
private static final Marker FORGEHOOKS = MarkerManager . getMarker ( " FORGEHOOKS " ) ;
2012-09-09 14:02:21 +00:00
2019-04-23 19:12:55 +00:00
public static boolean canContinueUsing ( @Nonnull ItemStack from , @Nonnull ItemStack to )
{
if ( ! from . isEmpty ( ) & & ! to . isEmpty ( ) )
{
return from . getItem ( ) . canContinueUsing ( from , to ) ;
}
return false ;
}
2019-05-23 23:02:15 +00:00
public static boolean canHarvestBlock ( @Nonnull BlockState state , @Nonnull PlayerEntity player , @Nonnull IBlockReader world , @Nonnull BlockPos pos )
2012-08-06 10:35:57 +00:00
{
2018-09-21 06:50:50 +00:00
//state = state.getActualState(world, pos);
2020-10-29 00:11:57 +00:00
if ( ! state . getRequiresTool ( ) )
2020-11-10 19:36:32 +00:00
return ForgeEventFactory . doPlayerHarvestCheck ( player , state , true ) ;
2012-08-11 21:45:48 +00:00
2016-11-22 23:20:05 +00:00
ItemStack stack = player . getHeldItemMainhand ( ) ;
2018-09-21 06:50:50 +00:00
ToolType tool = state . getHarvestTool ( ) ;
2016-12-21 23:52:30 +00:00
if ( stack . isEmpty ( ) | | tool = = null )
2020-06-26 22:40:05 +00:00
return player . func_234569_d_ ( state ) ;
2012-08-06 10:35:57 +00:00
2020-09-08 20:01:26 +00:00
int toolLevel = stack . getHarvestLevel ( tool , player , state ) ;
2013-12-21 08:10:35 +00:00
if ( toolLevel < 0 )
2020-06-26 22:40:05 +00:00
return player . func_234569_d_ ( state ) ;
2012-08-11 21:45:48 +00:00
2020-05-03 20:40:34 +00:00
return ForgeEventFactory . doPlayerHarvestCheck ( player , state , toolLevel > = state . getHarvestLevel ( ) ) ;
2012-08-06 10:35:57 +00:00
}
2013-04-10 20:37:25 +00:00
2018-09-14 16:30:56 +00:00
public static boolean isToolEffective ( IWorldReader world , BlockPos pos , @Nonnull ItemStack stack )
2012-08-06 10:35:57 +00:00
{
2019-05-23 23:02:15 +00:00
BlockState state = world . getBlockState ( pos ) ;
2018-09-21 06:50:50 +00:00
//state = state.getActualState(world, pos);
for ( ToolType type : stack . getToolTypes ( ) )
2013-12-21 08:10:35 +00:00
{
2018-09-21 06:50:50 +00:00
if ( state . isToolEffective ( type ) )
2013-12-21 08:10:35 +00:00
return true ;
}
return false ;
2012-08-06 10:35:57 +00:00
}
2012-09-09 14:02:21 +00:00
2018-09-21 06:50:50 +00:00
private static boolean toolInit = false ;
2012-08-06 10:35:57 +00:00
static void initTools ( )
{
if ( toolInit )
return ;
toolInit = true ;
2019-05-23 23:02:15 +00:00
Set < Block > blocks = getPrivateValue ( PickaxeItem . class , null , 0 ) ;
2018-09-21 06:50:50 +00:00
blocks . forEach ( block - > blockToolSetter . accept ( block , ToolType . PICKAXE , 0 ) ) ;
2019-05-23 23:02:15 +00:00
blocks = getPrivateValue ( ShovelItem . class , null , 0 ) ;
2018-09-21 06:50:50 +00:00
blocks . forEach ( block - > blockToolSetter . accept ( block , ToolType . SHOVEL , 0 ) ) ;
2020-09-28 18:01:59 +00:00
//Axes check Materials and Blocks now.
Set < Material > materials = getPrivateValue ( AxeItem . class , null , 0 ) ;
for ( Block block : ForgeRegistries . BLOCKS )
if ( materials . contains ( block . getDefaultState ( ) . getMaterial ( ) ) )
blockToolSetter . accept ( block , ToolType . AXE , 0 ) ;
2020-06-24 00:56:24 +00:00
blocks = getPrivateValue ( AxeItem . class , null , 1 ) ;
2018-09-21 06:50:50 +00:00
blocks . forEach ( block - > blockToolSetter . accept ( block , ToolType . AXE , 0 ) ) ;
2020-08-04 00:06:36 +00:00
blocks = getPrivateValue ( HoeItem . class , null , 0 ) ;
blocks . forEach ( block - > blockToolSetter . accept ( block , ToolType . HOE , 0 ) ) ;
2013-12-21 08:10:35 +00:00
2020-08-04 00:06:36 +00:00
//This is taken from PickaxeItem, if that changes update here.
2020-10-29 00:11:57 +00:00
for ( Block block : new Block [ ] { Blocks . OBSIDIAN , Blocks . CRYING_OBSIDIAN , Blocks . NETHERITE_BLOCK , Blocks . RESPAWN_ANCHOR , Blocks . ANCIENT_DEBRIS } )
2020-08-04 00:06:36 +00:00
blockToolSetter . accept ( block , ToolType . PICKAXE , 3 ) ;
2018-09-21 06:50:50 +00:00
for ( Block block : new Block [ ] { Blocks . DIAMOND_BLOCK , Blocks . DIAMOND_ORE , Blocks . EMERALD_ORE , Blocks . EMERALD_BLOCK , Blocks . GOLD_BLOCK , Blocks . GOLD_ORE , Blocks . REDSTONE_ORE } )
blockToolSetter . accept ( block , ToolType . PICKAXE , 2 ) ;
for ( Block block : new Block [ ] { Blocks . IRON_BLOCK , Blocks . IRON_ORE , Blocks . LAPIS_BLOCK , Blocks . LAPIS_ORE } )
blockToolSetter . accept ( block , ToolType . PICKAXE , 1 ) ;
2012-08-06 10:35:57 +00:00
}
2012-08-10 09:09:11 +00:00
/ * *
* Called when a player uses ' pick block ' , calls new Entity and Block hooks .
* /
2020-08-14 19:04:55 +00:00
@SuppressWarnings ( " resource " )
2019-05-23 23:02:15 +00:00
public static boolean onPickBlock ( RayTraceResult target , PlayerEntity player , World world )
2012-08-10 09:09:11 +00:00
{
2019-05-23 23:02:15 +00:00
ItemStack result = ItemStack . EMPTY ;
2019-06-22 02:42:16 +00:00
boolean isCreative = player . abilities . isCreativeMode ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
TileEntity te = null ;
2012-08-10 09:09:11 +00:00
2019-06-08 14:45:28 +00:00
if ( target . getType ( ) = = RayTraceResult . Type . BLOCK )
2012-08-10 09:09:11 +00:00
{
2019-06-08 14:45:28 +00:00
BlockPos pos = ( ( BlockRayTraceResult ) target ) . getPos ( ) ;
2019-05-23 23:02:15 +00:00
BlockState state = world . getBlockState ( pos ) ;
2012-08-10 09:09:11 +00:00
2019-05-23 23:02:15 +00:00
if ( state . isAir ( world , pos ) )
2012-08-10 09:09:11 +00:00
return false ;
2020-10-29 00:11:57 +00:00
if ( isCreative & & Screen . hasControlDown ( ) & & state . hasTileEntity ( ) )
2019-05-23 23:02:15 +00:00
te = world . getTileEntity ( pos ) ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
2020-07-06 20:19:53 +00:00
result = state . getPickBlock ( target , world , pos , player ) ;
2019-05-23 23:02:15 +00:00
if ( result . isEmpty ( ) )
2019-06-08 14:45:28 +00:00
LOGGER . warn ( " Picking on: [{}] {} gave null item " , target . getType ( ) , state . getBlock ( ) . getRegistryName ( ) ) ;
2012-08-10 09:09:11 +00:00
}
2019-06-08 14:45:28 +00:00
else if ( target . getType ( ) = = RayTraceResult . Type . ENTITY )
2012-08-10 09:09:11 +00:00
{
2019-06-08 14:45:28 +00:00
Entity entity = ( ( EntityRayTraceResult ) target ) . getEntity ( ) ;
2019-05-23 23:02:15 +00:00
result = entity . getPickedResult ( target ) ;
2012-08-10 09:09:11 +00:00
2019-05-23 23:02:15 +00:00
if ( result . isEmpty ( ) )
2019-06-08 14:45:28 +00:00
LOGGER . warn ( " Picking on: [{}] {} gave null item " , target . getType ( ) , entity . getType ( ) . getRegistryName ( ) ) ;
2012-08-10 09:09:11 +00:00
}
2016-12-21 23:52:30 +00:00
if ( result . isEmpty ( ) )
2012-08-10 09:09:11 +00:00
return false ;
2016-03-03 10:57:38 +00:00
if ( te ! = null )
2018-09-22 10:40:22 +00:00
Minecraft . getInstance ( ) . storeTEInStack ( result , te ) ;
2012-08-10 09:09:11 +00:00
2016-03-03 10:57:38 +00:00
if ( isCreative )
2012-08-10 09:09:11 +00:00
{
2016-05-18 12:11:56 +00:00
player . inventory . setPickedItemStack ( result ) ;
2019-06-22 02:42:16 +00:00
Minecraft . getInstance ( ) . playerController . sendSlotPacket ( player . getHeldItem ( Hand . MAIN_HAND ) , 36 + player . inventory . currentItem ) ;
2016-03-03 10:57:38 +00:00
return true ;
2012-08-10 09:09:11 +00:00
}
2016-03-13 01:40:03 +00:00
int slot = player . inventory . getSlotFor ( result ) ;
2016-03-03 10:57:38 +00:00
if ( slot ! = - 1 )
2012-08-10 09:09:11 +00:00
{
2019-05-23 23:02:15 +00:00
if ( PlayerInventory . isHotbar ( slot ) )
2016-03-03 10:57:38 +00:00
player . inventory . currentItem = slot ;
else
2019-06-22 02:42:16 +00:00
Minecraft . getInstance ( ) . playerController . pickItem ( slot ) ;
2016-03-03 10:57:38 +00:00
return true ;
2012-08-10 09:09:11 +00:00
}
2016-03-03 10:57:38 +00:00
return false ;
2012-08-10 09:09:11 +00:00
}
2017-06-02 23:22:16 +00:00
2019-05-23 23:02:15 +00:00
public static void onDifficultyChange ( Difficulty difficulty , Difficulty oldDifficulty )
2017-02-24 02:12:27 +00:00
{
MinecraftForge . EVENT_BUS . post ( new DifficultyChangeEvent ( difficulty , oldDifficulty ) ) ;
}
2012-08-23 01:02:14 +00:00
//Optifine Helper Functions u.u, these are here specifically for Optifine
2016-03-23 14:34:48 +00:00
//Note: When using Optifine, these methods are invoked using reflection, which
2012-08-23 01:02:14 +00:00
//incurs a major performance penalty.
2019-05-23 23:02:15 +00:00
public static void onLivingSetAttackTarget ( LivingEntity entity , LivingEntity target )
2012-08-23 01:02:14 +00:00
{
MinecraftForge . EVENT_BUS . post ( new LivingSetAttackTargetEvent ( entity , target ) ) ;
}
2019-05-23 23:02:15 +00:00
public static boolean onLivingUpdate ( LivingEntity entity )
2012-08-23 01:02:14 +00:00
{
return MinecraftForge . EVENT_BUS . post ( new LivingUpdateEvent ( entity ) ) ;
}
2019-05-23 23:02:15 +00:00
public static boolean onLivingAttack ( LivingEntity entity , DamageSource src , float amount )
2018-04-01 08:12:46 +00:00
{
2019-05-23 23:02:15 +00:00
return entity instanceof PlayerEntity | | ! MinecraftForge . EVENT_BUS . post ( new LivingAttackEvent ( entity , src , amount ) ) ;
2018-04-01 08:12:46 +00:00
}
2019-05-23 23:02:15 +00:00
public static boolean onPlayerAttack ( LivingEntity entity , DamageSource src , float amount )
2012-08-23 01:02:14 +00:00
{
2014-11-28 15:43:10 +00:00
return ! MinecraftForge . EVENT_BUS . post ( new LivingAttackEvent ( entity , src , amount ) ) ;
2012-08-23 01:02:14 +00:00
}
2020-08-13 07:13:48 +00:00
public static LivingKnockBackEvent onLivingKnockBack ( LivingEntity target , float strength , double ratioX , double ratioZ )
2017-12-17 02:03:45 +00:00
{
2020-08-13 07:13:48 +00:00
LivingKnockBackEvent event = new LivingKnockBackEvent ( target , strength , ratioX , ratioZ ) ;
2017-12-17 02:03:45 +00:00
MinecraftForge . EVENT_BUS . post ( event ) ;
return event ;
}
2019-05-23 23:02:15 +00:00
public static float onLivingHurt ( LivingEntity entity , DamageSource src , float amount )
2012-08-23 01:02:14 +00:00
{
LivingHurtEvent event = new LivingHurtEvent ( entity , src , amount ) ;
2016-03-23 14:34:48 +00:00
return ( MinecraftForge . EVENT_BUS . post ( event ) ? 0 : event . getAmount ( ) ) ;
2012-08-23 01:02:14 +00:00
}
2019-05-23 23:02:15 +00:00
public static float onLivingDamage ( LivingEntity entity , DamageSource src , float amount )
2017-10-31 22:29:19 +00:00
{
LivingDamageEvent event = new LivingDamageEvent ( entity , src , amount ) ;
return ( MinecraftForge . EVENT_BUS . post ( event ) ? 0 : event . getAmount ( ) ) ;
}
2019-05-23 23:02:15 +00:00
public static boolean onLivingDeath ( LivingEntity entity , DamageSource src )
2012-08-23 01:02:14 +00:00
{
return MinecraftForge . EVENT_BUS . post ( new LivingDeathEvent ( entity , src ) ) ;
}
2019-05-23 23:02:15 +00:00
public static boolean onLivingDrops ( LivingEntity entity , DamageSource source , Collection < ItemEntity > drops , int lootingLevel , boolean recentlyHit )
2012-08-23 01:02:14 +00:00
{
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
return MinecraftForge . EVENT_BUS . post ( new LivingDropsEvent ( entity , source , drops , lootingLevel , recentlyHit ) ) ;
2012-08-23 01:02:14 +00:00
}
2016-11-17 18:44:31 +00:00
@Nullable
2019-05-23 23:02:15 +00:00
public static float [ ] onLivingFall ( LivingEntity entity , float distance , float damageMultiplier )
2012-08-23 01:02:14 +00:00
{
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
LivingFallEvent event = new LivingFallEvent ( entity , distance , damageMultiplier ) ;
2016-03-24 08:44:52 +00:00
return ( MinecraftForge . EVENT_BUS . post ( event ) ? null : new float [ ] { event . getDistance ( ) , event . getDamageMultiplier ( ) } ) ;
2012-08-23 01:02:14 +00:00
}
2017-01-11 23:17:56 +00:00
public static int getLootingLevel ( Entity target , @Nullable Entity killer , DamageSource cause )
2016-10-30 15:53:50 +00:00
{
int looting = 0 ;
2019-05-23 23:02:15 +00:00
if ( killer instanceof LivingEntity )
looting = EnchantmentHelper . getLootingModifier ( ( LivingEntity ) killer ) ;
if ( target instanceof LivingEntity )
looting = getLootingLevel ( ( LivingEntity ) target , cause , looting ) ;
2016-10-30 15:53:50 +00:00
return looting ;
}
2019-05-23 23:02:15 +00:00
public static int getLootingLevel ( LivingEntity target , DamageSource cause , int level )
2016-10-30 15:53:50 +00:00
{
2016-07-03 13:19:31 +00:00
LootingLevelEvent event = new LootingLevelEvent ( target , cause , level ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
return event . getLootingLevel ( ) ;
}
2019-05-23 23:02:15 +00:00
public static double getPlayerVisibilityDistance ( PlayerEntity player , double xzDistance , double maxXZDistance )
2016-11-16 23:10:14 +00:00
{
PlayerEvent . Visibility event = new PlayerEvent . Visibility ( player ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
double value = event . getVisibilityModifier ( ) * xzDistance ;
return value > = maxXZDistance ? maxXZDistance : value ;
}
2019-05-23 23:02:15 +00:00
public static boolean isLivingOnLadder ( @Nonnull BlockState state , @Nonnull World world , @Nonnull BlockPos pos , @Nonnull LivingEntity entity )
2013-06-14 18:51:28 +00:00
{
2019-05-23 23:02:15 +00:00
boolean isSpectator = ( entity instanceof PlayerEntity & & ( ( PlayerEntity ) entity ) . isSpectator ( ) ) ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
if ( isSpectator ) return false ;
2019-02-10 21:38:14 +00:00
if ( ! ForgeConfig . SERVER . fullBoundingBoxLadders . get ( ) )
2013-08-11 02:39:06 +00:00
{
2019-06-25 03:05:50 +00:00
return state . isLadder ( world , pos , entity ) ;
2013-08-11 02:39:06 +00:00
}
else
{
2018-09-22 10:40:22 +00:00
AxisAlignedBB bb = entity . getBoundingBox ( ) ;
2016-12-21 23:52:30 +00:00
int mX = MathHelper . floor ( bb . minX ) ;
int mY = MathHelper . floor ( bb . minY ) ;
int mZ = MathHelper . floor ( bb . minZ ) ;
2013-09-25 05:46:18 +00:00
for ( int y2 = mY ; y2 < bb . maxY ; y2 + + )
2013-08-11 02:39:06 +00:00
{
for ( int x2 = mX ; x2 < bb . maxX ; x2 + + )
{
for ( int z2 = mZ ; z2 < bb . maxZ ; z2 + + )
{
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
BlockPos tmp = new BlockPos ( x2 , y2 , z2 ) ;
2016-03-08 07:34:40 +00:00
state = world . getBlockState ( tmp ) ;
2019-06-25 03:05:50 +00:00
if ( state . isLadder ( world , tmp , entity ) )
2013-08-11 02:39:06 +00:00
{
return true ;
}
}
}
}
return false ;
}
2013-06-14 18:51:28 +00:00
}
2012-08-23 01:02:14 +00:00
2019-05-23 23:02:15 +00:00
public static void onLivingJump ( LivingEntity entity )
2012-08-23 01:02:14 +00:00
{
MinecraftForge . EVENT_BUS . post ( new LivingJumpEvent ( entity ) ) ;
}
2012-09-11 22:27:34 +00:00
2017-01-11 23:17:56 +00:00
@Nullable
2019-05-23 23:02:15 +00:00
public static ItemEntity onPlayerTossEvent ( @Nonnull PlayerEntity player , @Nonnull ItemStack item , boolean includeName )
2012-09-11 22:27:34 +00:00
{
2018-09-21 22:50:37 +00:00
player . captureDrops ( Lists . newArrayList ( ) ) ;
2019-05-23 23:02:15 +00:00
ItemEntity ret = player . dropItem ( item , false , includeName ) ;
2018-09-21 22:50:37 +00:00
player . captureDrops ( null ) ;
2012-09-11 22:27:34 +00:00
2013-08-19 17:45:57 +00:00
if ( ret = = null )
return null ;
2012-09-11 22:27:34 +00:00
ItemTossEvent event = new ItemTossEvent ( ret , player ) ;
if ( MinecraftForge . EVENT_BUS . post ( event ) )
return null ;
2016-12-21 23:52:30 +00:00
if ( ! player . world . isRemote )
2019-06-22 02:42:16 +00:00
player . getEntityWorld ( ) . addEntity ( event . getEntityItem ( ) ) ;
2016-03-24 08:44:52 +00:00
return event . getEntityItem ( ) ;
2012-09-11 22:27:34 +00:00
}
2013-04-10 23:56:31 +00:00
2017-01-11 23:17:56 +00:00
@Nullable
2019-05-23 23:02:15 +00:00
public static ITextComponent onServerChatEvent ( ServerPlayNetHandler net , String raw , ITextComponent comp )
2013-06-30 12:50:11 +00:00
{
2019-06-22 02:42:16 +00:00
ServerChatEvent event = new ServerChatEvent ( net . player , raw , comp ) ;
2013-06-30 12:50:11 +00:00
if ( MinecraftForge . EVENT_BUS . post ( event ) )
{
return null ;
}
2016-03-02 07:38:31 +00:00
return event . getComponent ( ) ;
2013-06-30 12:50:11 +00:00
}
2013-12-28 02:26:42 +00:00
2014-12-23 23:04:41 +00:00
static final Pattern URL_PATTERN = Pattern . compile (
2016-05-04 17:46:33 +00:00
// schema ipv4 OR namespace port path ends
// |-----------------| |-------------------------| |-------------------------| |---------| |--| |---------------|
" ((?:[a-z0-9]{2,}: \\ / \\ /)?(?:(?:[0-9]{1,3} \\ .){3}[0-9]{1,3}|(?:[- \\ w_]{1,} \\ .[a-z]{2,}?))(?::[0-9]{1,5})?.*?(?=[! \" \ u00A7 \ n]|$)) " ,
2014-12-23 23:04:41 +00:00
Pattern . CASE_INSENSITIVE ) ;
2016-03-01 12:58:03 +00:00
public static ITextComponent newChatWithLinks ( String string ) { return newChatWithLinks ( string , true ) ; }
public static ITextComponent newChatWithLinks ( String string , boolean allowMissingHeader )
2014-12-23 23:04:41 +00:00
{
// Includes ipv4 and domain pattern
// Matches an ip (xx.xxx.xx.xxx) or a domain (something.com) with or
// without a protocol or path.
2020-06-19 14:58:45 +00:00
IFormattableTextComponent ichat = null ;
2014-12-23 23:04:41 +00:00
Matcher matcher = URL_PATTERN . matcher ( string ) ;
int lastEnd = 0 ;
// Find all urls
while ( matcher . find ( ) )
{
int start = matcher . start ( ) ;
int end = matcher . end ( ) ;
// Append the previous left overs.
2015-11-04 21:57:47 +00:00
String part = string . substring ( lastEnd , start ) ;
if ( part . length ( ) > 0 )
{
if ( ichat = = null )
2019-05-23 23:02:15 +00:00
ichat = new StringTextComponent ( part ) ;
2015-11-04 21:57:47 +00:00
else
2020-10-29 00:11:57 +00:00
ichat . appendString ( part ) ;
2015-11-04 21:57:47 +00:00
}
2014-12-23 23:04:41 +00:00
lastEnd = end ;
String url = string . substring ( start , end ) ;
2020-06-19 14:58:45 +00:00
IFormattableTextComponent link = new StringTextComponent ( url ) ;
2014-12-23 23:04:41 +00:00
2015-02-17 06:46:55 +00:00
try
2014-12-23 23:04:41 +00:00
{
2015-02-17 06:46:55 +00:00
// Add schema so client doesn't crash.
if ( ( new URI ( url ) ) . getScheme ( ) = = null )
2015-11-04 21:57:47 +00:00
{
if ( ! allowMissingHeader )
{
if ( ichat = = null )
2019-05-23 23:02:15 +00:00
ichat = new StringTextComponent ( url ) ;
2015-11-04 21:57:47 +00:00
else
2020-10-29 00:11:57 +00:00
ichat . appendString ( url ) ;
2015-11-04 21:57:47 +00:00
continue ;
}
2015-02-17 06:46:55 +00:00
url = " http:// " + url ;
2015-11-04 21:57:47 +00:00
}
2015-02-17 06:46:55 +00:00
}
catch ( URISyntaxException e )
{
// Bad syntax bail out!
2019-05-23 23:02:15 +00:00
if ( ichat = = null ) ichat = new StringTextComponent ( url ) ;
2020-10-29 00:11:57 +00:00
else ichat . appendString ( url ) ;
2015-02-17 06:46:55 +00:00
continue ;
2014-12-23 23:04:41 +00:00
}
// Set the click event and append the link.
ClickEvent click = new ClickEvent ( ClickEvent . Action . OPEN_URL , url ) ;
2020-10-29 00:11:57 +00:00
link . setStyle ( link . getStyle ( ) . setClickEvent ( click ) . setUnderlined ( true ) . setColor ( Color . fromTextFormatting ( TextFormatting . BLUE ) ) ) ;
2015-11-04 21:57:47 +00:00
if ( ichat = = null )
2019-07-08 22:46:49 +00:00
ichat = new StringTextComponent ( " " ) ;
2020-10-29 00:11:57 +00:00
ichat . append ( link ) ;
2014-12-23 23:04:41 +00:00
}
// Append the rest of the message.
2015-11-04 21:57:47 +00:00
String end = string . substring ( lastEnd ) ;
if ( ichat = = null )
2019-05-23 23:02:15 +00:00
ichat = new StringTextComponent ( end ) ;
2015-11-04 21:57:47 +00:00
else if ( end . length ( ) > 0 )
2020-10-29 00:11:57 +00:00
ichat . append ( new StringTextComponent ( string . substring ( lastEnd ) ) ) ;
2014-12-23 23:04:41 +00:00
return ichat ;
}
2019-05-23 23:02:15 +00:00
public static int onBlockBreakEvent ( World world , GameType gameType , ServerPlayerEntity entityPlayer , BlockPos pos )
2013-10-09 00:00:02 +00:00
{
// Logic from tryHarvestBlock for pre-canceling the event
boolean preCancelEvent = false ;
2017-04-07 23:59:21 +00:00
ItemStack itemstack = entityPlayer . getHeldItemMainhand ( ) ;
2019-09-16 20:36:43 +00:00
if ( ! itemstack . isEmpty ( ) & & ! itemstack . getItem ( ) . canPlayerBreakBlockWhileHolding ( world . getBlockState ( pos ) , world , pos , entityPlayer ) )
{
2013-10-09 00:00:02 +00:00
preCancelEvent = true ;
2019-09-16 20:36:43 +00:00
}
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
2017-10-04 05:08:36 +00:00
if ( gameType . hasLimitedInteractions ( ) )
2013-10-09 00:00:02 +00:00
{
2016-06-23 06:39:36 +00:00
if ( gameType = = GameType . SPECTATOR )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
preCancelEvent = true ;
2014-12-02 03:11:17 +00:00
if ( ! entityPlayer . isAllowEdit ( ) )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
2019-05-23 23:02:15 +00:00
if ( itemstack . isEmpty ( ) | | ! itemstack . canDestroy ( world . getTags ( ) , new CachedBlockInfo ( world , pos , false ) ) )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
preCancelEvent = true ;
}
2013-10-09 00:00:02 +00:00
}
// Tell client the block is gone immediately then process events
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
if ( world . getTileEntity ( pos ) = = null )
2013-10-09 00:00:02 +00:00
{
2019-05-23 23:02:15 +00:00
entityPlayer . connection . sendPacket ( new SChangeBlockPacket ( DUMMY_WORLD , pos ) ) ;
2013-10-09 00:00:02 +00:00
}
// Post the block break event
2019-05-23 23:02:15 +00:00
BlockState state = world . getBlockState ( pos ) ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
BlockEvent . BreakEvent event = new BlockEvent . BreakEvent ( world , pos , state , entityPlayer ) ;
2013-10-09 00:00:02 +00:00
event . setCanceled ( preCancelEvent ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
// Handle if the event is canceled
if ( event . isCanceled ( ) )
{
// Let the client know the block still exists
2019-05-23 23:02:15 +00:00
entityPlayer . connection . sendPacket ( new SChangeBlockPacket ( world , pos ) ) ;
2013-12-28 02:26:42 +00:00
2013-10-09 00:00:02 +00:00
// Update any tile entity data for this block
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
TileEntity tileentity = world . getTileEntity ( pos ) ;
2013-10-09 00:00:02 +00:00
if ( tileentity ! = null )
{
2019-05-23 23:02:15 +00:00
IPacket < ? > pkt = tileentity . getUpdatePacket ( ) ;
2013-11-16 23:26:00 +00:00
if ( pkt ! = null )
{
2016-05-18 12:11:56 +00:00
entityPlayer . connection . sendPacket ( pkt ) ;
2013-11-16 23:26:00 +00:00
}
2013-10-09 00:00:02 +00:00
}
}
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
return event . isCanceled ( ) ? - 1 : event . getExpToDrop ( ) ;
2013-10-09 00:00:02 +00:00
}
2014-04-03 01:33:13 +00:00
2019-05-23 23:02:15 +00:00
public static ActionResultType onPlaceItemIntoWorld ( @Nonnull ItemUseContext context )
2014-08-27 02:47:22 +00:00
{
2018-09-22 10:40:22 +00:00
ItemStack itemstack = context . getItem ( ) ;
World world = context . getWorld ( ) ;
2018-09-16 11:20:28 +00:00
2019-08-28 17:45:08 +00:00
PlayerEntity player = context . getPlayer ( ) ;
if ( player ! = null & & ! player . abilities . allowEdit & & ! itemstack . canPlaceOn ( world . getTags ( ) , new CachedBlockInfo ( world , context . getPos ( ) , false ) ) )
return ActionResultType . PASS ;
2014-08-27 02:47:22 +00:00
// handle all placement events here
2019-09-04 02:58:57 +00:00
Item item = itemstack . getItem ( ) ;
2016-12-21 23:52:30 +00:00
int size = itemstack . getCount ( ) ;
2019-05-23 23:02:15 +00:00
CompoundNBT nbt = null ;
2019-06-25 20:59:10 +00:00
if ( itemstack . getTag ( ) ! = null )
2019-04-24 00:42:08 +00:00
nbt = itemstack . getTag ( ) . copy ( ) ;
2014-08-27 02:47:22 +00:00
2019-05-23 23:02:15 +00:00
if ( ! ( itemstack . getItem ( ) instanceof BucketItem ) ) // if not bucket
2014-08-27 02:47:22 +00:00
world . captureBlockSnapshots = true ;
2020-05-03 20:48:17 +00:00
ItemStack copy = itemstack . copy ( ) ;
2019-05-23 23:02:15 +00:00
ActionResultType ret = itemstack . getItem ( ) . onItemUse ( context ) ;
2019-08-28 17:45:08 +00:00
if ( itemstack . isEmpty ( ) )
ForgeEventFactory . onPlayerDestroyItem ( player , copy , context . getHand ( ) ) ;
2014-08-27 02:47:22 +00:00
world . captureBlockSnapshots = false ;
2020-06-26 01:41:38 +00:00
if ( ret . isSuccessOrConsume ( ) )
2014-08-27 02:47:22 +00:00
{
// save new item data
2016-12-21 23:52:30 +00:00
int newSize = itemstack . getCount ( ) ;
2019-05-23 23:02:15 +00:00
CompoundNBT newNBT = null ;
2019-06-25 20:59:10 +00:00
if ( itemstack . getTag ( ) ! = null )
2014-08-27 02:47:22 +00:00
{
2019-04-24 00:42:08 +00:00
newNBT = itemstack . getTag ( ) . copy ( ) ;
2014-08-27 02:47:22 +00:00
}
2015-11-13 15:13:47 +00:00
@SuppressWarnings ( " unchecked " )
2017-04-07 23:24:59 +00:00
List < BlockSnapshot > blockSnapshots = ( List < BlockSnapshot > ) world . capturedBlockSnapshots . clone ( ) ;
2014-08-27 02:47:22 +00:00
world . capturedBlockSnapshots . clear ( ) ;
// make sure to set pre-placement item data for event
2016-12-21 23:52:30 +00:00
itemstack . setCount ( size ) ;
2019-06-25 20:59:10 +00:00
itemstack . setTag ( nbt ) ;
2018-09-16 11:20:28 +00:00
2019-05-23 23:02:15 +00:00
Direction side = context . getFace ( ) ;
2018-09-16 11:20:28 +00:00
2019-04-24 00:42:08 +00:00
boolean eventResult = false ;
2014-11-05 02:27:02 +00:00
if ( blockSnapshots . size ( ) > 1 )
2014-08-27 02:47:22 +00:00
{
2019-04-24 00:42:08 +00:00
eventResult = ForgeEventFactory . onMultiBlockPlace ( player , blockSnapshots , side ) ;
2014-11-05 02:27:02 +00:00
}
2014-08-27 02:47:22 +00:00
else if ( blockSnapshots . size ( ) = = 1 )
{
2019-04-24 00:42:08 +00:00
eventResult = ForgeEventFactory . onBlockPlace ( player , blockSnapshots . get ( 0 ) , side ) ;
2014-08-27 02:47:22 +00:00
}
2019-04-24 00:42:08 +00:00
if ( eventResult )
2014-08-27 02:47:22 +00:00
{
2019-05-23 23:02:15 +00:00
ret = ActionResultType . FAIL ; // cancel placement
2014-08-27 02:47:22 +00:00
// revert back all captured blocks
2017-04-07 23:24:59 +00:00
for ( BlockSnapshot blocksnapshot : Lists . reverse ( blockSnapshots ) )
2014-08-27 02:47:22 +00:00
{
world . restoringBlockSnapshots = true ;
blocksnapshot . restore ( true , false ) ;
world . restoringBlockSnapshots = false ;
}
}
else
{
// Change the stack to its new content
2016-12-21 23:52:30 +00:00
itemstack . setCount ( newSize ) ;
2019-06-25 20:59:10 +00:00
itemstack . setTag ( newNBT ) ;
2014-08-27 02:47:22 +00:00
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
for ( BlockSnapshot snap : blockSnapshots )
2014-08-27 02:47:22 +00:00
{
2016-03-24 10:14:39 +00:00
int updateFlag = snap . getFlag ( ) ;
2019-05-23 23:02:15 +00:00
BlockState oldBlock = snap . getReplacedBlock ( ) ;
BlockState newBlock = world . getBlockState ( snap . getPos ( ) ) ;
2020-06-26 01:41:38 +00:00
if ( ! newBlock . hasTileEntity ( ) ) // Containers get placed automatically
2014-08-27 02:47:22 +00:00
{
2019-06-08 14:45:28 +00:00
newBlock . onBlockAdded ( world , snap . getPos ( ) , oldBlock , false ) ;
2014-08-27 02:47:22 +00:00
}
2020-06-26 01:41:38 +00:00
world . markAndNotifyBlock ( snap . getPos ( ) , world . getChunkAt ( snap . getPos ( ) ) , oldBlock , newBlock , updateFlag , 512 ) ;
2014-08-27 02:47:22 +00:00
}
2019-09-04 02:58:57 +00:00
player . addStat ( Stats . ITEM_USED . get ( item ) ) ;
2014-08-27 02:47:22 +00:00
}
}
world . capturedBlockSnapshots . clear ( ) ;
2016-03-02 07:38:31 +00:00
return ret ;
2014-08-27 02:47:22 +00:00
}
2020-11-10 20:05:47 +00:00
@Deprecated // TODO: Remove 1.17 - Use player-contextual version below.
2019-05-23 23:02:15 +00:00
public static boolean onAnvilChange ( RepairContainer container , @Nonnull ItemStack left , @Nonnull ItemStack right , IInventory outputSlot , String name , int baseCost )
2014-04-03 01:33:13 +00:00
{
2020-11-10 20:05:47 +00:00
return onAnvilChange ( container , left , right , outputSlot , name , baseCost , null ) ;
}
public static boolean onAnvilChange ( RepairContainer container , @Nonnull ItemStack left , @Nonnull ItemStack right , IInventory outputSlot , String name , int baseCost , PlayerEntity player )
{
AnvilUpdateEvent e = new AnvilUpdateEvent ( left , right , name , baseCost , player ) ;
2014-04-03 01:33:13 +00:00
if ( MinecraftForge . EVENT_BUS . post ( e ) ) return false ;
2016-12-21 23:52:30 +00:00
if ( e . getOutput ( ) . isEmpty ( ) ) return true ;
2014-04-03 01:33:13 +00:00
2016-03-24 08:44:52 +00:00
outputSlot . setInventorySlotContents ( 0 , e . getOutput ( ) ) ;
2019-05-23 23:02:15 +00:00
container . setMaximumCost ( e . getCost ( ) ) ;
2016-03-24 08:44:52 +00:00
container . materialCost = e . getMaterialCost ( ) ;
2014-04-03 01:33:13 +00:00
return false ;
}
2014-11-05 02:27:02 +00:00
2019-05-23 23:02:15 +00:00
public static float onAnvilRepair ( PlayerEntity player , @Nonnull ItemStack output , @Nonnull ItemStack left , @Nonnull ItemStack right )
2014-08-04 20:54:35 +00:00
{
AnvilRepairEvent e = new AnvilRepairEvent ( player , left , right , output ) ;
MinecraftForge . EVENT_BUS . post ( e ) ;
2016-03-24 08:44:52 +00:00
return e . getBreakChance ( ) ;
2014-08-04 20:54:35 +00:00
}
2014-06-02 23:57:04 +00:00
2019-05-23 23:02:15 +00:00
private static ThreadLocal < PlayerEntity > craftingPlayer = new ThreadLocal < PlayerEntity > ( ) ;
public static void setCraftingPlayer ( PlayerEntity player )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
craftingPlayer . set ( player ) ;
}
2019-05-23 23:02:15 +00:00
public static PlayerEntity getCraftingPlayer ( )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
return craftingPlayer . get ( ) ;
}
2016-11-17 00:15:24 +00:00
@Nonnull
public static ItemStack getContainerItem ( @Nonnull ItemStack stack )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
if ( stack . getItem ( ) . hasContainerItem ( stack ) )
{
stack = stack . getItem ( ) . getContainerItem ( stack ) ;
2018-09-22 10:40:22 +00:00
if ( ! stack . isEmpty ( ) & & stack . isDamageable ( ) & & stack . getDamage ( ) > stack . getMaxDamage ( ) )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
2016-03-09 22:11:56 +00:00
ForgeEventFactory . onPlayerDestroyItem ( craftingPlayer . get ( ) , stack , null ) ;
2016-12-21 23:52:30 +00:00
return ItemStack . EMPTY ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
}
return stack ;
}
2016-12-21 23:52:30 +00:00
return ItemStack . EMPTY ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
}
2019-05-23 23:02:15 +00:00
public static boolean onPlayerAttackTarget ( PlayerEntity player , Entity target )
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
{
if ( MinecraftForge . EVENT_BUS . post ( new AttackEntityEvent ( player , target ) ) ) return false ;
2016-03-13 01:40:03 +00:00
ItemStack stack = player . getHeldItemMainhand ( ) ;
2016-12-21 23:52:30 +00:00
return stack . isEmpty ( ) | | ! stack . getItem ( ) . onLeftClickEntity ( stack , player , target ) ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
}
2016-01-03 14:21:33 +00:00
2020-06-19 14:58:45 +00:00
public static boolean onTravelToDimension ( Entity entity , RegistryKey < World > dimension )
2016-01-03 14:21:33 +00:00
{
EntityTravelToDimensionEvent event = new EntityTravelToDimensionEvent ( entity , dimension ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
if ( event . isCanceled ( ) )
{
// Revert variable back to true as it would have been set to false
2019-05-23 23:02:15 +00:00
if ( entity instanceof ContainerMinecartEntity )
2016-01-03 14:21:33 +00:00
{
2019-05-23 23:02:15 +00:00
( ( ContainerMinecartEntity ) entity ) . dropContentsWhenDead ( true ) ;
2016-01-03 14:21:33 +00:00
}
}
return ! event . isCanceled ( ) ;
}
2016-02-27 01:27:21 +00:00
2019-05-23 23:02:15 +00:00
public static ActionResultType onInteractEntityAt ( PlayerEntity player , Entity entity , RayTraceResult ray , Hand hand )
2016-02-27 01:27:21 +00:00
{
2020-06-19 14:58:45 +00:00
Vector3d vec3d = ray . getHitVec ( ) . subtract ( entity . getPositionVec ( ) ) ;
2017-06-15 18:26:14 +00:00
return onInteractEntityAt ( player , entity , vec3d , hand ) ;
2017-04-07 23:38:56 +00:00
}
2020-06-19 14:58:45 +00:00
public static ActionResultType onInteractEntityAt ( PlayerEntity player , Entity entity , Vector3d vec3d , Hand hand )
2017-04-07 23:38:56 +00:00
{
PlayerInteractEvent . EntityInteractSpecific evt = new PlayerInteractEvent . EntityInteractSpecific ( player , hand , entity , vec3d ) ;
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt . isCanceled ( ) ? evt . getCancellationResult ( ) : null ;
2016-04-05 00:58:46 +00:00
}
2019-05-23 23:02:15 +00:00
public static ActionResultType onInteractEntity ( PlayerEntity player , Entity entity , Hand hand )
2017-04-07 23:38:56 +00:00
{
PlayerInteractEvent . EntityInteract evt = new PlayerInteractEvent . EntityInteract ( player , hand , entity ) ;
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt . isCanceled ( ) ? evt . getCancellationResult ( ) : null ;
}
2019-05-23 23:02:15 +00:00
public static ActionResultType onItemRightClick ( PlayerEntity player , Hand hand )
2017-04-07 23:38:56 +00:00
{
PlayerInteractEvent . RightClickItem evt = new PlayerInteractEvent . RightClickItem ( player , hand ) ;
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt . isCanceled ( ) ? evt . getCancellationResult ( ) : null ;
2016-04-05 00:58:46 +00:00
}
2019-05-23 23:02:15 +00:00
public static PlayerInteractEvent . LeftClickBlock onLeftClickBlock ( PlayerEntity player , BlockPos pos , Direction face )
2016-04-05 00:58:46 +00:00
{
2019-05-23 23:02:15 +00:00
PlayerInteractEvent . LeftClickBlock evt = new PlayerInteractEvent . LeftClickBlock ( player , pos , face ) ;
2016-04-05 00:58:46 +00:00
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt ;
}
2020-12-28 19:54:30 +00:00
@Deprecated //Use RayTraceResult version. TODO: Remove 1.17
2019-05-23 23:02:15 +00:00
public static PlayerInteractEvent . RightClickBlock onRightClickBlock ( PlayerEntity player , Hand hand , BlockPos pos , Direction face )
2016-04-05 00:58:46 +00:00
{
2019-05-23 23:02:15 +00:00
PlayerInteractEvent . RightClickBlock evt = new PlayerInteractEvent . RightClickBlock ( player , hand , pos , face ) ;
2016-04-05 00:58:46 +00:00
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt ;
}
2020-12-28 19:54:30 +00:00
public static PlayerInteractEvent . RightClickBlock onRightClickBlock ( PlayerEntity player , Hand hand , BlockPos pos , BlockRayTraceResult hitVec )
{
PlayerInteractEvent . RightClickBlock evt = new PlayerInteractEvent . RightClickBlock ( player , hand , pos , hitVec ) ;
MinecraftForge . EVENT_BUS . post ( evt ) ;
return evt ;
}
2019-05-23 23:02:15 +00:00
public static void onEmptyClick ( PlayerEntity player , Hand hand )
2016-04-05 00:58:46 +00:00
{
MinecraftForge . EVENT_BUS . post ( new PlayerInteractEvent . RightClickEmpty ( player , hand ) ) ;
}
2016-05-09 21:15:59 +00:00
2019-05-23 23:02:15 +00:00
public static void onEmptyLeftClick ( PlayerEntity player )
2017-01-11 23:17:08 +00:00
{
MinecraftForge . EVENT_BUS . post ( new PlayerInteractEvent . LeftClickEmpty ( player ) ) ;
}
2020-10-15 17:15:06 +00:00
public static boolean onChangeGameMode ( PlayerEntity player , GameType currentGameMode , GameType newGameMode )
{
if ( currentGameMode ! = newGameMode )
{
PlayerEvent . PlayerChangeGameModeEvent evt = new PlayerEvent . PlayerChangeGameModeEvent ( player , currentGameMode , newGameMode ) ;
MinecraftForge . EVENT_BUS . post ( evt ) ;
return ! evt . isCanceled ( ) ;
}
return true ;
}
2016-05-09 21:15:59 +00:00
private static ThreadLocal < Deque < LootTableContext > > lootContext = new ThreadLocal < Deque < LootTableContext > > ( ) ;
private static LootTableContext getLootTableContext ( )
{
LootTableContext ctx = lootContext . get ( ) . peek ( ) ;
if ( ctx = = null )
2017-04-07 23:22:49 +00:00
throw new JsonParseException ( " Invalid call stack, could not grab json context! " ) ; // Should I throw this? Do we care about custom deserializers outside the manager?
2016-05-09 21:15:59 +00:00
return ctx ;
}
2017-01-11 23:17:56 +00:00
2017-04-07 23:22:49 +00:00
@Nullable
2020-06-24 00:56:24 +00:00
public static LootTable loadLootTable ( Gson gson , ResourceLocation name , JsonElement data , boolean custom , LootTableManager lootTableManager )
2016-05-09 21:15:59 +00:00
{
Deque < LootTableContext > que = lootContext . get ( ) ;
if ( que = = null )
{
que = Queues . newArrayDeque ( ) ;
lootContext . set ( que ) ;
}
LootTable ret = null ;
try
{
que . push ( new LootTableContext ( name , custom ) ) ;
ret = gson . fromJson ( data , LootTable . class ) ;
que . pop ( ) ;
}
catch ( JsonParseException e )
{
que . pop ( ) ;
throw e ;
}
if ( ! custom )
2017-04-07 23:22:49 +00:00
ret = ForgeEventFactory . loadLootTable ( name , ret , lootTableManager ) ;
2016-05-09 21:15:59 +00:00
2020-06-24 00:56:24 +00:00
if ( ret ! = null )
ret . freeze ( ) ;
2016-05-11 06:35:02 +00:00
2016-05-09 21:15:59 +00:00
return ret ;
}
2019-09-11 14:00:32 +00:00
public static FluidAttributes createVanillaFluidAttributes ( Fluid fluid )
{
if ( fluid instanceof EmptyFluid )
2019-09-12 15:33:19 +00:00
return net . minecraftforge . fluids . FluidAttributes . builder ( null , null )
2019-09-11 14:00:32 +00:00
. translationKey ( " block.minecraft.air " )
. color ( 0 ) . density ( 0 ) . temperature ( 0 ) . luminosity ( 0 ) . viscosity ( 0 ) . build ( fluid ) ;
if ( fluid instanceof WaterFluid )
return net . minecraftforge . fluids . FluidAttributes . Water . builder (
2019-12-17 04:22:13 +00:00
new ResourceLocation ( " block/water_still " ) ,
new ResourceLocation ( " block/water_flow " ) )
. overlay ( new ResourceLocation ( " block/water_overlay " ) )
2019-09-11 14:00:32 +00:00
. translationKey ( " block.minecraft.water " )
2020-06-19 17:34:50 +00:00
. color ( 0xFF3F76E4 )
. sound ( SoundEvents . ITEM_BUCKET_FILL , SoundEvents . ITEM_BUCKET_EMPTY )
. build ( fluid ) ;
2019-09-11 14:00:32 +00:00
if ( fluid instanceof LavaFluid )
return net . minecraftforge . fluids . FluidAttributes . builder (
2019-12-17 04:22:13 +00:00
new ResourceLocation ( " block/lava_still " ) ,
new ResourceLocation ( " block/lava_flow " ) )
2019-09-11 14:00:32 +00:00
. translationKey ( " block.minecraft.lava " )
2020-06-19 17:34:50 +00:00
. luminosity ( 15 ) . density ( 3000 ) . viscosity ( 6000 ) . temperature ( 1300 )
. sound ( SoundEvents . ITEM_BUCKET_FILL_LAVA , SoundEvents . ITEM_BUCKET_EMPTY_LAVA )
. build ( fluid ) ;
2019-09-11 14:00:32 +00:00
throw new RuntimeException ( " Mod fluids must override createAttributes. " ) ;
}
2020-11-27 23:57:15 +00:00
public static String getDefaultWorldType ( )
{
ForgeWorldType def = ForgeWorldType . getDefaultWorldType ( ) ;
if ( def ! = null )
return def . getRegistryName ( ) . toString ( ) ;
return " default " ;
}
2020-09-15 00:43:01 +00:00
@FunctionalInterface
public interface BiomeCallbackFunction
{
Biome apply ( final Biome . Climate climate , final Biome . Category category , final Float depth , final Float scale , final BiomeAmbience effects , final BiomeGenerationSettings gen , final MobSpawnInfo spawns ) ;
}
2020-10-26 22:06:53 +00:00
public static Biome enhanceBiome ( @Nullable final ResourceLocation name , final Biome . Climate climate , final Biome . Category category , final Float depth , final Float scale , final BiomeAmbience effects , final BiomeGenerationSettings gen , final MobSpawnInfo spawns , final RecordCodecBuilder . Instance < Biome > codec , final BiomeCallbackFunction callback )
2020-09-15 00:43:01 +00:00
{
BiomeGenerationSettingsBuilder genBuilder = new BiomeGenerationSettingsBuilder ( gen ) ;
MobSpawnInfoBuilder spawnBuilder = new MobSpawnInfoBuilder ( spawns ) ;
BiomeLoadingEvent event = new BiomeLoadingEvent ( name , climate , category , depth , scale , effects , genBuilder , spawnBuilder ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
2020-10-29 00:11:57 +00:00
return callback . apply ( event . getClimate ( ) , event . getCategory ( ) , event . getDepth ( ) , event . getScale ( ) , event . getEffects ( ) , event . getGeneration ( ) . build ( ) , event . getSpawns ( ) . copy ( ) ) . setRegistryName ( name ) ;
2020-09-15 00:43:01 +00:00
}
2016-05-09 21:15:59 +00:00
private static class LootTableContext
{
public final ResourceLocation name ;
private final boolean vanilla ;
public final boolean custom ;
public int poolCount = 0 ;
public int entryCount = 0 ;
private HashSet < String > entryNames = Sets . newHashSet ( ) ;
private LootTableContext ( ResourceLocation name , boolean custom )
{
this . name = name ;
this . custom = custom ;
2018-09-16 11:20:28 +00:00
this . vanilla = " minecraft " . equals ( this . name . getNamespace ( ) ) ;
2016-05-09 21:15:59 +00:00
}
private void resetPoolCtx ( )
{
this . entryCount = 0 ;
this . entryNames . clear ( ) ;
}
2016-11-17 18:44:31 +00:00
public String validateEntryName ( @Nullable String name )
2016-05-09 21:15:59 +00:00
{
2017-01-11 23:17:56 +00:00
if ( name ! = null & & ! this . entryNames . contains ( name ) )
2016-05-09 21:15:59 +00:00
{
this . entryNames . add ( name ) ;
return name ;
}
if ( ! this . vanilla )
throw new JsonParseException ( " Loot Table \" " + this . name . toString ( ) + " \" Duplicate entry name \" " + name + " \" for pool # " + ( this . poolCount - 1 ) + " entry # " + ( this . entryCount - 1 ) ) ;
int x = 0 ;
while ( this . entryNames . contains ( name + " # " + x ) )
x + + ;
name = name + " # " + x ;
this . entryNames . add ( name ) ;
return name ;
}
}
public static String readPoolName ( JsonObject json )
{
LootTableContext ctx = ForgeHooks . getLootTableContext ( ) ;
ctx . resetPoolCtx ( ) ;
if ( json . has ( " name " ) )
2019-05-23 23:02:15 +00:00
return JSONUtils . getString ( json , " name " ) ;
2016-05-09 21:15:59 +00:00
if ( ctx . custom )
return " custom# " + json . hashCode ( ) ; //We don't care about custom ones modders shouldn't be editing them!
ctx . poolCount + + ;
if ( ! ctx . vanilla )
throw new JsonParseException ( " Loot Table \" " + ctx . name . toString ( ) + " \" Missing `name` entry for pool # " + ( ctx . poolCount - 1 ) ) ;
return ctx . poolCount = = 1 ? " main " : " pool " + ( ctx . poolCount - 1 ) ;
}
public static String readLootEntryName ( JsonObject json , String type )
{
LootTableContext ctx = ForgeHooks . getLootTableContext ( ) ;
ctx . entryCount + + ;
if ( json . has ( " entryName " ) )
2019-05-23 23:02:15 +00:00
return ctx . validateEntryName ( JSONUtils . getString ( json , " entryName " ) ) ;
2016-05-09 21:15:59 +00:00
if ( ctx . custom )
return " custom# " + json . hashCode ( ) ; //We don't care about custom ones modders shouldn't be editing them!
String name = null ;
if ( " item " . equals ( type ) )
2019-05-23 23:02:15 +00:00
name = JSONUtils . getString ( json , " name " ) ;
2016-05-09 21:15:59 +00:00
else if ( " loot_table " . equals ( type ) )
2019-05-23 23:02:15 +00:00
name = JSONUtils . getString ( json , " name " ) ;
2016-05-09 21:15:59 +00:00
else if ( " empty " . equals ( type ) )
name = " empty " ;
return ctx . validateEntryName ( name ) ;
}
2019-05-23 23:02:15 +00:00
public static boolean onCropsGrowPre ( World worldIn , BlockPos pos , BlockState state , boolean def )
2016-11-07 22:40:44 +00:00
{
BlockEvent ev = new BlockEvent . CropGrowEvent . Pre ( worldIn , pos , state ) ;
MinecraftForge . EVENT_BUS . post ( ev ) ;
2018-06-11 01:12:46 +00:00
return ( ev . getResult ( ) = = net . minecraftforge . eventbus . api . Event . Result . ALLOW | | ( ev . getResult ( ) = = net . minecraftforge . eventbus . api . Event . Result . DEFAULT & & def ) ) ;
2016-11-07 22:40:44 +00:00
}
2019-05-23 23:02:15 +00:00
public static void onCropsGrowPost ( World worldIn , BlockPos pos , BlockState state )
2017-06-02 23:22:16 +00:00
{
MinecraftForge . EVENT_BUS . post ( new BlockEvent . CropGrowEvent . Post ( worldIn , pos , state , worldIn . getBlockState ( pos ) ) ) ;
}
2017-06-27 22:18:52 +00:00
2017-08-01 19:13:37 +00:00
@Nullable
2019-05-23 23:02:15 +00:00
public static CriticalHitEvent getCriticalHit ( PlayerEntity player , Entity target , boolean vanillaCritical , float damageModifier )
2017-08-01 19:13:37 +00:00
{
CriticalHitEvent hitResult = new CriticalHitEvent ( player , target , damageModifier , vanillaCritical ) ;
MinecraftForge . EVENT_BUS . post ( hitResult ) ;
2018-06-11 01:12:46 +00:00
if ( hitResult . getResult ( ) = = net . minecraftforge . eventbus . api . Event . Result . ALLOW | | ( vanillaCritical & & hitResult . getResult ( ) = = net . minecraftforge . eventbus . api . Event . Result . DEFAULT ) )
2017-08-01 19:13:37 +00:00
{
return hitResult ;
}
return null ;
}
2017-06-27 22:18:52 +00:00
2019-05-23 23:02:15 +00:00
public static void onAdvancement ( ServerPlayerEntity player , Advancement advancement )
2017-12-05 22:05:05 +00:00
{
MinecraftForge . EVENT_BUS . post ( new AdvancementEvent ( player , advancement ) ) ;
}
2018-03-27 06:25:27 +00:00
/ * *
* Used as the default implementation of { @link Item # getCreatorModId } . Call that method instead .
* /
@Nullable
public static String getDefaultCreatorModId ( @Nonnull ItemStack itemStack )
{
Item item = itemStack . getItem ( ) ;
ResourceLocation registryName = item . getRegistryName ( ) ;
2018-09-16 11:20:28 +00:00
String modId = registryName = = null ? null : registryName . getNamespace ( ) ;
2018-03-27 06:25:27 +00:00
if ( " minecraft " . equals ( modId ) )
{
2019-05-23 23:02:15 +00:00
if ( item instanceof EnchantedBookItem )
2018-03-27 06:25:27 +00:00
{
2019-05-23 23:02:15 +00:00
ListNBT enchantmentsNbt = EnchantedBookItem . getEnchantments ( itemStack ) ;
2018-09-18 04:04:02 +00:00
if ( enchantmentsNbt . size ( ) = = 1 )
2018-03-27 06:25:27 +00:00
{
2019-05-23 23:02:15 +00:00
CompoundNBT nbttagcompound = enchantmentsNbt . getCompound ( 0 ) ;
ResourceLocation resourceLocation = ResourceLocation . tryCreate ( nbttagcompound . getString ( " id " ) ) ;
2019-03-17 20:51:10 +00:00
if ( resourceLocation ! = null & & ForgeRegistries . ENCHANTMENTS . containsKey ( resourceLocation ) )
2018-03-27 06:25:27 +00:00
{
2019-03-17 20:51:10 +00:00
return resourceLocation . getNamespace ( ) ;
2018-03-27 06:25:27 +00:00
}
}
}
2019-05-23 23:02:15 +00:00
else if ( item instanceof PotionItem | | item instanceof TippedArrowItem )
2018-03-27 06:25:27 +00:00
{
2019-05-23 23:02:15 +00:00
Potion potionType = PotionUtils . getPotionFromItem ( itemStack ) ;
2018-03-27 06:25:27 +00:00
ResourceLocation resourceLocation = ForgeRegistries . POTION_TYPES . getKey ( potionType ) ;
if ( resourceLocation ! = null )
{
2018-09-16 11:20:28 +00:00
return resourceLocation . getNamespace ( ) ;
2018-03-27 06:25:27 +00:00
}
}
2019-05-23 23:02:15 +00:00
else if ( item instanceof SpawnEggItem )
2018-03-27 06:25:27 +00:00
{
2019-05-23 23:02:15 +00:00
ResourceLocation resourceLocation = ( ( SpawnEggItem ) item ) . getType ( null ) . getRegistryName ( ) ;
2018-03-27 06:25:27 +00:00
if ( resourceLocation ! = null )
{
2018-09-16 11:20:28 +00:00
return resourceLocation . getNamespace ( ) ;
2018-03-27 06:25:27 +00:00
}
}
}
return modId ;
}
2018-06-27 18:31:38 +00:00
2019-05-23 23:02:15 +00:00
public static boolean onFarmlandTrample ( World world , BlockPos pos , BlockState state , float fallDistance , Entity entity )
2018-06-27 18:31:38 +00:00
{
2018-09-21 22:50:37 +00:00
if ( entity . canTrample ( state , pos , fallDistance ) )
2018-06-27 18:31:38 +00:00
{
BlockEvent . FarmlandTrampleEvent event = new BlockEvent . FarmlandTrampleEvent ( world , pos , state , fallDistance , entity ) ;
MinecraftForge . EVENT_BUS . post ( event ) ;
return ! event . isCanceled ( ) ;
}
return false ;
}
2018-09-21 06:50:50 +00:00
private static TriConsumer < Block , ToolType , Integer > blockToolSetter ;
//Internal use only Modders, this is specifically hidden from you, as you shouldn't be editing other people's blocks.
public static void setBlockToolSetter ( TriConsumer < Block , ToolType , Integer > setter )
{
blockToolSetter = setter ;
}
@SuppressWarnings ( " unchecked " )
private static < T , E > T getPrivateValue ( Class < ? super E > classToAccess , @Nullable E instance , int fieldIndex )
{
try
{
Field f = classToAccess . getDeclaredFields ( ) [ fieldIndex ] ;
f . setAccessible ( true ) ;
return ( T ) f . get ( instance ) ;
}
catch ( Exception e )
{
Throwables . throwIfUnchecked ( e ) ;
throw new RuntimeException ( e ) ;
}
}
private static final DummyBlockReader DUMMY_WORLD = new DummyBlockReader ( ) ;
private static class DummyBlockReader implements IBlockReader {
@Override
public TileEntity getTileEntity ( BlockPos pos ) {
return null ;
}
@Override
2019-05-23 23:02:15 +00:00
public BlockState getBlockState ( BlockPos pos ) {
2018-09-21 06:50:50 +00:00
return Blocks . AIR . getDefaultState ( ) ;
}
@Override
2020-06-19 14:58:45 +00:00
public FluidState getFluidState ( BlockPos pos ) {
2018-09-22 10:40:22 +00:00
return Fluids . EMPTY . getDefaultState ( ) ;
2018-09-21 06:50:50 +00:00
}
}
2018-11-17 07:15:39 +00:00
2019-05-23 23:02:15 +00:00
public static int onNoteChange ( World world , BlockPos pos , BlockState state , int old , int _new ) {
2018-11-17 07:15:39 +00:00
NoteBlockEvent . Change event = new NoteBlockEvent . Change ( world , pos , state , old , _new ) ;
if ( MinecraftForge . EVENT_BUS . post ( event ) )
return - 1 ;
return event . getVanillaNoteId ( ) ;
}
2018-12-11 06:19:43 +00:00
2019-09-03 22:15:48 +00:00
public static int canEntitySpawn ( MobEntity entity , IWorld world , double x , double y , double z , AbstractSpawner spawner , SpawnReason spawnReason ) {
Result res = ForgeEventFactory . canEntitySpawn ( entity , world , x , y , z , null , spawnReason ) ;
2018-12-11 06:19:43 +00:00
return res = = Result . DEFAULT ? 0 : res = = Result . DENY ? - 1 : 1 ;
}
2019-01-15 03:23:36 +00:00
2020-06-25 01:25:55 +00:00
public static < T > void deserializeTagAdditions ( List < ITag . ITagEntry > list , JsonObject json , List < ITag . Proxy > allList )
2019-01-15 03:23:36 +00:00
{
2020-08-19 05:22:34 +00:00
//TODO 1.17 remove parsing the forge added "optional" array. Still here for compatibility with previously created tags.
2019-01-15 03:23:36 +00:00
if ( json . has ( " optional " ) )
{
2019-05-23 23:02:15 +00:00
for ( JsonElement entry : JSONUtils . getJsonArray ( json , " optional " ) )
2019-01-15 03:23:36 +00:00
{
2019-05-23 23:02:15 +00:00
String s = JSONUtils . getString ( entry , " value " ) ;
2019-01-15 03:23:36 +00:00
if ( ! s . startsWith ( " # " ) )
2020-08-19 05:22:34 +00:00
list . add ( new ITag . OptionalItemEntry ( new ResourceLocation ( s ) ) ) ;
2020-03-20 03:38:58 +00:00
else
2020-08-19 05:22:34 +00:00
list . add ( new ITag . OptionalTagEntry ( new ResourceLocation ( s . substring ( 1 ) ) ) ) ;
2019-01-15 03:23:36 +00:00
}
}
if ( json . has ( " remove " ) )
{
2019-05-23 23:02:15 +00:00
for ( JsonElement entry : JSONUtils . getJsonArray ( json , " remove " ) )
2019-01-15 03:23:36 +00:00
{
2019-05-23 23:02:15 +00:00
String s = JSONUtils . getString ( entry , " value " ) ;
2020-06-25 01:25:55 +00:00
ITag . ITagEntry dummy ;
2019-01-15 03:23:36 +00:00
if ( ! s . startsWith ( " # " ) )
2020-06-25 01:25:55 +00:00
dummy = new ITag . ItemEntry ( new ResourceLocation ( s ) ) ;
else
dummy = new ITag . TagEntry ( new ResourceLocation ( s . substring ( 1 ) ) ) ;
2020-10-29 00:11:57 +00:00
allList . removeIf ( e - > e . getEntry ( ) . equals ( dummy ) ) ;
2019-01-15 03:23:36 +00:00
}
}
}
2019-05-23 23:02:15 +00:00
private static final Map < IDataSerializer < ? > , DataSerializerEntry > serializerEntries = GameData . getSerializerMap ( ) ;
2019-04-11 12:33:12 +00:00
//private static final ForgeRegistry<DataSerializerEntry> serializerRegistry = (ForgeRegistry<DataSerializerEntry>) ForgeRegistries.DATA_SERIALIZERS;
2019-05-27 20:46:19 +00:00
// Do not reimplement this ^ it introduces a chicken-egg scenario by classloading registries during bootstrap
2019-04-11 12:33:12 +00:00
@Nullable
2019-05-23 23:02:15 +00:00
public static IDataSerializer < ? > getSerializer ( int id , IntIdentityHashBiMap < IDataSerializer < ? > > vanilla )
2019-04-11 12:33:12 +00:00
{
2019-05-23 23:02:15 +00:00
IDataSerializer < ? > serializer = vanilla . getByValue ( id ) ;
2019-04-11 12:33:12 +00:00
if ( serializer = = null )
{
DataSerializerEntry entry = ( ( ForgeRegistry < DataSerializerEntry > ) ForgeRegistries . DATA_SERIALIZERS ) . getValue ( id ) ;
if ( entry ! = null ) serializer = entry . getSerializer ( ) ;
}
return serializer ;
}
2019-05-23 23:02:15 +00:00
public static int getSerializerId ( IDataSerializer < ? > serializer , IntIdentityHashBiMap < IDataSerializer < ? > > vanilla )
2019-04-11 12:33:12 +00:00
{
int id = vanilla . getId ( serializer ) ;
if ( id < 0 )
{
DataSerializerEntry entry = serializerEntries . get ( serializer ) ;
if ( entry ! = null ) id = ( ( ForgeRegistry < DataSerializerEntry > ) ForgeRegistries . DATA_SERIALIZERS ) . getID ( entry ) ;
}
return id ;
}
2019-06-25 02:01:03 +00:00
public static boolean canEntityDestroy ( World world , BlockPos pos , LivingEntity entity )
{
BlockState state = world . getBlockState ( pos ) ;
return ForgeEventFactory . getMobGriefingEvent ( world , entity ) & & state . canEntityDestroy ( world , pos , entity ) & & ForgeEventFactory . onEntityDestroyBlock ( entity , pos , state ) ;
}
2019-09-16 21:04:32 +00:00
private static final Map < IRegistryDelegate < Item > , Integer > VANILLA_BURNS = new HashMap < > ( ) ;
/ * *
* Gets the burn time of this itemstack .
* /
public static int getBurnTime ( ItemStack stack )
{
if ( stack . isEmpty ( ) )
{
return 0 ;
}
else
{
Item item = stack . getItem ( ) ;
int ret = stack . getBurnTime ( ) ;
return ForgeEventFactory . getItemBurnTime ( stack , ret = = - 1 ? VANILLA_BURNS . getOrDefault ( item . delegate , 0 ) : ret ) ;
}
}
2020-04-01 18:34:36 +00:00
@SuppressWarnings ( " deprecation " )
2019-09-16 21:04:32 +00:00
public static synchronized void updateBurns ( )
{
VANILLA_BURNS . clear ( ) ;
FurnaceTileEntity . getBurnTimes ( ) . entrySet ( ) . forEach ( e - > VANILLA_BURNS . put ( e . getKey ( ) . delegate , e . getValue ( ) ) ) ;
}
2020-02-27 06:13:36 +00:00
/ * *
* All loot table drops should be passed to this function so that mod added effects
* ( e . g . smelting enchantments ) can be processed .
* @param list The loot generated
* @param context The loot context that generated that loot
* @return The modified list
* /
public static List < ItemStack > modifyLoot ( List < ItemStack > list , LootContext context ) {
2020-07-06 19:41:57 +00:00
LootModifierManager man = ForgeInternalHandler . getLootModifierManager ( ) ;
2020-02-27 06:13:36 +00:00
for ( IGlobalLootModifier mod : man . getAllLootMods ( ) ) {
list = mod . apply ( list , context ) ;
}
return list ;
}
2020-07-20 22:56:21 +00:00
public static List < String > getModPacks ( )
{
List < String > modpacks = ResourcePackLoader . getPackNames ( ) ;
if ( modpacks . isEmpty ( ) )
throw new IllegalStateException ( " Attempted to retrieve mod packs before they were loaded in! " ) ;
return modpacks ;
}
public static List < String > getModPacksWithVanilla ( )
{
List < String > modpacks = getModPacks ( ) ;
modpacks . add ( " vanilla " ) ;
return modpacks ;
}
2020-11-20 18:23:50 +00:00
/ * *
* Fixes MC - 194811
* When a structure mod is removed , this map may contain null keys . This will make the world unable to save if this persists .
* If we remove a structure from the save data in this way , we then mark the chunk for saving
* /
public static void fixNullStructureReferences ( IChunk chunk , Map < Structure < ? > , LongSet > structureReferences )
{
if ( structureReferences . remove ( null ) ! = null )
{
chunk . setModified ( true ) ;
}
chunk . setStructureReferences ( structureReferences ) ;
}
2016-03-08 05:06:54 +00:00
}