This repository has been archived by the owner on Jul 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbdcf30
commit 0a18852
Showing
11 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/dev/tonimatas/mossy/blocks/AnvilBlockHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.tonimatas.mossy.blocks; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.instance.block.BlockHandler; | ||
import net.minestom.server.inventory.Inventory; | ||
import net.minestom.server.inventory.InventoryType; | ||
import net.minestom.server.inventory.type.AnvilInventory; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class AnvilBlockHandler implements BlockHandler { | ||
@Override | ||
public boolean onInteract(@NotNull BlockHandler.Interaction interaction) { | ||
interaction.getPlayer().openInventory(new Inventory(InventoryType.ANVIL, Component.translatable("container.repair"))); | ||
|
||
// TODO: Add damage phases | ||
return true; | ||
} | ||
|
||
@Override | ||
public @NotNull NamespaceID getNamespaceId() { | ||
return Block.ANVIL.namespace(); | ||
} | ||
} |
11 changes: 9 additions & 2 deletions
11
src/main/java/dev/tonimatas/mossy/blocks/ChestBlockHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
package dev.tonimatas.mossy.blocks; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.instance.block.BlockHandler; | ||
import net.minestom.server.inventory.Inventory; | ||
import net.minestom.server.inventory.InventoryType; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ChestBlockHandler implements BlockHandler { | ||
private final Inventory inventory = new Inventory(InventoryType.CHEST_3_ROW, Component.translatable("container.chest")); | ||
|
||
@Override | ||
public boolean onInteract(@NotNull Interaction interaction) { | ||
System.out.println("Chest opened."); | ||
// TODO: Make the logic | ||
interaction.getPlayer().openInventory(inventory); | ||
return BlockHandler.super.onInteract(interaction); | ||
} | ||
|
||
@Override | ||
public @NotNull NamespaceID getNamespaceId() { | ||
return NamespaceID.from("minecraft:chest"); | ||
return Block.CHEST.namespace(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/tonimatas/mossy/blocks/ChippedAnvilBlockHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.tonimatas.mossy.blocks; | ||
|
||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.instance.block.BlockHandler; | ||
import net.minestom.server.inventory.type.AnvilInventory; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ChippedAnvilBlockHandler extends AnvilBlockHandler { | ||
@Override | ||
public @NotNull NamespaceID getNamespaceId() { | ||
return Block.CHIPPED_ANVIL.namespace(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/dev/tonimatas/mossy/blocks/DamagedAnvilBlockHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.tonimatas.mossy.blocks; | ||
|
||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DamagedAnvilBlockHandler extends AnvilBlockHandler { | ||
@Override | ||
public @NotNull NamespaceID getNamespaceId() { | ||
return Block.DAMAGED_ANVIL.namespace(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/tonimatas/mossy/blocks/placement/AnvilBlockPlacementRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.tonimatas.mossy.blocks.placement; | ||
|
||
import net.minestom.server.instance.block.Block; | ||
import net.minestom.server.instance.block.rule.BlockPlacementRule; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
public class AnvilBlockPlacementRule extends BlockPlacementRule { | ||
private static final String HORIZONTAL_DIRECTION = "vertical_direction"; | ||
|
||
protected AnvilBlockPlacementRule() { | ||
super(Block.ANVIL); | ||
} | ||
|
||
@Override | ||
public @Nullable Block blockPlace(@NotNull BlockPlacementRule.PlacementState placementState) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,5 @@ | |
|
||
public class BlockEvents { | ||
public static void init(GlobalEventHandler eventHandler) { | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/dev/tonimatas/mossy/events/InventoryEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.tonimatas.mossy.events; | ||
|
||
import net.minestom.server.event.GlobalEventHandler; | ||
import net.minestom.server.event.inventory.InventoryCloseEvent; | ||
import net.minestom.server.inventory.Inventory; | ||
import net.minestom.server.inventory.InventoryType; | ||
import net.minestom.server.item.ItemStack; | ||
|
||
public class InventoryEvents { | ||
public static void init(GlobalEventHandler eventHandler) { | ||
eventHandler.addListener(InventoryCloseEvent.class, event -> { | ||
Inventory inventory = event.getInventory(); | ||
if (inventory == null) return; | ||
InventoryType inventoryType = inventory.getInventoryType(); | ||
|
||
if (inventoryType.equals(InventoryType.ANVIL)) { | ||
for (ItemStack itemStack : inventory.getItemStacks()) { | ||
event.getPlayer().getInventory().addItemStack(itemStack); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters