forked from jzitnik/twodcraft
feat: Implemented break on place
This commit is contained in:
parent
9aa08dd685
commit
0aa161361b
@ -10,6 +10,7 @@ import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
|
||||
import cz.jzitnik.game.mobs.EntitySpawnProvider;
|
||||
import cz.jzitnik.game.sprites.Breaking;
|
||||
import cz.jzitnik.game.sprites.Steve;
|
||||
import cz.jzitnik.game.annotations.BreaksByPlace;
|
||||
import cz.jzitnik.game.blocks.Chest;
|
||||
import cz.jzitnik.game.blocks.Furnace;
|
||||
import cz.jzitnik.game.ui.Window;
|
||||
@ -374,11 +375,12 @@ public class Game implements Serializable {
|
||||
x, y)) {
|
||||
screenRenderer.render(this);
|
||||
}
|
||||
;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blocks.stream().allMatch(block -> block.getBlockId().equals("air") || block.isFlowing())) {
|
||||
if (!blocks.stream().allMatch(block -> block.getBlockId().equals("air") || block.isFlowing()
|
||||
|| block.getClass().isAnnotationPresent(BreaksByPlace.class))) {
|
||||
RightClickHandlerProvider.handle(x, y, this, screenRenderer);
|
||||
screenRenderer.render(this);
|
||||
return;
|
||||
@ -392,7 +394,10 @@ public class Game implements Serializable {
|
||||
|
||||
CustomPlaceHandler placeHandler = gameStates.dependencies.placeHandler.get(item.getId());
|
||||
|
||||
var blocksRemove = blocks.stream().filter(block -> block.getClass().isAnnotationPresent(BreaksByPlace.class)).toList();
|
||||
|
||||
if (placeHandler.place(this, x, y)) {
|
||||
blocks.removeAll(blocksRemove);
|
||||
gameStates.dependencies.eventHandlerProvider.handlePlace(screenRenderer, this, x, y);
|
||||
screenRenderer.render(this);
|
||||
}
|
||||
@ -402,6 +407,7 @@ public class Game implements Serializable {
|
||||
if (window != Window.WORLD) {
|
||||
return;
|
||||
}
|
||||
|
||||
inventory.setItemInhHandIndex(slot);
|
||||
screenRenderer.render(this);
|
||||
}
|
||||
|
11
src/main/java/cz/jzitnik/game/annotations/BreaksByPlace.java
Normal file
11
src/main/java/cz/jzitnik/game/annotations/BreaksByPlace.java
Normal file
@ -0,0 +1,11 @@
|
||||
package cz.jzitnik.game.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface BreaksByPlace {
|
||||
}
|
@ -4,6 +4,7 @@ import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockDropPercentage;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.BreakableByWater;
|
||||
import cz.jzitnik.game.annotations.BreaksByPlace;
|
||||
import cz.jzitnik.game.annotations.BreaksFalling;
|
||||
import cz.jzitnik.game.annotations.CustomDrop;
|
||||
import cz.jzitnik.game.annotations.PlaceOnSolid;
|
||||
@ -12,6 +13,7 @@ import cz.jzitnik.game.entities.Block;
|
||||
@PlaceOnSolid
|
||||
@BreakableByWater
|
||||
@BreaksFalling
|
||||
@BreaksByPlace
|
||||
@CustomDrop(tool = "shears", drops = "grass_bush")
|
||||
@BlockDropPercentage(13)
|
||||
@BlockRegistry(value = "grass_bush", drops = "wheat_seeds")
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cz.jzitnik.game.generation;
|
||||
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.sprites.Steve;
|
||||
@ -33,10 +32,6 @@ public class Generation {
|
||||
// Spawn player at a valid starting point
|
||||
world[terrainHeight[256] - 1][256].add(steveBlock2);
|
||||
world[terrainHeight[256] - 2][256].add(steveBlock);
|
||||
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("furnace"));
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("coal"));
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("mutton"));
|
||||
}
|
||||
|
||||
private static void initializeWorld(List<Block>[][] world) {
|
||||
|
@ -22,7 +22,3 @@ public class ScreenMovingCalculationProvider {
|
||||
return new int[] { startX, endX, startY, endY };
|
||||
}
|
||||
}
|
||||
|
||||
class Something {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user