forked from jzitnik/twodcraft
chore: Water placement
This commit is contained in:
parent
bb4e7423e3
commit
f5d2920a9a
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="RawUseOfParameterizedType" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
74
pom.xml
74
pom.xml
@ -9,11 +9,69 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
<maven.compiler.target>22</maven.compiler.target>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>cz.jzitnik.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>cz.jzitnik.Main</mainClass>
|
||||
<classpathScope>compile</classpathScope> <!-- This ensures the compiled classes are included -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@ -51,12 +109,24 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.18.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -13,6 +13,7 @@ import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLOutput;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@ -64,7 +65,7 @@ public class Main {
|
||||
|
||||
terminal.trackMouse(Terminal.MouseTracking.Off);
|
||||
terminal.close();
|
||||
} catch (IOException | InterruptedException _) {
|
||||
} catch (IOException | InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jline.terminal.Terminal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
12
src/main/java/cz/jzitnik/game/annotations/PickupHandler.java
Normal file
12
src/main/java/cz/jzitnik/game/annotations/PickupHandler.java
Normal file
@ -0,0 +1,12 @@
|
||||
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 PickupHandler {
|
||||
String value();
|
||||
}
|
@ -3,10 +3,15 @@ package cz.jzitnik.game.crafting.recipes;
|
||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
||||
|
||||
@CraftingRecipeRegistry(
|
||||
recipe = {
|
||||
/*recipe = {
|
||||
"iron_ingot", "_", "iron_ingot",
|
||||
"_", "iron_ingot", "_",
|
||||
"_", "_", "_"
|
||||
},*/
|
||||
recipe = {
|
||||
"dirt", "_", "_",
|
||||
"_", "_", "_",
|
||||
"_", "_", "_"
|
||||
},
|
||||
result = "bucket",
|
||||
amount = 1
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cz.jzitnik.game.entities;
|
||||
|
||||
import cz.jzitnik.game.handlers.pickup.PickupHandlerProvider;
|
||||
import cz.jzitnik.game.handlers.place.PlaceHandler;
|
||||
import cz.jzitnik.game.mobs.EntityHurtAnimation;
|
||||
import cz.jzitnik.game.mobs.EntityKill;
|
||||
@ -8,4 +9,5 @@ public class Dependencies {
|
||||
public PlaceHandler placeHandler = new PlaceHandler();
|
||||
public EntityHurtAnimation entityHurtAnimation = new EntityHurtAnimation();
|
||||
public EntityKill entityKill = new EntityKill();
|
||||
public PickupHandlerProvider pickupHandlerProvider = new PickupHandlerProvider();
|
||||
}
|
||||
|
@ -82,8 +82,6 @@ public class ItemBlockSupplier {
|
||||
Item dropItem = getItem(dropKey);
|
||||
if (dropKey.equals(block.getBlockId())) {
|
||||
dropItem.setBlock(Optional.of(block));
|
||||
} else {
|
||||
dropItem.setBlock(Optional.of(getBlock(dropKey)));
|
||||
}
|
||||
block.setDrops(List.of(dropItem));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.logic.services.water.WaterData;
|
||||
import cz.jzitnik.game.sprites.Water;
|
||||
|
||||
@BlockRegistry("water")
|
||||
@BlockRegistry(value = "water", drops = "water_item")
|
||||
public class WaterBlock extends Block {
|
||||
public WaterBlock() {
|
||||
super("water", SpriteLoader.SPRITES.WATER);
|
||||
|
@ -0,0 +1,7 @@
|
||||
package cz.jzitnik.game.handlers.pickup;
|
||||
|
||||
import cz.jzitnik.game.Game;
|
||||
|
||||
public interface CustomPickupHandler {
|
||||
boolean handle(Game game, int x, int y);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package cz.jzitnik.game.handlers.pickup;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import cz.jzitnik.game.annotations.PickupHandler;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
public class PickupHandlerProvider {
|
||||
public final HashMap<String, CustomPickupHandler> pickupList = new HashMap<>();
|
||||
|
||||
public CustomPickupHandler get(String itemId) {
|
||||
return pickupList.get(itemId);
|
||||
}
|
||||
|
||||
public PickupHandlerProvider() {
|
||||
registerHandlers();
|
||||
}
|
||||
|
||||
private void registerHandlers() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.handlers.pickup.handlers");
|
||||
Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(PickupHandler.class);
|
||||
|
||||
for (Class<?> clazz : handlerClasses) {
|
||||
if (CustomPickupHandler.class.isAssignableFrom(clazz)) {
|
||||
try {
|
||||
CustomPickupHandler handlerInstance = (CustomPickupHandler) clazz.getDeclaredConstructor().newInstance();
|
||||
PickupHandler annotation = clazz.getAnnotation(PickupHandler.class);
|
||||
String key = annotation.value();
|
||||
if (!key.contains(",")) {
|
||||
pickupList.put(key, handlerInstance);
|
||||
} else {
|
||||
String[] keys = key.split(",");
|
||||
for (String keyx : keys) {
|
||||
pickupList.put(keyx, handlerInstance);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.handlers.pickup.handlers;
|
||||
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.annotations.PickupHandler;
|
||||
import cz.jzitnik.game.handlers.pickup.CustomPickupHandler;
|
||||
|
||||
@PickupHandler("bucket,water_bucket")
|
||||
public class WaterPickupHandler implements CustomPickupHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(Game game, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cz.jzitnik.game.handlers.place.handlers;
|
||||
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.annotations.PlaceHandler;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
|
||||
|
||||
@PlaceHandler("bucket")
|
||||
public class BucketPlaceHandler implements CustomPlaceHandler {
|
||||
@Override
|
||||
public boolean place(Game game, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mine(Game game, int x, int y) {
|
||||
var world = game.getWorld();
|
||||
var blocks = world[y][x];
|
||||
var flowingBlocks = blocks.stream().filter(Block::isFlowing).toList();
|
||||
|
||||
if (flowingBlocks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var flowingBlock = flowingBlocks.getFirst();
|
||||
var items = flowingBlock.getDrops();
|
||||
for (Item item: items) {
|
||||
game.getInventory().addItem(item);
|
||||
}
|
||||
blocks.remove(flowingBlock);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cz.jzitnik.tui;
|
||||
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.ui.Window;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.jline.terminal.MouseEvent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user