mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-26 05:08:34 +01:00
fixed the color changer
This commit is contained in:
parent
c2c88dec61
commit
e1d6a52112
5 changed files with 70 additions and 77 deletions
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "naturesaura:item/color_changer"
|
||||
}
|
||||
}
|
|
@ -11,14 +11,12 @@ import de.ellpeck.naturesaura.compat.Compat;
|
|||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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) {
|
||||
if (Compat.hasCompat("curios")) {
|
||||
Optional<ItemStack> stack = CuriosAPI.getCurioEquipped(predicate, player).map(ImmutableTriple::getRight);
|
||||
|
|
|
@ -3,21 +3,23 @@ package de.ellpeck.naturesaura.items;
|
|||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
||||
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
|
||||
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
|
||||
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.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, ICustomItemModel {
|
||||
|
||||
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) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
for (IProperty prop : state.getProperties()) {
|
||||
// TODO Fix this since it's now not state-based anymore
|
||||
if (prop.getValueClass() == DyeColor.class) {
|
||||
DyeColor color = (DyeColor) state.get(prop);
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
List<Block> blocks = ColoredBlockHelper.getBlocksContaining(block);
|
||||
if (blocks == null)
|
||||
return false;
|
||||
DyeColor color = DyeColor.byId(blocks.indexOf(block));
|
||||
if (firstColor == null || color == firstColor) {
|
||||
DyeColor stored = getStoredColor(stack);
|
||||
if (player.isShiftKeyDown()) {
|
||||
|
@ -63,7 +65,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F);
|
||||
}
|
||||
if (!world.isRemote) {
|
||||
world.setBlockState(pos, state.with(prop, stored));
|
||||
world.setBlockState(pos, blocks.get(stored.getId()).getDefaultState());
|
||||
|
||||
if (isFillMode(stack)) {
|
||||
for (Direction off : Direction.values()) {
|
||||
|
@ -76,8 +78,6 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package de.ellpeck.naturesaura.recipes;
|
||||
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
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.ItemEffectPowder;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FlowerBlock;
|
||||
|
@ -226,7 +226,7 @@ public final class ModRecipes {
|
|||
for (DyeColor color : DyeColor.values())
|
||||
new AnimalSpawnerRecipe(res("sheep_" + color.getName()), EntityType.SHEEP,
|
||||
500, 60, ing(ModItems.BIRTH_SPIRIT), ing(Items.MUTTON),
|
||||
ing(Helper.getWool(color))) {
|
||||
ing(ColoredBlockHelper.WOOL.get(color.getId()))) {
|
||||
@Override
|
||||
public Entity makeEntity(World world, double x, double y, double z) {
|
||||
SheepEntity sheep = (SheepEntity) super.makeEntity(world, x, y, z);
|
||||
|
|
Loading…
Reference in a new issue