mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Add reverse tag cache, to make looking up tags for items/blocks/etc.. less costly.
This commit is contained in:
1 parent
9542f51cd0
commit
c30b27fcfe
15 files changed
+221
-26
No files matched your search
@@ -21,6 +21,7 @@ package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -28,11 +29,9 @@ import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BedBlock;
|
||||
import net.minecraft.block.FarmlandBlock;
|
||||
import net.minecraft.block.FenceBlock;
|
||||
import net.minecraft.block.FireBlock;
|
||||
import net.minecraft.block.HorizontalBlock;
|
||||
import net.minecraft.block.IBeaconBeamColorProvider;
|
||||
import net.minecraft.block.StainedGlassBlock;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -52,7 +51,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.WitherSkullEntity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -65,7 +63,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -86,6 +83,7 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface IForgeBlock
|
||||
{
|
||||
default Block getBlock()
|
||||
@@ -177,7 +175,6 @@ public interface IForgeBlock
|
||||
* @param state State of the current block
|
||||
* @return True if block has a tile entity, false otherwise
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default boolean hasTileEntity(BlockState state)
|
||||
{
|
||||
return this instanceof ITileEntityProvider;
|
||||
@@ -192,7 +189,6 @@ public interface IForgeBlock
|
||||
* @param world The world to create the TE in
|
||||
* @return A instance of a class extending TileEntity
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nullable
|
||||
default TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
@@ -606,7 +602,6 @@ public interface IForgeBlock
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
default BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction)
|
||||
{
|
||||
return state.rotate(direction);
|
||||
@@ -855,7 +850,6 @@ public interface IForgeBlock
|
||||
* @param hand The player hand used to place this block
|
||||
* @return The state to be placed in the world
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default BlockState getStateForPlacement(BlockState state, Direction facing, BlockState state2, IWorld world, BlockPos pos1, BlockPos pos2, Hand hand)
|
||||
{
|
||||
return this.getBlock().updatePostPlacement(state, facing, state2, world, pos1, pos2);
|
||||
@@ -905,7 +899,6 @@ public interface IForgeBlock
|
||||
* @param face The face that the fire is coming from
|
||||
* @return A number ranging from 0 to 300 relating used to determine if the block will be consumed by fire
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default int getFlammability(BlockState state, IBlockReader world, BlockPos pos, Direction face)
|
||||
{
|
||||
return ((FireBlock)Blocks.FIRE).func_220274_q(state);
|
||||
@@ -1006,9 +999,14 @@ public interface IForgeBlock
|
||||
/**
|
||||
* Determines if this block should drop loot when exploded.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default boolean canDropFromExplosion(BlockState state, IBlockReader world, BlockPos pos, Explosion explosion)
|
||||
{
|
||||
return state.getBlock().canDropFromExplosion(explosion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of tags names this is known to be associated with.
|
||||
* This should be used in favor of TagCollection.getOwningTags, as this caches the result and automatically updates when the TagCollection changes.
|
||||
*/
|
||||
Set<ResourceLocation> getTags();
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -28,6 +30,7 @@ import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Explosion;
|
||||
@@ -108,4 +111,10 @@ public interface IForgeFluid
|
||||
{
|
||||
return this.getFluid().getRenderLayer() == layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of tags names this is known to be associated with.
|
||||
* This should be used in favor of TagCollection.getOwningTags, as this caches the result and automatically updates when the TagCollection changes.
|
||||
*/
|
||||
Set<ResourceLocation> getTags();
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.entity.model.BipedModel;
|
||||
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.MobEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
@@ -43,6 +44,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
@@ -759,5 +761,11 @@ public interface IForgeItem
|
||||
* one.
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer getTileEntityItemStackRenderer();
|
||||
ItemStackTileEntityRenderer getTileEntityItemStackRenderer();
|
||||
|
||||
/**
|
||||
* Retrieves a list of tags names this is known to be associated with.
|
||||
* This should be used in favor of TagCollection.getOwningTags, as this caches the result and automatically updates when the TagCollection changes.
|
||||
*/
|
||||
Set<ResourceLocation> getTags();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ReverseTagWrapper<T>
|
||||
{
|
||||
private final T target;
|
||||
private final IntSupplier genSupplier;
|
||||
private final Supplier<TagCollection<T>> colSupplier;
|
||||
|
||||
private int generation = -1;
|
||||
private Set<ResourceLocation> cache = null;
|
||||
|
||||
public ReverseTagWrapper(T target, IntSupplier genSupplier, Supplier<TagCollection<T>> colSupplier)
|
||||
{
|
||||
this.target = target;
|
||||
this.genSupplier = genSupplier;
|
||||
this.colSupplier = colSupplier;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getTagNames()
|
||||
{
|
||||
if (cache == null || generation != genSupplier.getAsInt())
|
||||
{
|
||||
this.cache = new HashSet<>(colSupplier.get().getOwningTags(target));
|
||||
this.generation = genSupplier.getAsInt();
|
||||
}
|
||||
return this.cache;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user