Major Refactoring of Bootstrap Code (#75)
- Refactored boostrap code: * Completely reworked item/block/tile registration. * Fixed server side startup. * Fixed server side startup. * More documentation. * More heavy cleanup * More cleanups. * Major refactoring of state mapping and fixes a lot of other issue related to item rendering. * Fixes sky chest item models (no item TESR). * Only use CachingRotatingBakedModel for tile entities automatically. Fix default rotation of quartz pillar for item model. * Used method reference instead of lambda for ItemMeshDefinition for multiparts. * Removed unnecessary IHasSpecialItemModel * Removed unused IconReg class. * Updated resource pack version.
This commit is contained in:
committed by
Sebastian Hartte
parent
66df324ef0
commit
6f2bbfab4c
@@ -19,34 +19,25 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IGrowableCrystal;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.ButtonToolTips;
|
||||
import appeng.entity.EntityGrowingCrystal;
|
||||
import appeng.entity.EntityIds;
|
||||
@@ -57,8 +48,8 @@ import appeng.util.Platform;
|
||||
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
{
|
||||
|
||||
private static final int LEVEL_OFFSET = 200;
|
||||
private static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
||||
static final int LEVEL_OFFSET = 200;
|
||||
static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
||||
|
||||
public static final int CERTUS = 0;
|
||||
public static final int NETHER = SINGLE_OFFSET;
|
||||
@@ -68,7 +59,6 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
public ItemCrystalSeed()
|
||||
{
|
||||
this.setHasSubtypes( true );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
|
||||
EntityRegistry.registerModEntity( EntityGrowingCrystal.class, EntityGrowingCrystal.class.getSimpleName(), EntityIds.get( EntityGrowingCrystal.class ), AppEng.instance(), 16, 4, true );
|
||||
}
|
||||
@@ -94,7 +84,7 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static int getProgress( final ItemStack is )
|
||||
static int getProgress( final ItemStack is )
|
||||
{
|
||||
if( is.hasTagCompound() )
|
||||
{
|
||||
@@ -259,72 +249,4 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) );
|
||||
}
|
||||
|
||||
private static final ModelResourceLocation[] MODELS_CERTUS = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_FLUIX = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_NETHER = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether3" )
|
||||
};
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public List<ResourceLocation> getItemVariants()
|
||||
{
|
||||
return ImmutableList.<ResourceLocation>builder().add( MODELS_CERTUS ).add( MODELS_FLUIX ).add( MODELS_NETHER ).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public ItemMeshDefinition getItemMeshDefinition()
|
||||
{
|
||||
return is -> {
|
||||
int damage = getProgress( is );
|
||||
|
||||
// Split the damage value into crystal type and growth level
|
||||
int type = damage / SINGLE_OFFSET;
|
||||
int level = ( damage % SINGLE_OFFSET ) / LEVEL_OFFSET;
|
||||
|
||||
// Determine which list of models to use based on the type of crystal
|
||||
ModelResourceLocation[] models;
|
||||
switch( type )
|
||||
{
|
||||
case 0:
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
case 1:
|
||||
models = MODELS_NETHER;
|
||||
break;
|
||||
case 2:
|
||||
models = MODELS_FLUIX;
|
||||
break;
|
||||
default:
|
||||
// We use this as the fallback for broken items
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
}
|
||||
|
||||
// Return one of the 3 models based on the level
|
||||
if( level < 0 )
|
||||
{
|
||||
level = 0;
|
||||
}
|
||||
else if( level >= models.length )
|
||||
{
|
||||
level = models.length - 1;
|
||||
}
|
||||
|
||||
return models[level];
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
|
||||
|
||||
public class ItemCrystalSeedRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
|
||||
private static final ModelResourceLocation[] MODELS_CERTUS = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_FLUIX = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_NETHER = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether3" )
|
||||
};
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
rendering.variants( ImmutableList.<ResourceLocation>builder().add( MODELS_CERTUS ).add( MODELS_FLUIX ).add( MODELS_NETHER ).build() );
|
||||
rendering.meshDefinition( getItemMeshDefinition() );
|
||||
}
|
||||
|
||||
private ItemMeshDefinition getItemMeshDefinition()
|
||||
{
|
||||
return is ->
|
||||
{
|
||||
int damage = ItemCrystalSeed.getProgress( is );
|
||||
|
||||
// Split the damage value into crystal type and growth level
|
||||
int type = damage / ItemCrystalSeed.SINGLE_OFFSET;
|
||||
int level = ( damage % ItemCrystalSeed.SINGLE_OFFSET ) / ItemCrystalSeed.LEVEL_OFFSET;
|
||||
|
||||
// Determine which list of models to use based on the type of crystal
|
||||
ModelResourceLocation[] models;
|
||||
switch( type )
|
||||
{
|
||||
case 0:
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
case 1:
|
||||
models = MODELS_NETHER;
|
||||
break;
|
||||
case 2:
|
||||
models = MODELS_FLUIX;
|
||||
break;
|
||||
default:
|
||||
// We use this as the fallback for broken items
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
}
|
||||
|
||||
// Return one of the 3 models based on the level
|
||||
if( level < 0 )
|
||||
{
|
||||
level = 0;
|
||||
}
|
||||
else if( level >= models.length )
|
||||
{
|
||||
level = models.length - 1;
|
||||
}
|
||||
|
||||
return models[level];
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,10 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -37,16 +33,12 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.items.AEBaseItem;
|
||||
@@ -60,7 +52,6 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
|
||||
public ItemEncodedPattern()
|
||||
{
|
||||
this.setFeature( EnumSet.of( AEFeature.Patterns ) );
|
||||
this.setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
|
||||
@@ -19,22 +19,13 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
|
||||
@@ -46,7 +37,6 @@ public class ItemPaintBall extends AEBaseItem
|
||||
|
||||
public ItemPaintBall()
|
||||
{
|
||||
this.setFeature( EnumSet.of( AEFeature.PaintBalls ) );
|
||||
this.setHasSubtypes( true );
|
||||
}
|
||||
|
||||
@@ -97,49 +87,10 @@ public class ItemPaintBall extends AEBaseItem
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLumen( final ItemStack is )
|
||||
public static boolean isLumen( final ItemStack is )
|
||||
{
|
||||
final int dmg = is.getItemDamage();
|
||||
return dmg >= DAMAGE_THRESHOLD;
|
||||
}
|
||||
|
||||
public static int getColorFromItemstack( ItemStack stack, int tintIndex )
|
||||
{
|
||||
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
|
||||
|
||||
final int colorValue = stack.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
|
||||
final int r = ( colorValue >> 16 ) & 0xff;
|
||||
final int g = ( colorValue >> 8 ) & 0xff;
|
||||
final int b = ( colorValue ) & 0xff;
|
||||
|
||||
if( stack.getItemDamage() >= 20 )
|
||||
{
|
||||
final float fail = 0.7f;
|
||||
final int full = (int) ( 255 * 0.3 );
|
||||
return (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r << 16 | g << 8 | b | 0xff << 24;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation( "appliedenergistics2:ItemPaintBall" );
|
||||
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation( "appliedenergistics2:ItemPaintBallShimmer" );
|
||||
|
||||
@Override
|
||||
public List<ResourceLocation> getItemVariants()
|
||||
{
|
||||
return ImmutableList.of(
|
||||
MODEL_NORMAL,
|
||||
MODEL_SHIMMER
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public ItemMeshDefinition getItemMeshDefinition()
|
||||
{
|
||||
return is -> isLumen( is ) ? MODEL_SHIMMER : MODEL_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
|
||||
|
||||
public class ItemPaintBallRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
|
||||
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation( "appliedenergistics2:paint_ball" );
|
||||
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation( "appliedenergistics2:paint_ball_shimmer" );
|
||||
|
||||
@Override
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
rendering.color( ItemPaintBallRendering::getColorFromItemstack );
|
||||
rendering.variants( MODEL_NORMAL, MODEL_SHIMMER );
|
||||
rendering.meshDefinition( is -> ItemPaintBall.isLumen( is ) ? MODEL_SHIMMER : MODEL_NORMAL );
|
||||
}
|
||||
|
||||
private static int getColorFromItemstack( ItemStack stack, int tintIndex )
|
||||
{
|
||||
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
|
||||
|
||||
final int colorValue = stack.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
|
||||
final int r = ( colorValue >> 16 ) & 0xff;
|
||||
final int g = ( colorValue >> 8 ) & 0xff;
|
||||
final int b = ( colorValue ) & 0xff;
|
||||
|
||||
if( stack.getItemDamage() >= 20 )
|
||||
{
|
||||
final float fail = 0.7f;
|
||||
final int full = (int) ( 255 * 0.3 );
|
||||
return (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r << 16 | g << 8 | b | 0xff << 24;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user