Skip to content

Commit

Permalink
Update color system and sheep coloring (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Litorom authored Aug 29, 2024
2 parents 4efa734 + 8c0a77f commit 5102159
Show file tree
Hide file tree
Showing 151 changed files with 5,415 additions and 2,091 deletions.
27 changes: 25 additions & 2 deletions src/client/java/minicraft/entity/furniture/Bed.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,45 @@
import minicraft.core.Updater;
import minicraft.core.io.Localization;
import minicraft.entity.mob.Player;
import minicraft.gfx.SpriteAnimation;
import minicraft.gfx.SpriteLinker.LinkedSprite;
import minicraft.gfx.SpriteLinker.SpriteType;
import minicraft.item.DyeItem;
import minicraft.level.Level;
import minicraft.util.MyUtils;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;

public class Bed extends Furniture {

private static final HashMap<DyeItem.DyeColor, LinkedSprite> sprites = new HashMap<>();
private static final HashMap<DyeItem.DyeColor, LinkedSprite> itemSprites = new HashMap<>();

@Override
public @NotNull Furniture copy() {
return new Bed(color);
}

static {
for (DyeItem.DyeColor color : DyeItem.DyeColor.values()) {
sprites.put(color, new LinkedSprite(SpriteType.Entity, color.toString().toLowerCase() + "_bed"));
itemSprites.put(color, new LinkedSprite(SpriteType.Item, color.toString().toLowerCase() + "_bed"));
}
}

private static int playersAwake = 1;
private static final HashMap<Player, Bed> sleepingPlayers = new HashMap<>();

public final DyeItem.DyeColor color;

/**
* Creates a new furniture with the name Bed and the bed sprite and color.
*/
public Bed() {
super("Bed", new LinkedSprite(SpriteType.Entity, "bed"), new LinkedSprite(SpriteType.Item, "bed"), 3, 2);
public Bed() { this(DyeItem.DyeColor.WHITE); }
public Bed(DyeItem.DyeColor color) {
super(MyUtils.capitalizeFully(color.toString().replace('_', ' ')) + " Bed", sprites.get(color), itemSprites.get(color), 3, 2);
this.color = color;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/client/java/minicraft/entity/furniture/Crafter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum Type {
Furnace(new LinkedSprite(SpriteType.Entity, "furnace"), new LinkedSprite(SpriteType.Item, "furnace"), 3, 2, Recipes.furnaceRecipes),
Anvil(new LinkedSprite(SpriteType.Entity, "anvil"), new LinkedSprite(SpriteType.Item, "anvil"), 3, 2, Recipes.anvilRecipes),
Enchanter(new LinkedSprite(SpriteType.Entity, "enchanter"), new LinkedSprite(SpriteType.Item, "enchanter"), 7, 2, Recipes.enchantRecipes),
Loom(new LinkedSprite(SpriteType.Entity, "loom"), new LinkedSprite(SpriteType.Item, "loom"), 7, 2, Recipes.loomRecipes);
Loom(new LinkedSprite(SpriteType.Entity, "loom"), new LinkedSprite(SpriteType.Item, "loom"), 7, 2, Recipes.loomRecipes),
DyeVat(new LinkedSprite(SpriteType.Entity, "dyevat"), new LinkedSprite(SpriteType.Item, "dyevat"), 0, 0, Recipes.dyeVatRecipes);

public ArrayList<Recipe> recipes;
protected LinkedSprite sprite;
Expand All @@ -45,12 +46,12 @@ public enum Type {
* @param type What type of crafter this is.
*/
public Crafter(Crafter.Type type) {
super(type.name(), type.sprite, type.itemSprite, type.xr, type.yr);
super((type.name().equalsIgnoreCase("DyeVat") ? "Dye Vat" : type.name()), type.sprite, type.itemSprite, type.xr, type.yr);
this.type = type;
}

public boolean use(Player player) {
Game.setDisplay(new CraftingDisplay(type.recipes, type.name(), player));
Game.setDisplay(new CraftingDisplay(type.recipes, (type.name().equalsIgnoreCase("DyeVat") ? "Dye Vat" : type.name()), player));
return true;
}

Expand All @@ -61,6 +62,6 @@ public boolean use(Player player) {

@Override
public String toString() {
return type.name() + getDataPrints();
return (type.name().equalsIgnoreCase("DyeVat") ? "Dye Vat" : type.name()) + getDataPrints();
}
}
2 changes: 1 addition & 1 deletion src/client/java/minicraft/entity/mob/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static LinkedSprite[][] compileMobSpriteAnimations(int sheetX, int sheetY
private boolean isWooling() { // supposed to walk at half speed on wool
if (level == null) return false;
Tile tile = level.getTile(x >> 4, y >> 4);
return tile == Tiles.get("wool");
return tile == Tiles.get("white wool");
}

/**
Expand Down
50 changes: 39 additions & 11 deletions src/client/java/minicraft/entity/mob/Sheep.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package minicraft.entity.mob;

import minicraft.item.DyeItem;
import org.jetbrains.annotations.Nullable;

import minicraft.core.io.Settings;
import minicraft.entity.Direction;
import minicraft.gfx.Screen;
Expand All @@ -11,27 +14,50 @@
import minicraft.level.tile.GrassTile;
import minicraft.level.tile.Tile;
import minicraft.level.tile.Tiles;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;

public class Sheep extends PassiveMob {
private static final LinkedSprite[][] sprites = Mob.compileMobSpriteAnimations(0, 0, "sheep");
private static final LinkedSprite[][] cutSprites = Mob.compileMobSpriteAnimations(0, 2, "sheep");
private static final HashMap<DyeItem.DyeColor, LinkedSprite[][]> sprites = new HashMap<>();
private static final HashMap<DyeItem.DyeColor, LinkedSprite[][]> cutSprites = new HashMap<>();

static {
for (DyeItem.DyeColor color : DyeItem.DyeColor.values()) {
LinkedSprite[][] mobSprites = Mob.compileMobSpriteAnimations(0, 0, "sheep");
for (LinkedSprite[] mobSprite : mobSprites) {
for (LinkedSprite linkedSprite : mobSprite) {
linkedSprite.setColor(color.color);
}
}
sprites.put(color, mobSprites);
mobSprites = Mob.compileMobSpriteAnimations(0, 2, "sheep");
for (LinkedSprite[] mobSprite : mobSprites) {
for (LinkedSprite linkedSprite : mobSprite) {
linkedSprite.setColor(color.color);
}
}
cutSprites.put(color, mobSprites);
}
}

public boolean cut = false;
public DyeItem.DyeColor color;

/**
* Creates a sheep entity.
*/
public Sheep() {
super(sprites);
public Sheep() { this(DyeItem.DyeColor.WHITE); }
public Sheep(DyeItem.DyeColor color) {
super(null);
this.color = color;
}

@Override
public void render(Screen screen) {
int xo = x - 8;
int yo = y - 11;

LinkedSprite[][] curAnim = cut ? cutSprites : sprites;
LinkedSprite[][] curAnim = cut ? cutSprites.get(color) : sprites.get(color);

LinkedSprite curSprite = curAnim[dir.getDir()][(walkDist >> 3) % curAnim[dir.getDir()].length];
if (hurtTime > 0) {
Expand All @@ -52,15 +78,17 @@ public void tick() {
}

public boolean interact(Player player, @Nullable Item item, Direction attackDir) {
if (cut) return false;

if (item instanceof ToolItem) {
if (((ToolItem) item).type == ToolType.Shears) {
if (!cut && ((ToolItem) item).type == ToolType.Shears) {
cut = true;
dropItem(1, 3, Items.get("Wool"));
dropItem(1, 3, Items.get(color.toString().replace('_', ' ') + " Wool"));
((ToolItem) item).payDurability();
return true;
}
} else if (item instanceof DyeItem) {
color = ((DyeItem) item).color;
((DyeItem) item).count--;
return true;
}
return false;
}
Expand All @@ -80,7 +108,7 @@ public void die() {
max = 2;
}

if (!cut) dropItem(min, max, Items.get("wool"));
if (!cut) dropItem(min, max, Items.get(color.toString().replace('_', ' ') + " Wool"));
dropItem(min, max, Items.get("Raw Beef"));

super.die();
Expand Down
2 changes: 1 addition & 1 deletion src/client/java/minicraft/item/ClothingItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new ClothingItem("Orange Clothes", new LinkedSprite(SpriteType.Item, "orange_clothes"), Color.get(1, 255, 102, 0)));
items.add(new ClothingItem("Purple Clothes", new LinkedSprite(SpriteType.Item, "purple_clothes"), Color.get(1, 102, 0, 153)));
items.add(new ClothingItem("Cyan Clothes", new LinkedSprite(SpriteType.Item, "cyan_clothes"), Color.get(1, 0, 102, 153)));
items.add(new ClothingItem("Reg Clothes", new LinkedSprite(SpriteType.Item, "reg_clothes"), Color.get(1, 51, 51, 0)));
items.add(new ClothingItem("Reg Clothes", new LinkedSprite(SpriteType.Item, "reg_clothes"), Color.get(1, 51, 51, 0))); // Dark Green

return items;
}
Expand Down
58 changes: 58 additions & 0 deletions src/client/java/minicraft/item/DyeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package minicraft.item;

import minicraft.gfx.SpriteLinker;
import minicraft.util.MyUtils;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class DyeItem extends StackableItem {

protected static ArrayList<Item> getAllInstances() {
ArrayList<Item> items = new ArrayList<>();

for (DyeColor color : DyeColor.values()) {
items.add(new DyeItem(MyUtils.capitalizeFully(color.toString().replace('_', ' ')) + " Dye", new SpriteLinker.LinkedSprite(
SpriteLinker.SpriteType.Item, color.toString().toLowerCase() + "_dye"), color));
}

return items;
}

public final DyeColor color;

protected DyeItem(String name, SpriteLinker.LinkedSprite sprite, DyeColor color) {
super(name, sprite);
this.color = color;
}

public enum DyeColor {
BLACK(0x1_1D1D21),
RED(0x1_B02E26),
GREEN(0x1_5E7C16),
BROWN(0x1_835432),
BLUE(0x1_3C44AA),
PURPLE(0x1_8932B8),
CYAN(0x1_169C9C),
LIGHT_GRAY(0x1_9D9D97),
GRAY(0x1_474F52),
PINK(0x1_F38BAA),
LIME(0x1_80C71F),
YELLOW(0x1_FED83D),
LIGHT_BLUE(0x1_3AB3DA),
MAGENTA(0x1_C74EBD),
ORANGE(0x1_F9801D),
WHITE(0x1_F9FFFE);

public final int color;

DyeColor(int color) {
this.color = color;
}
}

@Override
public @NotNull DyeItem copy() {
return new DyeItem(getName(), sprite, color);
}
}
7 changes: 6 additions & 1 deletion src/client/java/minicraft/item/FurnitureItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ protected static ArrayList<Item> getAllInstances() {
for (Crafter.Type type : Crafter.Type.values()) {
items.add(new FurnitureItem(new Crafter(type)));
}

// Add the various lanterns
for (Lantern.Type type : Lantern.Type.values()) {
items.add(new FurnitureItem(new Lantern(type)));
}

// Add the various colors of bed
for (DyeItem.DyeColor color : DyeItem.DyeColor.values()) {
items.add(new FurnitureItem(new Bed(color)));
}

items.add(new FurnitureItem(new Tnt()));
items.add(new FurnitureItem(new Bed()));
items.add(new FurnitureItem(new Composter()));

return items;
Expand Down
2 changes: 2 additions & 0 deletions src/client/java/minicraft/item/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private static void addAll(ArrayList<Item> items) {
addAll(SummonItem.getAllInstances());
addAll(HeartItem.getAllInstances());
addAll(WateringCanItem.getAllInstances());
addAll(DyeItem.getAllInstances());
addAll(WoolItem.getAllInstances());
}

public static ArrayList<Item> getAll() {
Expand Down
7 changes: 7 additions & 0 deletions src/client/java/minicraft/item/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import minicraft.entity.mob.Player;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -114,4 +115,10 @@ public int hashCode() {
result = 31 * result + amount;
return result;
}

@Override
public String toString() {
return product + ":" + amount +
"[" + String.join(";", costs.entrySet().stream().<CharSequence>map(e -> e.getKey() + ":" + e.getValue())::iterator) + "]";
}
}
Loading

0 comments on commit 5102159

Please sign in to comment.