-
Notifications
You must be signed in to change notification settings - Fork 97
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
Added fences #572
Changes from all commits
0a98da3
0445dd0
783fd84
acab5ec
9d36424
b7d02b9
d9c793d
b57791e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using there ids two times is absolutely catastrophic! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,32 @@ | |
} | ||
} | ||
}, | ||
"minicraft.advancements.recipes.wood_fence": { | ||
"criteria": { | ||
"has_plank": { | ||
"trigger": "inventory_changed", | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": [ | ||
"plank" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_plank" | ||
] | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": { | ||
|
@@ -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": { | ||
|
@@ -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": { | ||
|
There was a problem hiding this comment.
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?