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 3 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
4 changes: 4 additions & 0 deletions src/client/java/minicraft/item/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ public class Recipes {
craftRecipes.add(new Recipe("plank_2", "Wood_1"));
craftRecipes.add(new Recipe("Plank Wall_1", "plank_3"));
craftRecipes.add(new Recipe("Wood Door_1", "plank_5"));
craftRecipes.add(new Recipe("Wood Fence_1", "plank_3"));

workbenchRecipes.add(new Recipe("Workbench_1", "Wood_10"));
workbenchRecipes.add(new Recipe("Torch_2", "Wood_1", "coal_1"));
workbenchRecipes.add(new Recipe("plank_2", "Wood_1"));
workbenchRecipes.add(new Recipe("Plank Wall_1", "plank_3"));
workbenchRecipes.add(new Recipe("Wood Door_1", "plank_5"));
workbenchRecipes.add(new Recipe("Wood Fence_1", "plank_3"));
workbenchRecipes.add(new Recipe("Lantern_1", "Wood_8", "slime_4", "glass_3"));
workbenchRecipes.add(new Recipe("Stone Brick_1", "Stone_2"));
workbenchRecipes.add(new Recipe("Ornate Stone_1", "Stone_2"));
workbenchRecipes.add(new Recipe("Stone Wall_1", "Stone Brick_3"));
workbenchRecipes.add(new Recipe("Stone Door_1", "Stone Brick_5"));
workbenchRecipes.add(new Recipe("Stone Fence_1", "Stone Brick_3"));
workbenchRecipes.add(new Recipe("Obsidian Brick_1", "Raw Obsidian_2"));
workbenchRecipes.add(new Recipe("Ornate Obsidian_1", "Raw Obsidian_2"));
workbenchRecipes.add(new Recipe("Obsidian Wall_1", "Obsidian Brick_3"));
workbenchRecipes.add(new Recipe("Obsidian Door_1", "Obsidian Brick_5"));
workbenchRecipes.add(new Recipe("Obsidian Fence_1", "Obsidian Brick_3"));
workbenchRecipes.add(new Recipe("Oven_1", "Stone_15"));
workbenchRecipes.add(new Recipe("Furnace_1", "Stone_20"));
workbenchRecipes.add(new Recipe("Enchanter_1", "Wood_5", "String_2", "Lapis_10"));
Expand Down
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 @@ -33,16 +33,19 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new TileItem("Plank", new LinkedSprite(SpriteType.Item, "plank"), "Wood Planks", "hole", "water", "cloud"));
items.add(new TileItem("Plank Wall", new LinkedSprite(SpriteType.Item, "plank_wall"), "Wood Wall", "Wood Planks"));
items.add(new TileItem("Wood Door", new LinkedSprite(SpriteType.Item, "wood_door"), "Wood Door", "Wood Planks"));
items.add(new TileItem("Wood Fence", new LinkedSprite(SpriteType.Item, "wood_fence"), "Wood Fence", "grass"));
items.add(new TileItem("Stone", new LinkedSprite(SpriteType.Item, "stone"), "Stone", "hole", "water", "cloud", "lava"));
items.add(new TileItem("Stone Brick", new LinkedSprite(SpriteType.Item, "stone_brick"), "Stone Bricks", "hole", "water", "cloud", "lava"));
items.add(new TileItem("Ornate Stone", new LinkedSprite(SpriteType.Item, "stone_brick"), "Ornate Stone", "hole", "water", "cloud", "lava"));
items.add(new TileItem("Stone Wall", new LinkedSprite(SpriteType.Item, "stone_wall"), "Stone Wall", "Stone Bricks"));
items.add(new TileItem("Stone Door", new LinkedSprite(SpriteType.Item, "stone_wall"), "Stone Door", "Stone Bricks"));
items.add(new TileItem("Stone Fence", new LinkedSprite(SpriteType.Item, "stone_fence"), "Stone Fence", "Stone Bricks"));
items.add(new TileItem("Raw Obsidian", new LinkedSprite(SpriteType.Item, "obsidian"), "Raw Obsidian", "hole", "water", "cloud", "lava"));
items.add(new TileItem("Obsidian Brick", new LinkedSprite(SpriteType.Item, "obsidian_brick"), "Obsidian", "hole", "water", "cloud", "lava"));
items.add(new TileItem("Ornate Obsidian", new LinkedSprite(SpriteType.Item, "obsidian_brick"), "Ornate Obsidian","hole", "water", "cloud", "lava"));
items.add(new TileItem("Obsidian Wall", new LinkedSprite(SpriteType.Item, "obsidian_wall"), "Obsidian Wall", "Obsidian"));
items.add(new TileItem("Obsidian Door", new LinkedSprite(SpriteType.Item, "obsidian_door"), "Obsidian Door", "Obsidian"));
items.add(new TileItem("Obsidian Fence", new LinkedSprite(SpriteType.Item, "obsidian_fence"), "Obsidian Fence", "Obsidian"));

items.add(new TileItem("Wool", new LinkedSprite(SpriteType.Item, "wool"), "Wool", "hole", "water"));
items.add(new TileItem("Red Wool", new LinkedSprite(SpriteType.Item, "red_wool"), "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 @@ -72,6 +72,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.


// WARNING: don't use this tile for anything!
tiles.put((short)255, new ConnectTile());
Expand Down
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