Fixes the color applicator

This commit is contained in:
Sebastian Hartte
2020-06-21 20:41:04 +02:00
parent 8ed68d9c74
commit 8606bd5c61
5 changed files with 271 additions and 135 deletions
@@ -0,0 +1,167 @@
package appeng.items.tools.powered;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.EnumHashBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import appeng.api.util.AEColor;
/**
* Allows recoloring a variety of vanilla blocks.
*/
public final class BlockRecolorer {
private BlockRecolorer() {
}
private static final BiMap<AEColor, Block> STAINED_GLASS_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_STAINED_GLASS)
.put(AEColor.ORANGE, Blocks.ORANGE_STAINED_GLASS).put(AEColor.MAGENTA, Blocks.MAGENTA_STAINED_GLASS)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_STAINED_GLASS).put(AEColor.YELLOW, Blocks.YELLOW_STAINED_GLASS)
.put(AEColor.LIME, Blocks.LIME_STAINED_GLASS).put(AEColor.PINK, Blocks.PINK_STAINED_GLASS)
.put(AEColor.GRAY, Blocks.GRAY_STAINED_GLASS).put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_STAINED_GLASS)
.put(AEColor.CYAN, Blocks.CYAN_STAINED_GLASS).put(AEColor.PURPLE, Blocks.PURPLE_STAINED_GLASS)
.put(AEColor.BLUE, Blocks.BLUE_STAINED_GLASS).put(AEColor.BROWN, Blocks.BROWN_STAINED_GLASS)
.put(AEColor.GREEN, Blocks.GREEN_STAINED_GLASS).put(AEColor.RED, Blocks.RED_STAINED_GLASS)
.put(AEColor.BLACK, Blocks.BLACK_STAINED_GLASS).build());
private static final BiMap<AEColor, Block> STAINED_GLASS_PANE_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_STAINED_GLASS_PANE)
.put(AEColor.ORANGE, Blocks.ORANGE_STAINED_GLASS_PANE)
.put(AEColor.MAGENTA, Blocks.MAGENTA_STAINED_GLASS_PANE)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_STAINED_GLASS_PANE)
.put(AEColor.YELLOW, Blocks.YELLOW_STAINED_GLASS_PANE).put(AEColor.LIME, Blocks.LIME_STAINED_GLASS_PANE)
.put(AEColor.PINK, Blocks.PINK_STAINED_GLASS_PANE).put(AEColor.GRAY, Blocks.GRAY_STAINED_GLASS_PANE)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_STAINED_GLASS_PANE)
.put(AEColor.CYAN, Blocks.CYAN_STAINED_GLASS_PANE).put(AEColor.PURPLE, Blocks.PURPLE_STAINED_GLASS_PANE)
.put(AEColor.BLUE, Blocks.BLUE_STAINED_GLASS_PANE).put(AEColor.BROWN, Blocks.BROWN_STAINED_GLASS_PANE)
.put(AEColor.GREEN, Blocks.GREEN_STAINED_GLASS_PANE).put(AEColor.RED, Blocks.RED_STAINED_GLASS_PANE)
.put(AEColor.BLACK, Blocks.BLACK_STAINED_GLASS_PANE).build());
private static final BiMap<AEColor, Block> WOOL_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_WOOL).put(AEColor.ORANGE, Blocks.ORANGE_WOOL)
.put(AEColor.MAGENTA, Blocks.MAGENTA_WOOL).put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_WOOL)
.put(AEColor.YELLOW, Blocks.YELLOW_WOOL).put(AEColor.LIME, Blocks.LIME_WOOL)
.put(AEColor.PINK, Blocks.PINK_WOOL).put(AEColor.GRAY, Blocks.GRAY_WOOL)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_WOOL).put(AEColor.CYAN, Blocks.CYAN_WOOL)
.put(AEColor.PURPLE, Blocks.PURPLE_WOOL).put(AEColor.BLUE, Blocks.BLUE_WOOL)
.put(AEColor.BROWN, Blocks.BROWN_WOOL).put(AEColor.GREEN, Blocks.GREEN_WOOL)
.put(AEColor.RED, Blocks.RED_WOOL).put(AEColor.BLACK, Blocks.BLACK_WOOL).build());
private static final BiMap<AEColor, Block> BANNER_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_BANNER).put(AEColor.ORANGE, Blocks.ORANGE_BANNER)
.put(AEColor.MAGENTA, Blocks.MAGENTA_BANNER).put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_BANNER)
.put(AEColor.YELLOW, Blocks.YELLOW_BANNER).put(AEColor.LIME, Blocks.LIME_BANNER)
.put(AEColor.PINK, Blocks.PINK_BANNER).put(AEColor.GRAY, Blocks.GRAY_BANNER)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_BANNER).put(AEColor.CYAN, Blocks.CYAN_BANNER)
.put(AEColor.PURPLE, Blocks.PURPLE_BANNER).put(AEColor.BLUE, Blocks.BLUE_BANNER)
.put(AEColor.BROWN, Blocks.BROWN_BANNER).put(AEColor.GREEN, Blocks.GREEN_BANNER)
.put(AEColor.RED, Blocks.RED_BANNER).put(AEColor.BLACK, Blocks.BLACK_BANNER).build());
private static final BiMap<AEColor, Block> WALL_BANNER_BY_COLOR = EnumHashBiMap
.create(ImmutableMap.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_WALL_BANNER)
.put(AEColor.ORANGE, Blocks.ORANGE_WALL_BANNER).put(AEColor.MAGENTA, Blocks.MAGENTA_WALL_BANNER)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_WALL_BANNER)
.put(AEColor.YELLOW, Blocks.YELLOW_WALL_BANNER).put(AEColor.LIME, Blocks.LIME_WALL_BANNER)
.put(AEColor.PINK, Blocks.PINK_WALL_BANNER).put(AEColor.GRAY, Blocks.GRAY_WALL_BANNER)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_WALL_BANNER).put(AEColor.CYAN, Blocks.CYAN_WALL_BANNER)
.put(AEColor.PURPLE, Blocks.PURPLE_WALL_BANNER).put(AEColor.BLUE, Blocks.BLUE_WALL_BANNER)
.put(AEColor.BROWN, Blocks.BROWN_WALL_BANNER).put(AEColor.GREEN, Blocks.GREEN_WALL_BANNER)
.put(AEColor.RED, Blocks.RED_WALL_BANNER).put(AEColor.BLACK, Blocks.BLACK_WALL_BANNER).build());
private static final BiMap<AEColor, Block> CARPET_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_CARPET).put(AEColor.ORANGE, Blocks.ORANGE_CARPET)
.put(AEColor.MAGENTA, Blocks.MAGENTA_CARPET).put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_CARPET)
.put(AEColor.YELLOW, Blocks.YELLOW_CARPET).put(AEColor.LIME, Blocks.LIME_CARPET)
.put(AEColor.PINK, Blocks.PINK_CARPET).put(AEColor.GRAY, Blocks.GRAY_CARPET)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_CARPET).put(AEColor.CYAN, Blocks.CYAN_CARPET)
.put(AEColor.PURPLE, Blocks.PURPLE_CARPET).put(AEColor.BLUE, Blocks.BLUE_CARPET)
.put(AEColor.BROWN, Blocks.BROWN_CARPET).put(AEColor.GREEN, Blocks.GREEN_CARPET)
.put(AEColor.RED, Blocks.RED_CARPET).put(AEColor.BLACK, Blocks.BLACK_CARPET).build());
private static final BiMap<AEColor, Block> TERRACOTTA_BY_COLOR = EnumHashBiMap
.create(ImmutableMap.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_TERRACOTTA)
.put(AEColor.ORANGE, Blocks.ORANGE_TERRACOTTA).put(AEColor.MAGENTA, Blocks.MAGENTA_TERRACOTTA)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_TERRACOTTA).put(AEColor.YELLOW, Blocks.YELLOW_TERRACOTTA)
.put(AEColor.LIME, Blocks.LIME_TERRACOTTA).put(AEColor.PINK, Blocks.PINK_TERRACOTTA)
.put(AEColor.GRAY, Blocks.GRAY_TERRACOTTA).put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_TERRACOTTA)
.put(AEColor.CYAN, Blocks.CYAN_TERRACOTTA).put(AEColor.PURPLE, Blocks.PURPLE_TERRACOTTA)
.put(AEColor.BLUE, Blocks.BLUE_TERRACOTTA).put(AEColor.BROWN, Blocks.BROWN_TERRACOTTA)
.put(AEColor.GREEN, Blocks.GREEN_TERRACOTTA).put(AEColor.RED, Blocks.RED_TERRACOTTA)
.put(AEColor.BLACK, Blocks.BLACK_TERRACOTTA).build());
private static final BiMap<AEColor, Block> GLAZED_TERRACOTTA_BY_COLOR = EnumHashBiMap.create(ImmutableMap
.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_GLAZED_TERRACOTTA)
.put(AEColor.ORANGE, Blocks.ORANGE_GLAZED_TERRACOTTA).put(AEColor.MAGENTA, Blocks.MAGENTA_GLAZED_TERRACOTTA)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_GLAZED_TERRACOTTA)
.put(AEColor.YELLOW, Blocks.YELLOW_GLAZED_TERRACOTTA).put(AEColor.LIME, Blocks.LIME_GLAZED_TERRACOTTA)
.put(AEColor.PINK, Blocks.PINK_GLAZED_TERRACOTTA).put(AEColor.GRAY, Blocks.GRAY_GLAZED_TERRACOTTA)
.put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_GLAZED_TERRACOTTA)
.put(AEColor.CYAN, Blocks.CYAN_GLAZED_TERRACOTTA).put(AEColor.PURPLE, Blocks.PURPLE_GLAZED_TERRACOTTA)
.put(AEColor.BLUE, Blocks.BLUE_GLAZED_TERRACOTTA).put(AEColor.BROWN, Blocks.BROWN_GLAZED_TERRACOTTA)
.put(AEColor.GREEN, Blocks.GREEN_GLAZED_TERRACOTTA).put(AEColor.RED, Blocks.RED_GLAZED_TERRACOTTA)
.put(AEColor.BLACK, Blocks.BLACK_GLAZED_TERRACOTTA).build());
private static final BiMap<AEColor, Block> CONCRETE_BY_COLOR = EnumHashBiMap
.create(ImmutableMap.<AEColor, Block>builder().put(AEColor.WHITE, Blocks.WHITE_CONCRETE)
.put(AEColor.ORANGE, Blocks.ORANGE_CONCRETE).put(AEColor.MAGENTA, Blocks.MAGENTA_CONCRETE)
.put(AEColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_CONCRETE).put(AEColor.YELLOW, Blocks.YELLOW_CONCRETE)
.put(AEColor.LIME, Blocks.LIME_CONCRETE).put(AEColor.PINK, Blocks.PINK_CONCRETE)
.put(AEColor.GRAY, Blocks.GRAY_CONCRETE).put(AEColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_CONCRETE)
.put(AEColor.CYAN, Blocks.CYAN_CONCRETE).put(AEColor.PURPLE, Blocks.PURPLE_CONCRETE)
.put(AEColor.BLUE, Blocks.BLUE_CONCRETE).put(AEColor.BROWN, Blocks.BROWN_CONCRETE)
.put(AEColor.GREEN, Blocks.GREEN_CONCRETE).put(AEColor.RED, Blocks.RED_CONCRETE)
.put(AEColor.BLACK, Blocks.BLACK_CONCRETE).build());
private static final List<RecolorableBlockGroup> BLOCK_GROUPS = ImmutableList.of(
new RecolorableBlockGroup(Blocks.GLASS, STAINED_GLASS_BY_COLOR),
new RecolorableBlockGroup(Blocks.GLASS_PANE, STAINED_GLASS_PANE_BY_COLOR),
new RecolorableBlockGroup(Blocks.WHITE_WOOL, WOOL_BY_COLOR),
new RecolorableBlockGroup(Blocks.WHITE_BANNER, BANNER_BY_COLOR),
new RecolorableBlockGroup(Blocks.WHITE_WALL_BANNER, WALL_BANNER_BY_COLOR),
new RecolorableBlockGroup(Blocks.WHITE_CARPET, CARPET_BY_COLOR),
new RecolorableBlockGroup(Blocks.TERRACOTTA, TERRACOTTA_BY_COLOR),
new RecolorableBlockGroup(null, GLAZED_TERRACOTTA_BY_COLOR),
new RecolorableBlockGroup(null, CONCRETE_BY_COLOR));
public static Block recolor(Block block, AEColor newColor) {
Preconditions.checkNotNull(block);
for (RecolorableBlockGroup group : BLOCK_GROUPS) {
if (group.uncoloredVariant == block || group.coloredVariants.containsValue(block)) {
Block newBlock = group.coloredVariants.get(newColor);
if (newBlock == null) {
if (group.uncoloredVariant != null) {
newBlock = group.uncoloredVariant;
} else {
newBlock = block;
}
}
return newBlock;
}
}
return block;
}
private static class RecolorableBlockGroup {
final Block uncoloredVariant;
final BiMap<AEColor, Block> coloredVariants;
public RecolorableBlockGroup(Block uncoloredVariant, BiMap<AEColor, Block> coloredVariants) {
this.uncoloredVariant = uncoloredVariant;
this.coloredVariants = coloredVariants;
}
}
}
@@ -18,14 +18,11 @@
package appeng.items.tools.powered;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.apache.commons.lang3.text.WordUtils;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@@ -33,17 +30,21 @@ import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.item.SnowballItem;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.IProperty;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
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;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler;
@@ -81,42 +82,49 @@ import appeng.util.item.AEItemStack;
public class ToolColorApplicator extends AEBasePoweredItem
implements IStorageCell<IAEItemStack>, IItemGroup, IBlockTool, IMouseWheelItem {
private static final Map<Integer, AEColor> ORE_TO_COLOR = new HashMap<>();
private static final Map<ResourceLocation, AEColor> TAG_TO_COLOR = ImmutableMap.<ResourceLocation, AEColor>builder()
.put(new ResourceLocation("forge:dyes/black"), AEColor.BLACK)
.put(new ResourceLocation("forge:dyes/blue"), AEColor.BLUE)
.put(new ResourceLocation("forge:dyes/brown"), AEColor.BROWN)
.put(new ResourceLocation("forge:dyes/cyan"), AEColor.CYAN)
.put(new ResourceLocation("forge:dyes/gray"), AEColor.GRAY)
.put(new ResourceLocation("forge:dyes/green"), AEColor.GREEN)
.put(new ResourceLocation("forge:dyes/light_blue"), AEColor.LIGHT_BLUE)
.put(new ResourceLocation("forge:dyes/light_gray"), AEColor.LIGHT_GRAY)
.put(new ResourceLocation("forge:dyes/lime"), AEColor.LIME)
.put(new ResourceLocation("forge:dyes/magenta"), AEColor.MAGENTA)
.put(new ResourceLocation("forge:dyes/orange"), AEColor.ORANGE)
.put(new ResourceLocation("forge:dyes/pink"), AEColor.PINK)
.put(new ResourceLocation("forge:dyes/purple"), AEColor.PURPLE)
.put(new ResourceLocation("forge:dyes/red"), AEColor.RED)
.put(new ResourceLocation("forge:dyes/white"), AEColor.WHITE)
.put(new ResourceLocation("forge:dyes/yellow"), AEColor.YELLOW).build();
private static final String TAG_COLOR = "color";
static {
for (final AEColor color : AEColor.VALID_COLORS) {
final String dyeName = color.dye.getTranslationKey();
final String oreDictName = "dye" + WordUtils.capitalize(dyeName);
// FIXME final int oreDictId = OreDictionary.getOreID( oreDictName );
// FIXME ORE_TO_COLOR.put( oreDictId, color );
}
}
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
// 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
public ActionResultType onItemUse(PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX,
float hitY, float hitZ) {
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
}
public ActionResultType onItemUse(ItemUseContext context) {
World w = context.getWorld();
BlockPos pos = context.getPos();
ItemStack is = context.getItem();
Direction side = context.getFace();
PlayerEntity p = context.getPlayer(); // This can be null
if (p == null && w instanceof ServerWorld) {
p = Platform.getPlayer((ServerWorld) w);
}
@Override
public ActionResultType onItemUse(ItemStack is, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side,
float hitX, float hitY, float hitZ) {
final Block blk = w.getBlockState(pos).getBlock();
ItemStack paintBall = this.getColor(is);
@@ -134,7 +142,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
paintBall = ItemStack.EMPTY;
}
if (!Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
if (p != null && !Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
return ActionResultType.FAIL;
}
@@ -142,7 +150,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
if (!paintBall.isEmpty() && paintBall.getItem() instanceof SnowballItem) {
final TileEntity te = w.getTileEntity(pos);
// clean cables.
if (te instanceof IColorableTile) {
if (te instanceof IColorableTile && p != null) {
if (this.getAECurrentPower(is) > powerPerUse
&& ((IColorableTile) te).getColor() != AEColor.TRANSPARENT) {
if (((IColorableTile) te).recolourBlock(side, AEColor.TRANSPARENT, p)) {
@@ -168,7 +176,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
final AEColor color = this.getColorFromItem(paintBall);
if (color != null && this.getAECurrentPower(is) > powerPerUse) {
if (color != AEColor.TRANSPARENT && this.recolourBlock(blk, side, w, pos, side, color, p)) {
if (color != AEColor.TRANSPARENT && this.recolourBlock(blk, side, w, pos, color, p)) {
inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.MODULATE,
new BaseActionSource());
this.extractAEPower(is, powerPerUse, Actionable.MODULATE);
@@ -178,7 +186,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
}
if (p.isCrouching()) {
if (p != null && p.isCrouching()) {
this.cycleColors(is, paintBall, 1);
}
@@ -215,15 +223,12 @@ public class ToolColorApplicator extends AEBasePoweredItem
final ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem();
return ipb.getColor();
} else {
// FIXME final int[] id = OreDictionary.getOreIDs( paintBall );
// FIXME
// FIXME for( final int oreID : id )
// FIXME {
// FIXME if( ORE_TO_COLOR.containsKey( oreID ) )
// FIXME {
// FIXME return ORE_TO_COLOR.get( oreID );
// FIXME }
// FIXME }
for (Map.Entry<ResourceLocation, AEColor> entry : TAG_TO_COLOR.entrySet()) {
Tag<Item> tag = ItemTags.getCollection().get(entry.getKey());
if (tag != null && paintBall.getItem().isIn(tag)) {
return entry.getValue();
}
}
}
return null;
@@ -262,16 +267,21 @@ public class ToolColorApplicator extends AEBasePoweredItem
list.add(i);
}
Collections.sort(list, (a, b) -> Integer.compare(a.getItemDamage(), b.getItemDamage()));
if (list.size() <= 0) {
if (list.isEmpty()) {
return ItemStack.EMPTY;
}
// Sort by color
list.sort(Comparator.comparingInt(a -> {
AEColor color = getColorFromItem(a.getDefinition());
return color != null ? color.ordinal() : Integer.MAX_VALUE;
}));
IAEItemStack where = list.getFirst();
int cycles = 1 + list.size();
while (cycles > 0 && !where.equals(anchor)) {
AEColor anchorColor = getColorFromItem(anchor);
while (cycles > 0 && getColorFromItem(where.getDefinition()) != anchorColor) {
list.addLast(list.removeFirst());
cycles--;
where = list.getFirst();
@@ -308,67 +318,34 @@ public class ToolColorApplicator extends AEBasePoweredItem
}
private boolean recolourBlock(final Block blk, final Direction side, final World w, final BlockPos pos,
final Direction orientation, final AEColor newColor, final PlayerEntity p) {
final AEColor newColor, @Nullable final PlayerEntity p) {
final BlockState state = w.getBlockState(pos);
// FIXME if( blk instanceof BlockColored )
// FIXME {
// FIXME final DyeColor color = state.get( BlockColored.COLOR );
// FIXME
// FIXME if( newColor.dye == color )
// FIXME {
// FIXME return false;
// FIXME }
// FIXME
// FIXME return w.setBlockState( pos, state.with( BlockColored.COLOR, newColor.dye ) );
// FIXME }
Block recolored = BlockRecolorer.recolor(blk, newColor);
if (recolored != blk) {
BlockState newState = recolored.getDefaultState();
for (IProperty<?> prop : newState.getProperties()) {
newState = copyProp(state, newState, prop);
}
// if( blk == Blocks.GLASS )
// {
// return w.setBlockState( pos, Blocks.STAINED_GLASS.getDefaultState().with( BlockStainedGlass.COLOR, newColor.dye ) );
// }
//
// if( blk == Blocks.STAINED_GLASS )
// {
// final DyeColor color = state.get( BlockStainedGlass.COLOR );
//
// if( newColor.dye == color )
// {
// return false;
// }
//
// return w.setBlockState( pos, state.with( BlockStainedGlass.COLOR, newColor.dye ) );
// }
return w.setBlockState(pos, newState);
}
// if( blk == Blocks.GLASS_PANE )
// {
// return w.setBlockState( pos, Blocks.STAINED_GLASS_PANE.getDefaultState().with( BlockStainedGlassPane.COLOR, newColor.dye ) );
// }
//
// if( blk == Blocks.STAINED_GLASS_PANE )
// {
// final DyeColor color = state.get( BlockStainedGlassPane.COLOR );
//
// if( newColor.dye == color )
// {
// return false;
// }
//
// return w.setBlockState( pos, state.with( BlockStainedGlassPane.COLOR, newColor.dye ) );
// }
//
// if( blk == Blocks.HARDENED_CLAY )
// {
// return w.setBlockState( pos, Blocks.STAINED_HARDENED_CLAY.getDefaultState().with( BlockColored.COLOR, newColor.dye ) );
// }
if (blk instanceof BlockCableBus) {
if (blk instanceof BlockCableBus && p != null) {
return ((BlockCableBus) blk).recolorBlock(w, pos, side, newColor.dye, p);
}
return blk.recolorBlock(state, w, pos, side, newColor.dye);
}
private static <T extends Comparable<T>> BlockState copyProp(BlockState oldState, BlockState newState,
IProperty<T> prop) {
if (newState.has(prop)) {
return newState.with(prop, oldState.get(prop));
}
return newState;
}
public void cycleColors(final ItemStack is, final ItemStack paintBall, final int i) {
if (paintBall.isEmpty()) {
this.setColor(is, this.getColor(is));
@@ -407,22 +384,7 @@ public class ToolColorApplicator extends AEBasePoweredItem
@Override
public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) {
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 getColorFromItem(requestedAddition.getDefinition()) == null;
}
return true;
}
@@ -32,6 +32,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
@@ -44,6 +45,8 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.FakePlayer;
import appeng.api.config.Actionable;
import appeng.api.util.DimensionalCoord;
@@ -187,9 +190,11 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
return false;
}
// Overridden to allow use of the item on WATER and LAVA which are otherwise not
// considered for onItemUse
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity p, final Hand hand) {
final RayTraceResult target = this.rayTrace(w, p, RayTraceContext.FluidMode.ANY);
final RayTraceResult target = rayTrace(w, p, RayTraceContext.FluidMode.ANY);
if (target.getType() != RayTraceResult.Type.BLOCK) {
return new ActionResult<>(ActionResultType.FAIL, p.getHeldItem(hand));
@@ -198,7 +203,8 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
final BlockState state = w.getBlockState(pos);
if (state.getMaterial() == Material.LAVA || state.getMaterial() == Material.WATER) {
if (Platform.hasPermissions(new DimensionalCoord(w, pos), p)) {
this.onItemUse(p, w, pos, hand, Direction.UP, 0.0F, 0.0F, 0.0F);
ItemUseContext context = new ItemUseContext(p, hand, (BlockRayTraceResult) target);
this.onItemUse(context);
}
}
}
@@ -207,14 +213,19 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
}
@Override
public ActionResultType onItemUse(PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX,
float hitY, float hitZ) {
return this.onItemUse(p.getHeldItem(hand), p, w, pos, hand, side, hitX, hitY, hitZ);
}
public ActionResultType onItemUse(ItemUseContext context) {
World w = context.getWorld();
ItemStack item = context.getItem();
BlockPos pos = context.getPos();
Direction side = context.getFace();
PlayerEntity p = context.getPlayer();
if (p == null) {
if (w.isRemote) {
return ActionResultType.FAIL;
}
p = Platform.getPlayer((ServerWorld) w);
}
@Override
public ActionResultType onItemUse(ItemStack item, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side,
float hitX, float hitY, float hitZ) {
if (this.getAECurrentPower(item) > 1600) {
if (!p.canPlayerEdit(pos, side, item)) {
return ActionResultType.FAIL;