Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fences #572

Merged
merged 8 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 144 additions & 140 deletions src/client/java/minicraft/item/Recipes.java

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/client/java/minicraft/item/TileItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new TileItem("Plank", new LinkedSprite(SpriteType.Item, "plank"), new TileModel("Wood Planks"), "hole", "water", "cloud"));
items.add(new TileItem("Plank Wall", new LinkedSprite(SpriteType.Item, "plank_wall"), new TileModel("Wood Wall"), "Wood Planks"));
items.add(new TileItem("Wood Door", new LinkedSprite(SpriteType.Item, "wood_door"), new TileModel("Wood Door"), "Wood Planks"));
items.add(new TileItem("Wood Fence", new LinkedSprite(SpriteType.Item, "wood_fence"), new TileModel("Wood Fence"), "grass"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about planks, sand, etc?

items.add(new TileItem("Stone", new LinkedSprite(SpriteType.Item, "stone"), new TileModel("Stone"), "hole", "water", "cloud", "lava"));
items.add(new TileItem("Stone Brick", new LinkedSprite(SpriteType.Item, "stone_brick"), new TileModel("Stone Bricks"), "hole", "water", "cloud", "lava"));
items.add(new TileItem("Ornate Stone", new LinkedSprite(SpriteType.Item, "stone_brick"), new TileModel("Ornate Stone"), "hole", "water", "cloud", "lava"));
items.add(new TileItem("Stone Wall", new LinkedSprite(SpriteType.Item, "stone_wall"), new TileModel("Stone Wall"), "Stone Bricks"));
items.add(new TileItem("Stone Door", new LinkedSprite(SpriteType.Item, "stone_wall"), new TileModel("Stone Door"), "Stone Bricks"));
items.add(new TileItem("Stone Fence", new LinkedSprite(SpriteType.Item, "stone_fence"), new TileModel("Stone Fence"), "Stone Bricks"));
items.add(new TileItem("Raw Obsidian", new LinkedSprite(SpriteType.Item, "obsidian"), new TileModel("Raw Obsidian"), "hole", "water", "cloud", "lava"));
items.add(new TileItem("Obsidian Brick", new LinkedSprite(SpriteType.Item, "obsidian_brick"), new TileModel("Obsidian"), "hole", "water", "cloud", "lava"));
items.add(new TileItem("Ornate Obsidian", new LinkedSprite(SpriteType.Item, "obsidian_brick"), new TileModel("Ornate Obsidian"),"hole", "water", "cloud", "lava"));
items.add(new TileItem("Obsidian Wall", new LinkedSprite(SpriteType.Item, "obsidian_wall"), new TileModel("Obsidian Wall"), "Obsidian"));
items.add(new TileItem("Obsidian Door", new LinkedSprite(SpriteType.Item, "obsidian_door"), new TileModel("Obsidian Door"), "Obsidian"));
items.add(new TileItem("Obsidian Fence", new LinkedSprite(SpriteType.Item, "obsidian_fence"), new TileModel("Obsidian Fence"), "Obsidian"));

items.add(new TileItem("Wool", new LinkedSprite(SpriteType.Item, "wool"), new TileModel("Wool"), "hole", "water"));
items.add(new TileItem("Red Wool", new LinkedSprite(SpriteType.Item, "red_wool"), new TileModel("Red Wool"), "hole", "water"));
Expand Down
178 changes: 178 additions & 0 deletions src/client/java/minicraft/level/tile/FenceTile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package minicraft.level.tile;

import minicraft.core.Game;
import minicraft.core.io.Sound;
import minicraft.entity.Direction;
import minicraft.entity.Entity;
import minicraft.entity.mob.Mob;
import minicraft.entity.mob.Player;
import minicraft.entity.particle.SmashParticle;
import minicraft.entity.particle.TextParticle;
import minicraft.gfx.Color;
import minicraft.gfx.Screen;
import minicraft.gfx.Sprite;
import minicraft.gfx.SpriteAnimation;
import minicraft.gfx.SpriteLinker;
import minicraft.gfx.SpriteLinker.LinkedSprite;
import minicraft.gfx.SpriteLinker.SpriteType;
import minicraft.item.Item;
import minicraft.item.Items;
import minicraft.item.ToolItem;
import minicraft.level.Level;
import minicraft.util.AdvancementElement;
import minicraft.util.Logging;

public class FenceTile extends Tile {

private static SpriteAnimation wood = new SpriteAnimation(SpriteType.Tile, "wood_fence");
private static SpriteAnimation stone = new SpriteAnimation(SpriteType.Tile, "stone_fence");
private static SpriteAnimation obsidian = new SpriteAnimation(SpriteType.Tile, "obsidian_fence");

protected Material type;

protected SpriteAnimation top, bottom, left, right;

public boolean connectUp = false, connectDown = false, connectLeft = false, connectRight = false;

protected FenceTile(Material type) { this(type, null); }
protected FenceTile(Material type, String name) {
super(type.name() + " " + (name == null ? "Fence" : name), null);
this.type = type;
switch (type)
{
case Wood:
sprite = wood;
connectsToGrass = true;
break;
case Stone:
sprite = stone;
break;
case Obsidian:
sprite = obsidian;
break;
}
top = new SpriteAnimation(SpriteType.Tile, type.name().toLowerCase() + "_fence_top");
bottom = new SpriteAnimation(SpriteType.Tile, type.name().toLowerCase() + "_fence_bottom");
left = new SpriteAnimation(SpriteType.Tile, type.name().toLowerCase() + "_fence_left");
right = new SpriteAnimation(SpriteType.Tile, type.name().toLowerCase() + "_fence_right");
}

public void updateConnections(Level level, int x, int y)
{
connectUp = level.getTile(x, y - 1).name.equals(name);
connectDown = level.getTile(x, y + 1).name.equals(name);
connectLeft = level.getTile(x - 1, y).name.equals(name);
connectRight = level.getTile(x + 1, y).name.equals(name);
}

public boolean mayPass(Level level, int x, int y, Entity e) {
return false;
}

public void render(Screen screen, Level level, int x, int y)
{
switch (type)
{
case Wood: Tiles.get("Grass").render(screen, level, x, y); break;
case Stone: Tiles.get("Stone Bricks").render(screen, level, x, y); break;
case Obsidian: Tiles.get("Obsidian").render(screen, level, x, y); break;
}

sprite.render(screen, level, x, y);

updateConnections(level, x, y);

// up
if (connectUp) {
top.render(screen, level, x, y);
}
// bottom
if (connectDown) {
bottom.render(screen, level, x, y);
}
// left
if (connectLeft) {
left.render(screen, level, x, y);
}
// right
if (connectRight) {
right.render(screen, level, x, y);
}
}

@Override
public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) {
hurt(level, x, y, dmg);
return true;
}

@Override
public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) {
if(Game.isMode("minicraft.settings.mode.creative"))
return false; // Go directly to hurt method
if (item instanceof ToolItem) {
ToolItem tool = (ToolItem) item;
if (tool.type == type.getRequiredTool()) {
if (player.payStamina(4 - tool.level) && tool.payDurability()) {
int data = level.getData(xt, yt);
hurt(level, xt, yt, tool.getDamage());
AdvancementElement.AdvancementTrigger.ItemUsedOnTileTrigger.INSTANCE.trigger(
new AdvancementElement.AdvancementTrigger.ItemUsedOnTileTrigger.ItemUsedOnTileTriggerConditionHandler.ItemUsedOnTileTriggerConditions(
item, this, data, xt, yt, level.depth));
return true;
}
}
}
return false;
}

public void hurt(Level level, int x, int y, int dmg) {
int damage = level.getData(x, y) + dmg;
int fenceHealth = 5;
if (Game.isMode("minicraft.settings.mode.creative")) dmg = damage = fenceHealth;

level.add(new SmashParticle(x * 16, y * 16));
Sound.play("monsterhurt");

level.add(new TextParticle("" + dmg, x * 16 + 8, y * 16 + 8, Color.RED));

if (damage >= fenceHealth) {
String itemName = "", tilename = "";
switch (type) { // Get what tile to set and what item to drop
case Wood: {
itemName = "Wood Fence";
tilename = "Grass";
break;
}
case Stone: {
itemName = "Stone Fence";
tilename = "Stone Bricks";
break;
}
case Obsidian: {
itemName = "Obsidian Fence";
tilename = "Obsidian";
break;
}
}

level.dropItem(x * 16 + 8, y * 16 + 8, 1, 1, Items.get(itemName));
level.setTile(x, y, Tiles.get(tilename));
} else {
level.setData(x, y, damage);
}
}

public boolean tick(Level level, int xt, int yt) {
int damage = level.getData(xt, yt);
if (damage > 0) {
level.setData(xt, yt, damage - 1);
return true;
}
return false;
}

public String getName(int data) {
return Material.values[data].name() + " Fence";
}
}
3 changes: 3 additions & 0 deletions src/client/java/minicraft/level/tile/Tiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static void initTileList() {
tiles.put((short)47, new BossWallTile());
tiles.put((short)48, new BossFloorTile());
tiles.put((short)49, new BossDoorTile());
tiles.put((short)50, new FenceTile(Tile.Material.Wood));
tiles.put((short)51, new FenceTile(Tile.Material.Stone));
tiles.put((short)52, new FenceTile(Tile.Material.Obsidian));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using there ids two times is absolutely catastrophic!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are aware that this is because that it was made using another outdated version of the code therefore it’s technically correct at that time. However now it has to be adjusted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of a merge is to adjust the written code to reflect changes upstream. It wouldn't be hard to fix.

tiles.put((short)50, new TomatoTile("Tomato"));
tiles.put((short)51, new CarrotTile("Carrot"));
tiles.put((short)52, new HeavenlyBerriesTile("Heavenly Berries"));
Expand Down
5 changes: 4 additions & 1 deletion src/client/resources/assets/localization/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,8 @@
"Infinite Fall": "Infinite Fall",
"Cloud Cactus": "Cloud Cactus",
"Raw Obsidian": "Raw Obsidian",
"Totem of Air": "Totem of Air"
"Totem of Air": "Totem of Air",
"Wood Fence": "Wood Fence",
"Stone Fence": "Stone Fence",
"Obsidian Fence": "Obsidian Fence"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions src/client/resources/resources/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,32 @@
}
}
},
"minicraft.advancements.recipes.wood_fence": {
"criteria": {
"has_plank": {
"trigger": "inventory_changed",
"conditions": {
"items": [
{
"items": [
"plank"
]
}
]
}
}
},
"requirements": [
[
"has_plank"
]
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why this is here. I assume this will break the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't break the code as it follows the format

"rewards": {
"recipes": {
"Wood Fence_1": ["plank_3"]
}
}
},
"minicraft.advancements.recipes.lantern": {
"criteria": {
"has_wood": {
Expand Down Expand Up @@ -298,6 +324,32 @@
}
}
},
"minicraft.advancements.recipes.stone_fence": {
"criteria": {
"has_stone_brick": {
"trigger": "inventory_changed",
"conditions": {
"items": [
{
"items": [
"stone brick"
]
}
]
}
}
},
"requirements": [
[
"has_stone_brick"
]
],
"rewards": {
"recipes": {
"Stone Fence_1": ["Stone Brick_3"]
}
}
},
"minicraft.advancements.recipes.obsidian_brick": {
"criteria": {
"has_raw_obsidian": {
Expand Down Expand Up @@ -402,6 +454,32 @@
}
}
},
"minicraft.advancements.recipes.obsidian_fence": {
"criteria": {
"has_obsidian_brick": {
"trigger": "inventory_changed",
"conditions": {
"items": [
{
"items": [
"obsidian brick"
]
}
]
}
}
},
"requirements": [
[
"has_obsidian_brick"
]
],
"rewards": {
"recipes": {
"Obsidian Fence_1": ["Obsidian Brick_3"]
}
}
},
"minicraft.advancements.recipes.oven": {
"criteria": {
"has_stone": {
Expand Down