fixed the color changer

This commit is contained in:
Ellpeck 2020-01-29 20:22:10 +01:00
parent c2c88dec61
commit e1d6a52112
5 changed files with 70 additions and 77 deletions

View file

@ -1,6 +0,0 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:item/color_changer"
}
}

View file

@ -11,14 +11,12 @@ import de.ellpeck.naturesaura.compat.Compat;
import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
@ -334,43 +332,6 @@ public final class Helper {
} }
} }
public static Block getWool(DyeColor color) {
switch (color) {
case ORANGE:
return Blocks.ORANGE_WOOL;
case MAGENTA:
return Blocks.MAGENTA_WOOL;
case LIGHT_BLUE:
return Blocks.LIGHT_BLUE_WOOL;
case YELLOW:
return Blocks.YELLOW_WOOL;
case LIME:
return Blocks.LIME_WOOL;
case PINK:
return Blocks.PINK_WOOL;
case GRAY:
return Blocks.GRAY_WOOL;
case LIGHT_GRAY:
return Blocks.LIGHT_GRAY_WOOL;
case CYAN:
return Blocks.CYAN_WOOL;
case PURPLE:
return Blocks.PURPLE_WOOL;
case BLUE:
return Blocks.BLUE_WOOL;
case BROWN:
return Blocks.BROWN_WOOL;
case GREEN:
return Blocks.GREEN_WOOL;
case RED:
return Blocks.RED_WOOL;
case BLACK:
return Blocks.BLACK_WOOL;
default:
return Blocks.WHITE_WOOL;
}
}
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) { public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) {
if (Compat.hasCompat("curios")) { if (Compat.hasCompat("curios")) {
Optional<ItemStack> stack = CuriosAPI.getCurioEquipped(predicate, player).map(ImmutableTriple::getRight); Optional<ItemStack> stack = CuriosAPI.getCurioEquipped(predicate, player).map(ImmutableTriple::getRight);

View file

@ -3,21 +3,23 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.BlockState; import net.minecraft.block.Block;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.DyeColor; import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.state.IProperty;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.List;
public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, ICustomItemModel { public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, ICustomItemModel {
public ItemColorChanger() { public ItemColorChanger() {
@ -40,11 +42,11 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
} }
private static boolean changeOrCopyColor(PlayerEntity player, ItemStack stack, World world, BlockPos pos, DyeColor firstColor) { private static boolean changeOrCopyColor(PlayerEntity player, ItemStack stack, World world, BlockPos pos, DyeColor firstColor) {
BlockState state = world.getBlockState(pos); Block block = world.getBlockState(pos).getBlock();
for (IProperty prop : state.getProperties()) { List<Block> blocks = ColoredBlockHelper.getBlocksContaining(block);
// TODO Fix this since it's now not state-based anymore if (blocks == null)
if (prop.getValueClass() == DyeColor.class) { return false;
DyeColor color = (DyeColor) state.get(prop); DyeColor color = DyeColor.byId(blocks.indexOf(block));
if (firstColor == null || color == firstColor) { if (firstColor == null || color == firstColor) {
DyeColor stored = getStoredColor(stack); DyeColor stored = getStoredColor(stack);
if (player.isShiftKeyDown()) { if (player.isShiftKeyDown()) {
@ -63,7 +65,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F); SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F);
} }
if (!world.isRemote) { if (!world.isRemote) {
world.setBlockState(pos, state.with(prop, stored)); world.setBlockState(pos, blocks.get(stored.getId()).getDefaultState());
if (isFillMode(stack)) { if (isFillMode(stack)) {
for (Direction off : Direction.values()) { for (Direction off : Direction.values()) {
@ -76,8 +78,6 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
} }
} }
} }
}
}
return false; return false;
} }

View file

@ -0,0 +1,38 @@
package de.ellpeck.naturesaura.misc;
import net.minecraft.block.Block;
import net.minecraft.item.DyeColor;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public final class ColoredBlockHelper {
public static final List<Block> WOOL = collectBlocks("wool");
public static final List<Block> TERRACOTTA = collectBlocks("terracotta");
public static final List<Block> CONCRETE_POWDER = collectBlocks("concrete_powder");
public static final List<Block> CONCRETE = collectBlocks("concrete");
public static final List<Block> GLASS = collectBlocks("stained_glass");
public static final List<Block> GLASS_PANE = collectBlocks("glass_pane");
public static final List<Block> CARPET = collectBlocks("carpet");
public static final List<List<Block>> LISTS = Arrays.asList(WOOL, TERRACOTTA, CONCRETE_POWDER, CONCRETE, GLASS, GLASS_PANE, CARPET);
private static List<Block> collectBlocks(String name) {
List<Block> blocks = new ArrayList<>();
for (DyeColor color : DyeColor.values())
blocks.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(color.getName() + '_' + name)));
return Collections.unmodifiableList(blocks);
}
public static List<Block> getBlocksContaining(Block block) {
for (List<Block> list : LISTS) {
if (list.contains(block))
return list;
}
return null;
}
}

View file

@ -1,6 +1,5 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.recipes.*; import de.ellpeck.naturesaura.api.recipes.*;
@ -14,6 +13,7 @@ import de.ellpeck.naturesaura.chunk.effect.PlantBoostEffect;
import de.ellpeck.naturesaura.items.ItemAuraBottle; import de.ellpeck.naturesaura.items.ItemAuraBottle;
import de.ellpeck.naturesaura.items.ItemEffectPowder; import de.ellpeck.naturesaura.items.ItemEffectPowder;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.FlowerBlock; import net.minecraft.block.FlowerBlock;
@ -226,7 +226,7 @@ public final class ModRecipes {
for (DyeColor color : DyeColor.values()) for (DyeColor color : DyeColor.values())
new AnimalSpawnerRecipe(res("sheep_" + color.getName()), EntityType.SHEEP, new AnimalSpawnerRecipe(res("sheep_" + color.getName()), EntityType.SHEEP,
500, 60, ing(ModItems.BIRTH_SPIRIT), ing(Items.MUTTON), 500, 60, ing(ModItems.BIRTH_SPIRIT), ing(Items.MUTTON),
ing(Helper.getWool(color))) { ing(ColoredBlockHelper.WOOL.get(color.getId()))) {
@Override @Override
public Entity makeEntity(World world, double x, double y, double z) { public Entity makeEntity(World world, double x, double y, double z) {
SheepEntity sheep = (SheepEntity) super.makeEntity(world, x, y, z); SheepEntity sheep = (SheepEntity) super.makeEntity(world, x, y, z);