GUI Rendering and various fixes

This commit is contained in:
Sebastian Hartte
2020-06-07 03:29:57 +02:00
parent 97f04922b9
commit 46b1d1ffdc
72 changed files with 650 additions and 552 deletions
@@ -19,13 +19,13 @@
package appeng.items.misc;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import appeng.api.util.AEColor;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
@@ -33,14 +33,14 @@ import net.minecraft.util.text.TranslationTextComponent;
public class ItemPaintBall extends AEBaseItem
{
private static final String TAG_COLOR = "c";
private static final String TAG_LUMEN = "l";
private static final ITextComponent LUMEN_PREFIX = new TranslationTextComponent(GuiText.Lumen.getTranslationKey())
.appendText(" ");
private static final int DAMAGE_THRESHOLD = 20;
public ItemPaintBall(Properties properties) {
super(properties);
// FIXME this.setHasSubtypes( true );
}
@Override
@@ -54,7 +54,7 @@ public class ItemPaintBall extends AEBaseItem
private ITextComponent getExtraName( final ItemStack is )
{
ITextComponent colorText = new TranslationTextComponent(this.getColor(is).translationKey);
if (is.getDamage() >= DAMAGE_THRESHOLD) {
if (isLumen(is)) {
return LUMEN_PREFIX.shallowCopy().appendSibling(colorText);
} else {
return colorText;
@@ -63,18 +63,33 @@ public class ItemPaintBall extends AEBaseItem
public AEColor getColor( final ItemStack is )
{
int dmg = is.getDamage();
if( dmg >= DAMAGE_THRESHOLD )
{
dmg -= DAMAGE_THRESHOLD;
}
if( dmg >= AEColor.values().length )
{
CompoundNBT tag = is.getTag();
if (tag == null || !tag.contains(TAG_COLOR)) {
return AEColor.TRANSPARENT;
}
int c = tag.getInt(TAG_COLOR);
if (c < 0 || c >= AEColor.values().length) {
return AEColor.TRANSPARENT;
}
return AEColor.values()[c];
}
return AEColor.values()[dmg];
public ItemStack setColor( final ItemStack is, AEColor color )
{
is.getOrCreateTag().putInt(TAG_COLOR, color.ordinal());
return is;
}
public boolean isLumen( final ItemStack is )
{
CompoundNBT tag = is.getTag();
return tag != null && tag.getBoolean(TAG_LUMEN);
}
public ItemStack setLumen( final ItemStack is, boolean lumen )
{
is.getOrCreateTag().putBoolean(TAG_LUMEN, lumen);
return is;
}
@Override
@@ -84,7 +99,7 @@ public class ItemPaintBall extends AEBaseItem
{
if( c != AEColor.TRANSPARENT )
{
itemStacks.add( new ItemStack( this, 1 /* FIXME, c.ordinal() */ ) );
itemStacks.add( setColor(new ItemStack( this ), c) );
}
}
@@ -92,15 +107,9 @@ public class ItemPaintBall extends AEBaseItem
{
if( c != AEColor.TRANSPARENT )
{
itemStacks.add( new ItemStack( this, 1 /* FIXME , DAMAGE_THRESHOLD + c.ordinal() */ ) );
itemStacks.add( setLumen(setColor(new ItemStack( this ), c), true) );
}
}
}
public static boolean isLumen( final ItemStack is )
{
final int dmg = is.getDamage();
return dmg >= DAMAGE_THRESHOLD;
}
}
@@ -44,14 +44,16 @@ public class ItemPaintBallRendering extends ItemRenderingCustomizer
private static int getColorFromItemstack( ItemStack stack, int tintIndex )
{
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
ItemPaintBall item = (ItemPaintBall) stack.getItem();
final AEColor col = item.getColor( stack );
final int colorValue = stack.getDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
boolean lumen = item.isLumen(stack);
final int colorValue = lumen ? col.mediumVariant : col.mediumVariant;
final int r = ( colorValue >> 16 ) & 0xff;
final int g = ( colorValue >> 8 ) & 0xff;
final int b = ( colorValue ) & 0xff;
if( stack.getDamage() >= 20 )
if( lumen )
{
final float fail = 0.7f;
final int full = (int) ( 255 * 0.3 );
@@ -36,6 +36,7 @@ import appeng.block.networking.BlockCableBus;
import appeng.block.paint.BlockPaint;
import appeng.core.AEConfig;
import appeng.core.Api;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import appeng.helpers.IMouseWheelItem;
import appeng.hooks.IBlockTool;
@@ -59,6 +60,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
@@ -76,6 +78,8 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
private static final String TAG_COLOR = "color";
static
{
for( final AEColor color : AEColor.VALID_COLORS )
@@ -91,6 +95,16 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
public ToolColorApplicator(Item.Properties props)
{
super( AEConfig.instance().getColorApplicatorBattery(), props );
addPropertyOverride(
new ResourceLocation(AppEng.MOD_ID, "colored"),
(itemStack, world, entity) -> {
// If the stack has no color, don't use the colored model since the impact of calling getColor
// for every quad is extremely high, if the stack tries to re-search its inventory for a new
// paintball everytime
AEColor col = getActiveColor( itemStack );
return ( col != null ) ? 1 : 0;
}
);
}
@Override
@@ -239,9 +253,9 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
public ItemStack getColor( final ItemStack is )
{
final CompoundNBT c = is.getTag();
if( c != null && c.contains("color") )
if( c != null && c.contains(TAG_COLOR) )
{
final CompoundNBT color = c.getCompound( "color" );
final CompoundNBT color = c.getCompound( TAG_COLOR );
final ItemStack oldColor = ItemStack.read(color);
if( !oldColor.isEmpty() )
{
@@ -326,13 +340,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
final CompoundNBT data = is.getOrCreateTag();
if( newColor.isEmpty() )
{
data.remove( "color" );
data.remove( TAG_COLOR );
}
else
{
final CompoundNBT color = new CompoundNBT();
newColor.write(color);
data.put( "color", color );
data.put( TAG_COLOR, color );
}
}
@@ -447,25 +461,25 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
@Override
public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition )
{
// FIXME if( requestedAddition != null )
// FIXME {
// FIXME final int[] id = OreDictionary.getOreIDs( requestedAddition.getDefinition() );
// FIXME
// FIXME for( final int x : id )
// FIXME {
// FIXME if( ORE_TO_COLOR.containsKey( x ) )
// FIXME {
// FIXME return false;
// FIXME }
// FIXME }
// FIXME
// FIXME if( requestedAddition.getItem() instanceof SnowballItem )
// FIXME {
// FIXME return false;
// FIXME }
// FIXME
// FIXME return !( requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20 );
// FIXME }
if( requestedAddition != null )
{
// FIXME final int[] id = OreDictionary.getOreIDs( requestedAddition.getDefinition() );
// FIXME for( final int x : id )
// FIXME {
// FIXME if( ORE_TO_COLOR.containsKey( x ) )
// FIXME {
// FIXME return false;
// FIXME }
// FIXME }
if( requestedAddition.getItem() instanceof SnowballItem )
{
return false;
}
return !( requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20 );
}
return true;
}
@@ -542,4 +556,5 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{
this.cycleColors( is, this.getColor( is ), up ? 1 : -1 );
}
}