1.15 port

This commit is contained in:
yueh
2020-05-18 14:02:45 +02:00
parent 0ea86c939c
commit 16d6d55d7f
630 changed files with 4211 additions and 12664 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ public class BlockUpdate implements IWorldCallable<Boolean>
{
if( world.isBlockLoaded( this.pos ) )
{
world.notifyNeighborsOfStateChange( this.pos, Platform.AIR_BLOCK, true );
world.notifyNeighborsOfStateChange( this.pos, Platform.AIR_BLOCK );
}
return true;
+5 -5
View File
@@ -23,7 +23,7 @@ import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import appeng.api.config.LevelEmitterMode;
import appeng.api.config.Settings;
@@ -82,11 +82,11 @@ public final class ConfigManager implements IConfigManager
* @param tagCompound to be written to compound
*/
@Override
public void writeToNBT( final NBTTagCompound tagCompound )
public void writeToNBT( final CompoundNBT tagCompound )
{
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
{
tagCompound.setString( entry.getKey().name(), this.settings.get( entry.getKey() ).toString() );
tagCompound.putString( entry.getKey().name(), this.settings.get( entry.getKey() ).toString() );
}
}
@@ -96,13 +96,13 @@ public final class ConfigManager implements IConfigManager
* @param tagCompound to be read from compound
*/
@Override
public void readFromNBT( final NBTTagCompound tagCompound )
public void readFromNBT( final CompoundNBT tagCompound )
{
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
{
try
{
if( tagCompound.hasKey( entry.getKey().name() ) )
if( tagCompound.contains( entry.getKey().name() ) )
{
String value = tagCompound.getString( entry.getKey().name() );
@@ -22,16 +22,16 @@ package appeng.util;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.AirBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
public class InWorldToolOperationResult
{
private final IBlockState blockState;
private final BlockState blockState;
private final List<ItemStack> drops;
public InWorldToolOperationResult()
@@ -40,13 +40,13 @@ public class InWorldToolOperationResult
this.drops = null;
}
public InWorldToolOperationResult( final IBlockState block, final List<ItemStack> drops )
public InWorldToolOperationResult( final BlockState block, final List<ItemStack> drops )
{
this.blockState = block;
this.drops = drops;
}
public InWorldToolOperationResult( final IBlockState block )
public InWorldToolOperationResult( final BlockState block )
{
this.blockState = block;
this.drops = null;
@@ -55,7 +55,7 @@ public class InWorldToolOperationResult
public static InWorldToolOperationResult getBlockOperationResult( final ItemStack[] items )
{
final List<ItemStack> temp = new ArrayList<>();
IBlockState b = null;
BlockState b = null;
for( final ItemStack l : items )
{
@@ -63,7 +63,7 @@ public class InWorldToolOperationResult
{
final Block bl = Block.getBlockFromItem( l.getItem() );
if( bl != null && !( bl instanceof BlockAir ) )
if( bl != null && !( bl instanceof AirBlock ) )
{
b = bl.getDefaultState();
continue;
@@ -76,7 +76,7 @@ public class InWorldToolOperationResult
return new InWorldToolOperationResult( b, temp );
}
public IBlockState getBlockState()
public BlockState getBlockState()
{
return this.blockState;
}
@@ -19,10 +19,10 @@
package appeng.util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
@@ -41,9 +41,9 @@ import appeng.util.inv.ItemSlot;
*/
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
{
public static InventoryAdaptor getAdaptor( final TileEntity te, final EnumFacing d )
public static InventoryAdaptor getAdaptor( final TileEntity te, final Direction d )
{
if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) )
if( te != null && te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) )
{
// Attempt getting an IItemHandler for the given side via caps
IItemHandler itemHandler = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d );
@@ -55,7 +55,7 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
return null;
}
public static InventoryAdaptor getAdaptor( final EntityPlayer te )
public static InventoryAdaptor getAdaptor( final PlayerEntity te )
{
if( te != null )
{
+68 -74
View File
@@ -36,45 +36,42 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerEntityMP;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.server.management.PlayerChunkMap;
import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
@@ -136,9 +133,6 @@ import appeng.util.prioritylist.IPartitionList;
*/
public class Platform
{
public static final Block AIR_BLOCK = Blocks.AIR;
public static final int DEF_OFFSET = 16;
private static final boolean CLIENT_INSTALL = FMLCommonHandler.instance().getSide().isClient();
@@ -147,7 +141,7 @@ public class Platform
* random source, use it for item drop locations...
*/
private static final Random RANDOM_GENERATOR = new Random();
private static final WeakHashMap<World, EntityPlayer> FAKE_PLAYERS = new WeakHashMap<>();
private static final WeakHashMap<World, PlayerEntity> FAKE_PLAYERS = new WeakHashMap<>();
// private static Method getEntry;
private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper();
@@ -231,7 +225,7 @@ public class Platform
return AEPartLocation.INTERNAL;
}
public static EnumFacing crossProduct( final EnumFacing forward, final EnumFacing up )
public static Direction crossProduct( final Direction forward, final Direction up )
{
final int west_x = forward.getFrontOffsetY() * up.getFrontOffsetZ() - forward.getFrontOffsetZ() * up.getFrontOffsetY();
final int west_y = forward.getFrontOffsetZ() * up.getFrontOffsetX() - forward.getFrontOffsetX() * up.getFrontOffsetZ();
@@ -240,23 +234,23 @@ public class Platform
switch( west_x + west_y * 2 + west_z * 3 )
{
case 1:
return EnumFacing.EAST;
return Direction.EAST;
case -1:
return EnumFacing.WEST;
return Direction.WEST;
case 2:
return EnumFacing.UP;
return Direction.UP;
case -2:
return EnumFacing.DOWN;
return Direction.DOWN;
case 3:
return EnumFacing.SOUTH;
return Direction.SOUTH;
case -3:
return EnumFacing.NORTH;
return Direction.NORTH;
}
// something is better then nothing?
return EnumFacing.NORTH;
return Direction.NORTH;
}
public static <T extends Enum> T rotateEnum( T ce, final boolean backwards, final EnumSet validOptions )
@@ -355,7 +349,7 @@ public class Platform
return false;
}
public static void openGUI( @Nonnull final EntityPlayer p, @Nullable final TileEntity tile, @Nullable final AEPartLocation side, @Nonnull final GuiBridge type )
public static void openGUI( @Nonnull final PlayerEntity p, @Nullable final TileEntity tile, @Nullable final AEPartLocation side, @Nonnull final GuiBridge type )
{
if( isClient() )
{
@@ -405,7 +399,7 @@ public class Platform
return CLIENT_INSTALL;
}
public static boolean hasPermissions( final DimensionalCoord dc, final EntityPlayer player )
public static boolean hasPermissions( final DimensionalCoord dc, final PlayerEntity player )
{
return dc.getWorld().canMineBlockBody( player, dc.getPos() );
}
@@ -428,7 +422,7 @@ public class Platform
public static ItemStack[] getBlockDrops( final World w, final BlockPos pos )
{
List<ItemStack> out = new ArrayList<>();
final IBlockState state = w.getBlockState( pos );
final BlockState state = w.getBlockState( pos );
if( state != null )
{
@@ -491,13 +485,13 @@ public class Platform
/*
* Creates / or loads previous NBT Data on items, used for editing items owned by AE.
*/
public static NBTTagCompound openNbtData( final ItemStack i )
public static CompoundNBT openNbtData( final ItemStack i )
{
NBTTagCompound compound = i.getTagCompound();
CompoundNBT compound = i.getTagCompound();
if( compound == null )
{
i.setTagCompound( compound = new NBTTagCompound() );
i.setTagCompound( compound = new CompoundNBT() );
}
return compound;
@@ -567,7 +561,7 @@ public class Platform
return CraftingManager.findMatchingResult( ic, world );
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public static List<String> getTooltip( final Object o )
{
if( o == null )
@@ -594,7 +588,7 @@ public class Platform
{
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft
.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
return itemStack.getTooltip( Minecraft.getMinecraft().player, tooltipFlag );
return itemStack.getTooltip( Minecraft.getInstance().player, tooltipFlag );
}
catch( final Exception errB )
{
@@ -651,7 +645,7 @@ public class Platform
String name = itemStack.getDisplayName();
if( name == null || name.isEmpty() )
{
name = itemStack.getItem().getUnlocalizedName( itemStack );
name = itemStack.getItem().getTranslationKey( itemStack );
}
return name == null ? "** Null" : name;
}
@@ -659,7 +653,7 @@ public class Platform
{
try
{
final String n = itemStack.getUnlocalizedName();
final String n = itemStack.getTranslationKey();
return n == null ? "** Null" : n;
}
catch( final Exception errB )
@@ -691,12 +685,12 @@ public class Platform
String n = fluidStack.getLocalizedName();
if( n == null || "".equalsIgnoreCase( n ) )
{
n = fluidStack.getUnlocalizedName();
n = fluidStack.getTranslationKey();
}
return n == null ? "** Null" : n;
}
public static boolean isWrench( final EntityPlayer player, final ItemStack eq, final BlockPos pos )
public static boolean isWrench( final PlayerEntity player, final ItemStack eq, final BlockPos pos )
{
if( !eq.isEmpty() )
{
@@ -744,20 +738,20 @@ public class Platform
return false;
}
public static EntityPlayer getPlayer( final WorldServer w )
public static PlayerEntity getPlayer( final ServerWorld w )
{
if( w == null )
{
throw new InvalidParameterException( "World is null." );
}
final EntityPlayer wrp = FAKE_PLAYERS.get( w );
final PlayerEntity wrp = FAKE_PLAYERS.get( w );
if( wrp != null )
{
return wrp;
}
final EntityPlayer p = FakePlayerFactory.getMinecraft( w );
final PlayerEntity p = FakePlayerFactory.getMinecraft( w );
FAKE_PLAYERS.put( w, p );
return p;
}
@@ -942,7 +936,7 @@ public class Platform
return forward;
}
public static EnumFacing rotateAround( final EnumFacing forward, final EnumFacing axis )
public static Direction rotateAround( final Direction forward, final Direction axis )
{
switch( forward )
{
@@ -954,13 +948,13 @@ public class Platform
case UP:
return forward;
case NORTH:
return EnumFacing.EAST;
return Direction.EAST;
case SOUTH:
return EnumFacing.WEST;
return Direction.WEST;
case EAST:
return EnumFacing.NORTH;
return Direction.NORTH;
case WEST:
return EnumFacing.SOUTH;
return Direction.SOUTH;
default:
break;
}
@@ -969,13 +963,13 @@ public class Platform
switch( axis )
{
case NORTH:
return EnumFacing.WEST;
return Direction.WEST;
case SOUTH:
return EnumFacing.EAST;
return Direction.EAST;
case EAST:
return EnumFacing.SOUTH;
return Direction.SOUTH;
case WEST:
return EnumFacing.NORTH;
return Direction.NORTH;
default:
break;
}
@@ -984,13 +978,13 @@ public class Platform
switch( axis )
{
case UP:
return EnumFacing.WEST;
return Direction.WEST;
case DOWN:
return EnumFacing.EAST;
return Direction.EAST;
case EAST:
return EnumFacing.UP;
return Direction.UP;
case WEST:
return EnumFacing.DOWN;
return Direction.DOWN;
default:
break;
}
@@ -999,13 +993,13 @@ public class Platform
switch( axis )
{
case UP:
return EnumFacing.EAST;
return Direction.EAST;
case DOWN:
return EnumFacing.WEST;
return Direction.WEST;
case EAST:
return EnumFacing.DOWN;
return Direction.DOWN;
case WEST:
return EnumFacing.UP;
return Direction.UP;
default:
break;
}
@@ -1014,13 +1008,13 @@ public class Platform
switch( axis )
{
case UP:
return EnumFacing.NORTH;
return Direction.NORTH;
case DOWN:
return EnumFacing.SOUTH;
return Direction.SOUTH;
case NORTH:
return EnumFacing.UP;
return Direction.UP;
case SOUTH:
return EnumFacing.DOWN;
return Direction.DOWN;
default:
break;
}
@@ -1028,13 +1022,13 @@ public class Platform
switch( axis )
{
case UP:
return EnumFacing.SOUTH;
return Direction.SOUTH;
case DOWN:
return EnumFacing.NORTH;
return Direction.NORTH;
case NORTH:
return EnumFacing.DOWN;
return Direction.DOWN;
case SOUTH:
return EnumFacing.UP;
return Direction.UP;
default:
break;
}
@@ -1044,13 +1038,13 @@ public class Platform
return forward;
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public static String gui_localize( final String string )
{
return I18n.translateToLocal( string );
}
public static LookDirection getPlayerRay( final EntityPlayer playerIn, final float eyeOffset )
public static LookDirection getPlayerRay( final PlayerEntity playerIn, final float eyeOffset )
{
double reachDistance = 5.0d;
@@ -1069,9 +1063,9 @@ public class Platform
final float eyeRayX = yawRayX * pitchMultiplier;
final float eyeRayZ = yawRayZ * pitchMultiplier;
if( playerIn instanceof EntityPlayerMP )
if( playerIn instanceof PlayerEntityMP )
{
reachDistance = ( (EntityPlayerMP) playerIn ).interactionManager.getBlockReachDistance();
reachDistance = ( (PlayerEntityMP) playerIn ).interactionManager.getBlockReachDistance();
}
final Vec3d from = new Vec3d( x, y, z );
@@ -1080,7 +1074,7 @@ public class Platform
return new LookDirection( from, to );
}
public static RayTraceResult rayTrace( final EntityPlayer p, final boolean hitBlocks, final boolean hitEntities )
public static RayTraceResult rayTrace( final PlayerEntity p, final boolean hitBlocks, final boolean hitEntities )
{
final World w = p.getEntityWorld();
@@ -1415,7 +1409,7 @@ public class Platform
return gs.hasPermission( playerID, SecurityPermissions.BUILD );
}
public static void configurePlayer( final EntityPlayer player, final AEPartLocation side, final TileEntity tile )
public static void configurePlayer( final PlayerEntity player, final AEPartLocation side, final TileEntity tile )
{
float pitch = 0.0f;
float yaw = 0.0f;
@@ -1654,7 +1648,7 @@ public class Platform
}
}
public static float getEyeOffset( final EntityPlayer player )
public static float getEyeOffset( final PlayerEntity player )
{
assert player.world.isRemote : "Valid only on client";
return (float) ( player.posY + player.getEyeHeight() - player.getDefaultEyeHeight() );
@@ -1662,7 +1656,7 @@ public class Platform
// public static void addStat( final int playerID, final Achievement achievement )
// {
// final EntityPlayer p = AEApi.instance().registries().players().findPlayer( playerID );
// final PlayerEntity p = AEApi.instance().registries().players().findPlayer( playerID );
// if( p != null )
// {
// p.addStat( achievement, 1 );
@@ -23,8 +23,7 @@ import javax.annotation.Nonnull;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraft.nbt.CompoundNBT;
import appeng.api.config.FuzzyMode;
import appeng.util.item.OreHelper;
@@ -50,15 +49,7 @@ public class ItemComparisonHelper
*/
public boolean isEqualItemType( @Nonnull final ItemStack that, @Nonnull final ItemStack other )
{
if( !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem() )
{
if( that.isItemStackDamageable() )
{
return true;
}
return that.getItemDamage() == other.getItemDamage();
}
return false;
return !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem();
}
/**
@@ -71,7 +62,7 @@ public class ItemComparisonHelper
*/
public boolean isSameItem( @Nonnull final ItemStack is, @Nonnull final ItemStack filter )
{
return ItemStack.areItemsEqual( is, filter ) && this.isNbtTagEqual( is.getTagCompound(), filter.getTagCompound() );
return ItemStack.areItemsEqual( is, filter ) && this.isNbtTagEqual( is.getTag(), filter.getTag() );
}
/**
@@ -103,12 +94,12 @@ public class ItemComparisonHelper
}
else if( mode == FuzzyMode.PERCENT_99 )
{
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
return ( a.getDamage() > 1 ) == ( b.getDamage() > 1 );
}
else
{
final float percentDamagedOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
final float percentDamagedOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
final float percentDamagedOfA = (float) a.getDamage() / a.getMaxDamage();
final float percentDamagedOfB = (float) b.getDamage() / b.getMaxDamage();
return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint );
}
@@ -130,15 +121,15 @@ public class ItemComparisonHelper
* then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive
* performance wise, so try an use shared tag compounds as long as the system remains in AE.
*/
public boolean isNbtTagEqual( final NBTBase left, final NBTBase right )
public boolean isNbtTagEqual( final CompoundNBT left, final CompoundNBT right )
{
if( left == right )
{
return true;
}
final boolean isLeftEmpty = left == null || left.hasNoTags();
final boolean isRightEmpty = right == null || right.hasNoTags();
final boolean isLeftEmpty = left == null || left.isEmpty();
final boolean isRightEmpty = right == null || right.isEmpty();
if( isLeftEmpty && isRightEmpty )
{
@@ -19,7 +19,7 @@
package appeng.util.helpers;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
@@ -72,7 +72,7 @@ public class ItemHandlerUtil
}
}
public static void copy( final InventoryCrafting from, final IItemHandler to, boolean deepCopy )
public static void copy( final CraftingInventory from, final IItemHandler to, boolean deepCopy )
{
for( int i = 0; i < Math.min( from.getSizeInventory(), to.getSlots() ); ++i )
{
@@ -19,7 +19,7 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
@@ -28,7 +28,7 @@ import appeng.util.Platform;
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler
{
public AdaptorItemHandlerPlayerInv( final EntityPlayer playerInv )
public AdaptorItemHandlerPlayerInv( final PlayerEntity playerInv )
{
super( new PlayerMainInvWrapper( playerInv.inventory ) );
}
@@ -19,20 +19,20 @@
package appeng.util.inv;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraftforge.items.ItemStackHandler;
public class WrapperCursorItemHandler extends ItemStackHandler
{
private final InventoryPlayer inv;
private final PlayerInventory inv;
public WrapperCursorItemHandler( InventoryPlayer inventoryPlayer )
public WrapperCursorItemHandler( PlayerInventory PlayerInventory )
{
super( 1 );
this.inv = inventoryPlayer;
this.setStackInSlot( 0, inventoryPlayer.getItemStack() );
this.inv = PlayerInventory;
this.setStackInSlot( 0, PlayerInventory.getItemStack() );
}
@Override
@@ -19,7 +19,7 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
@@ -109,19 +109,19 @@ public class WrapperInvItemHandler implements IInventory
}
@Override
public boolean isUsableByPlayer( EntityPlayer player )
public boolean isUsableByPlayer( PlayerEntity player )
{
return false;
}
@Override
public void openInventory( EntityPlayer player )
public void openInventory( PlayerEntity player )
{
// NOP
}
@Override
public void closeInventory( EntityPlayer player )
public void closeInventory( PlayerEntity player )
{
// NOP
}
+27 -59
View File
@@ -21,7 +21,6 @@ package appeng.util.item;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -30,11 +29,11 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.ItemHandlerHelper;
import appeng.api.AEApi;
@@ -48,13 +47,12 @@ import appeng.util.Platform;
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
{
private AESharedItemStack sharedStack;
private Optional<OreReference> oreReference;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private String displayName;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private List<String> tooltip;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private ResourceLocation uniqueID;
private AEItemStack( final AEItemStack is )
@@ -63,7 +61,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.sharedStack = is.sharedStack;
this.oreReference = is.oreReference;
}
private AEItemStack( final AESharedItemStack is, long size )
@@ -72,7 +69,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.setStackSize( size );
this.setCraftable( false );
this.setCountRequestable( 0 );
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
}
@Nullable
@@ -86,14 +82,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
}
public static IAEItemStack fromNBT( final NBTTagCompound i )
public static IAEItemStack fromNBT( final CompoundNBT i )
{
if( i == null )
{
return null;
}
final ItemStack itemstack = new ItemStack( i );
final ItemStack itemstack = ItemStack.read( i );
if( itemstack.isEmpty() )
{
return null;
@@ -107,12 +103,12 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
@Override
public void writeToNBT( final NBTTagCompound i )
public void writeToNBT( final CompoundNBT i )
{
this.getDefinition().writeToNBT( i );
i.setLong( "Cnt", this.getStackSize() );
i.setLong( "Req", this.getCountRequestable() );
i.setBoolean( "Craft", this.isCraftable() );
this.getDefinition().write( i );
i.putLong( "Cnt", this.getStackSize() );
i.putLong( "Req", this.getCountRequestable() );
i.putBoolean( "Craft", this.isCraftable() );
}
public static AEItemStack fromPacket( final ByteBuf data )
@@ -122,7 +118,8 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
final boolean isCraftable = ( mask & 0x40 ) > 0;
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
final PacketBuffer p = new PacketBuffer( data );
final ItemStack itemstack = p.readItemStack();
final long stackSize = getPacketValue( stackType, data );
final long countRequestable = getPacketValue( countReqType, data );
@@ -138,13 +135,13 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
@Override
public void writeToPacket( final ByteBuf i )
public void writeToPacket( final PacketBuffer i )
{
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
i.writeByte( mask );
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
i.writeCompoundTag( this.getDefinition().serializeNBT() );
this.putPacketValue( i, this.getStackSize() );
this.putPacketValue( i, this.getCountRequestable() );
}
@@ -165,11 +162,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@Override
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
{
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
{
return true;
}
final ItemStack itemStack = this.getDefinition();
final ItemStack otherStack = other.getDefinition();
@@ -218,12 +210,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.sharedStack.getItemDamage();
}
@Override
public boolean sameOre( final IAEItemStack is )
{
return OreHelper.INSTANCE.sameOre( this, is );
}
@Override
public boolean isSameType( final IAEItemStack otherStack )
{
@@ -274,10 +260,10 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public List<String> getToolTip()
{
if( this.tooltip == null )
@@ -287,7 +273,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.tooltip;
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public String getDisplayName()
{
if( this.displayName == null )
@@ -297,31 +283,16 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.displayName;
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public String getModID()
{
if( this.uniqueID == null )
{
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
}
if( this.uniqueID == null )
{
return "** Null";
}
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
}
public Optional<OreReference> getOre()
{
return this.oreReference;
return this.getDefinition().getItem().getRegistryName().getNamespace();
}
@Override
public boolean hasTagCompound()
{
return this.getDefinition().hasTagCompound();
return this.getDefinition().hasTag();
}
@Override
@@ -353,21 +324,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
else if( mode == FuzzyMode.PERCENT_99 )
{
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
return ( a.getDamage() > 1 ) == ( b.getDamage() > 1 );
}
else
{
final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
final float percentDamageOfA = (float) a.getDamage() / a.getMaxDamage();
final float percentDamageOfB = (float) b.getDamage() / b.getMaxDamage();
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
}
}
return a.getMetadata() == b.getMetadata();
}
return false;
}
}
@@ -25,15 +25,15 @@ import com.google.common.base.Preconditions;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import appeng.api.config.FuzzyMode;
final class AESharedItemStack implements Comparable<AESharedItemStack>
{
private static final NBTTagCompound LOW_TAG = new NBTTagCompound();
private static final NBTTagCompound HIGH_TAG = new NBTTagCompound();
private static final CompoundNBT LOW_TAG = new CompoundNBT();
private static final CompoundNBT HIGH_TAG = new CompoundNBT();
private final ItemStack itemStack;
private final int itemId;
@@ -44,7 +44,7 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
this.itemStack = itemStack;
this.itemId = Item.getIdFromItem( itemStack.getItem() );
this.itemDamage = itemStack.getItemDamage();
this.itemDamage = itemStack.getDamage();
this.hashCode = this.makeHashCode();
}
@@ -131,24 +131,24 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
private int compareNBT( final ItemStack b )
{
if( this.itemStack.getTagCompound() == b.getTagCompound() )
if( this.itemStack.getTag() == b.getTag() )
{
return 0;
}
if( this.itemStack.getTagCompound() == LOW_TAG || b.getTagCompound() == HIGH_TAG )
if( this.itemStack.getTag() == LOW_TAG || b.getTag() == HIGH_TAG )
{
return -1;
}
if( this.itemStack.getTagCompound() == HIGH_TAG || b.getTagCompound() == LOW_TAG )
if( this.itemStack.getTag() == HIGH_TAG || b.getTag() == LOW_TAG )
{
return 1;
}
return System.identityHashCode( this.itemStack.getTagCompound() ) - System.identityHashCode( b.getTagCompound() );
return System.identityHashCode( this.itemStack.getTag() ) - System.identityHashCode( b.getTag() );
}
private int makeHashCode()
{
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTag() ? this.itemStack.getTag() : 0 );
}
/**
@@ -170,7 +170,7 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
Preconditions.checkState( !stack.isEmpty(), "ItemStack#isEmpty() has to be false" );
Preconditions.checkState( stack.getCount() == 1, "ItemStack#getCount() has to be 1" );
final NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : null;
final CompoundNBT tag = stack.hasTag() ? stack.getTag() : null;
this.lower = this.makeLowerBound( stack, tag, fuzzy, ignoreMeta );
this.upper = this.makeUpperBound( stack, tag, fuzzy, ignoreMeta );
@@ -186,14 +186,14 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
return this.upper;
}
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
final ItemStack newDef = itemStack.copy();
if( ignoreMeta )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setTagCompound( tag );
newDef.setDamage( MIN_DAMAGE_VALUE );
newDef.setTag( tag );
}
else
{
@@ -201,40 +201,40 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else if( fuzzy == FuzzyMode.PERCENT_99 )
{
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else
{
newDef.setItemDamage( MIN_DAMAGE_VALUE + 1 );
newDef.setDamage( MIN_DAMAGE_VALUE + 1 );
}
}
else
{
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
final int damage = breakpoint <= itemStack.getItemDamage() ? breakpoint : 0;
newDef.setItemDamage( damage );
final int damage = breakpoint <= itemStack.getDamage() ? breakpoint : 0;
newDef.setDamage( damage );
}
}
newDef.setTagCompound( LOW_TAG );
newDef.setTag( LOW_TAG );
}
return new AESharedItemStack( newDef );
}
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
final ItemStack newDef = itemStack.copy();
if( ignoreMeta )
{
newDef.setItemDamage( MAX_DAMAGE_VALUE );
newDef.setTagCompound( tag );
newDef.setDamage( MAX_DAMAGE_VALUE );
newDef.setTag( tag );
}
else
{
@@ -242,27 +242,27 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
newDef.setDamage( itemStack.getMaxDamage() + 1 );
}
else if( fuzzy == FuzzyMode.PERCENT_99 )
{
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else
{
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
newDef.setDamage( itemStack.getMaxDamage() + 1 );
}
}
else
{
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
final int damage = itemStack.getItemDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
newDef.setItemDamage( damage );
final int damage = itemStack.getDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
newDef.setDamage( damage );
}
}
newDef.setTagCompound( HIGH_TAG );
newDef.setTag( HIGH_TAG );
}
return new AESharedItemStack( newDef );
+1 -23
View File
@@ -19,15 +19,12 @@
package appeng.util.item;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@@ -81,26 +78,7 @@ public final class ItemList implements IItemList<IAEItemStack>
final AEItemStack ais = (AEItemStack) filter;
return ais.getOre().map( or ->
{
if( or.getAEEquivalents().size() == 1 )
{
final IAEItemStack is = or.getAEEquivalents().get( 0 );
return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
}
else
{
final Collection<IAEItemStack> output = new ArrayList<>();
for( final IAEItemStack is : or.getAEEquivalents() )
{
output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
}
return output;
}
} ).orElse( this.findFuzzyDamage( ais, fuzzy, false ) );
return this.findFuzzyDamage( ais, fuzzy, false );
}
@Override
@@ -1,222 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 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, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 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 Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.item;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.storage.data.IAEItemStack;
public class OreHelper
{
public static final OreHelper INSTANCE = new OreHelper();
/**
* A local cache to speed up OreDictionary lookups.
*/
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
{
@Override
public List<ItemStack> load( final String oreName )
{
return OreDictionary.getOres( oreName );
}
} );
private final Map<ItemRef, OreReference> references = new HashMap<>();
/**
* Test if the passed {@link ItemStack} is an ore.
*
* @param itemStack the itemstack to test
*
* @return true if an ore entry exists, false otherwise
*/
public Optional<OreReference> getOre( final ItemStack itemStack )
{
final ItemRef ir = new ItemRef( itemStack );
if( !this.references.containsKey( ir ) )
{
final OreReference ref = new OreReference();
final Collection<Integer> ores = ref.getOres();
final Collection<String> set = ref.getEquivalents();
final Set<String> toAdd = new HashSet<>();
for( final String ore : OreDictionary.getOreNames() )
{
// skip ore if it is a match already or null.
if( ore == null || toAdd.contains( ore ) )
{
continue;
}
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
{
if( OreDictionary.itemMatches( oreItem, itemStack, false ) )
{
toAdd.add( ore );
break;
}
}
}
for( final String ore : toAdd )
{
set.add( ore );
ores.add( OreDictionary.getOreID( ore ) );
}
if( !set.isEmpty() )
{
this.references.put( ir, ref );
}
else
{
this.references.put( ir, null );
}
}
return Optional.ofNullable( this.references.get( ir ) );
}
boolean sameOre( final AEItemStack aeItemStack, final IAEItemStack is )
{
final OreReference a = aeItemStack.getOre().orElse( null );
final OreReference b = aeItemStack.getOre().orElse( null );
return this.sameOre( a, b );
}
public boolean sameOre( final OreReference a, final OreReference b )
{
if( a == null || b == null )
{
return false;
}
if( a == b )
{
return true;
}
final Collection<Integer> bOres = b.getOres();
for( final Integer ore : a.getOres() )
{
if( bOres.contains( ore ) )
{
return true;
}
}
return false;
}
boolean sameOre( final AEItemStack aeItemStack, final ItemStack o )
{
return aeItemStack.getOre().map( a ->
{
for( final String oreName : a.getEquivalents() )
{
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
{
if( OreDictionary.itemMatches( oreItem, o, false ) )
{
return true;
}
}
}
return false;
} )
.orElse( false );
}
List<ItemStack> getCachedOres( final String oreName )
{
return this.oreDictCache.getUnchecked( oreName );
}
private static class ItemRef
{
private final Item ref;
private final int damage;
private final int hash;
ItemRef( final ItemStack stack )
{
this.ref = stack.getItem();
if( stack.getItem().isDamageable() )
{
this.damage = 0; // IGNORED
}
else
{
this.damage = stack.getItemDamage(); // might be important...
}
this.hash = this.ref.hashCode() ^ this.damage;
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final ItemRef other = (ItemRef) obj;
return this.damage == other.damage && this.ref == other.ref;
}
@Override
public String toString()
{
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
}
}
}
@@ -1,72 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 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, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 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 Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.item;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
public class OreReference
{
private final List<String> otherOptions = new ArrayList<>();
private final Set<Integer> ores = new HashSet<>();
private List<IAEItemStack> aeOtherOptions = null;
Collection<String> getEquivalents()
{
return this.otherOptions;
}
List<IAEItemStack> getAEEquivalents()
{
if( this.aeOtherOptions == null )
{
this.aeOtherOptions = new ArrayList<>( this.otherOptions.size() );
// SUMMON AE STACKS!
for( final String oreName : this.otherOptions )
{
for( final ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
{
if( is.getItem() != Items.AIR )
{
this.aeOtherOptions.add( AEItemStack.fromItemStack( is ) );
}
}
}
}
return this.aeOtherOptions;
}
Collection<Integer> getOres()
{
return this.ores;
}
}