Skip to content

Commit

Permalink
feat: implement beacon block
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jan 7, 2025
1 parent 683b7b4 commit af7a852
Show file tree
Hide file tree
Showing 31 changed files with 505 additions and 82 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Added `BlockGrowEvent` which will be called when crops grow.
- (API) Added two overloads `LightService#getInternalLight(Vector3ic)` and `LightService#getSkyLight(Vector3ic)`, they
have the same functionality as `LightService#getXXXLight(int, int, int)`.
- (API) Implemented beacon block, and several related interfaces are added to api module.
- (API) `BlockContainer#getBlockPos` and `BlockContainer#setBlockPos` now return/require `Position3ic` instead of
`Vector3ic`, this enables us to get the dimension information of a `BlockContainer`.
- Implemented trapdoor except redstone feature (Redstone feature requires the implementation of redstone system).
- Implemented sponge and wet sponge.
- Implemented farmland and hoe.
Expand All @@ -50,13 +53,16 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Removed `ScoreboardService#ServerEventListener` as it is not supposed to be touched by plugin.
- Removed useless class `PackageClassLoaderUtils`, dependency `org.reflections.reflections` is also removed.
- Added `-dev` suffix to api version in development build.
- Changed `ContainerActionProcessorHolder` to a final class instead of an interface, because this abstraction is
meaningless.

### Fixed

- (API) `BlockHangingSignBehavior` now extends `BlockEntityHolderComponent<BlockEntityHangingSign>` which was forgotten
to be added.
- Fixed the bug that interacting with door doesn't have any sound.
- Waxing copper-made block using honeycomb won't call `BlockFadeEvent` now.
- Fixed the bug that player can still open enchant table even if he is sneaking.

## [0.1.2](https://github.com/AllayMC/Allay/releases/tag/0.1.2) (API 0.3.0) - 2024-12-31

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.BlockEntityHolderComponent;
import org.allaymc.api.blockentity.interfaces.BlockEntityBeacon;

public interface BlockBeaconBehavior extends BlockBehavior {
public interface BlockBeaconBehavior extends BlockBehavior, BlockEntityHolderComponent<BlockEntityBeacon> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface BlockCustomTags {

BlockTag SOUL_FIRE_CONVERTER = create("allay:soul_fire_converter");

BlockTag BEACON_BASE = create("allay:beacon_base");

BlockTag REPLACEABLE = create("allay:replaceable");

BlockTag WOOL = create("allay:wool");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.allaymc.api.blockentity.component;

import org.allaymc.api.entity.effect.EffectType;

/**
* @author daoge_cmd
*/
public interface BlockEntityBeaconBaseComponent extends BlockEntityBaseComponent {
/**
* Get the level of the beacon.
* <p>
* level is the amount of the pyramid's levels, it is defined by the mineral blocks which build up the
* pyramid, and can be 0-4.
*
* @return the level of the beacon.
*/
int getLevel();

/**
* Get the primary effect of the beacon.
*
* @return the primary effect of the beacon, or {@code null} if no primary effect.
*/
EffectType getPrimaryEffect();

/**
* Set the primary effect of the beacon.
*
* @param effectType the primary effect of the beacon.
*/
void setPrimaryEffect(EffectType effectType);

/**
* Check if the beacon has a primary effect.
*
* @return {@code true} if the beacon has a primary effect, otherwise {@code false}.
*/
default boolean hasPrimaryEffect() {
return getPrimaryEffect() != null;
}

/**
* Get the secondary effect of the beacon.
*
* @return the secondary effect of the beacon, or {@code null} if no secondary effect.
*/
EffectType getSecondaryEffect();

/**
* Set the secondary effect of the beacon.
*
* @param effectType the secondary effect of the beacon.
*/
void setSecondaryEffect(EffectType effectType);

/**
* Check if the beacon has a secondary effect.
*
* @return {@code true} if the beacon has a secondary effect, otherwise {@code false}.
*/
default boolean hasSecondaryEffect() {
return getSecondaryEffect() != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.allaymc.api.blockentity.interfaces;

import org.allaymc.api.blockentity.BlockEntity;
import org.allaymc.api.blockentity.component.BlockEntityBeaconBaseComponent;

/**
* @author daoge_cmd
*/
public interface BlockEntityBeacon extends BlockEntity, BlockEntityBeaconBaseComponent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public final class BlockEntityTypes {
public static BlockEntityType<BlockEntityHangingSign> HANGING_SIGN;
public static BlockEntityType<BlockEntityEnchantTable> ENCHANT_TABLE;
public static BlockEntityType<BlockEntityJukebox> JUKEBOX;
public static BlockEntityType<BlockEntityBeacon> BEACON;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public record FullContainerType<T extends Container>(
.mapRangedNetworkSlotIndex(14, 15, 0)
.build();

public static final FullContainerType<BeaconContainer> BEACON = builder()
.id(ContainerType.BEACON)
.size(1)
.mapAllSlotToType(ContainerSlotType.BEACON_PAYMENT)
.mapNetworkSlotIndex(27, BeaconContainer.BEACON_PAYMENT_SLOT)
.build();

public FullContainerType(int id, ContainerSlotType[] slotTypeTable, Set<ContainerSlotType> heldSlotTypes, BiMap<Integer, Integer> networkSlotIndexMapper) {
this.id = id;
this.slotTypeTable = slotTypeTable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.allaymc.api.container.impl;

import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.item.ItemStack;

/**
* @author daoge_cmd
*/
public class BeaconContainer extends BlockContainer {
public static final int BEACON_PAYMENT_SLOT = 0;

public BeaconContainer() {
super(FullContainerType.BEACON);
}

/**
* Get the item stack in the payment slot.
*
* @return The item stack in the payment slot.
*/
public ItemStack getBeaconPayment() {
return this.getItemStack(BEACON_PAYMENT_SLOT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import org.allaymc.api.container.BaseContainer;
import org.allaymc.api.container.Container;
import org.allaymc.api.container.FullContainerType;
import org.joml.Vector3ic;
import org.allaymc.api.math.position.Position3ic;

/**
* @author IWareQ
*/
public class BlockContainer extends BaseContainer {
@Getter
@Setter
protected Vector3ic blockPos;
protected Position3ic blockPos;

public BlockContainer(FullContainerType<? extends Container> containerType) {
super(containerType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.item.recipe.input.CraftingInput;
import org.joml.Vector3ic;
import org.allaymc.api.math.position.Position3ic;

/**
* @author daoge_cmd
Expand Down Expand Up @@ -32,12 +32,12 @@ public CraftingInput createCraftingInput() {
}

@Override
public Vector3ic getBlockPos() {
public Position3ic getBlockPos() {
throw new UnsupportedOperationException();
}

@Override
public void setBlockPos(Vector3ic blockPos) {
public void setBlockPos(Position3ic blockPos) {
throw new UnsupportedOperationException();
}
}
25 changes: 5 additions & 20 deletions api/src/main/java/org/allaymc/api/entity/effect/EffectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,21 @@
*/
public interface EffectType {
/**
* Creates a new instance of this effect with the given amplifier and default duration.
*
* @param amplifier The amplifier of the effect.
*
* @return A new instance of this effect.
* @see #createInstance(int, int, boolean, boolean)
*/
default EffectInstance createInstance(int amplifier) {
return createInstance(amplifier, 15);
}

/**
* Creates a new instance of this effect with the given amplifier and duration.
*
* @param amplifier The amplifier of the effect.
* @param duration The duration of the effect.
*
* @return A new instance of this effect.
* @see #createInstance(int, int, boolean, boolean)
*/
default EffectInstance createInstance(int amplifier, int duration) {
return createInstance(amplifier, duration, true);
}

/**
* Creates a new instance of this effect with the given amplifier, duration, and visibility.
*
* @param amplifier The amplifier of the effect.
* @param duration The duration of the effect.
* @param visible Whether the effect is visible.
*
* @return A new instance of this effect.
* @see #createInstance(int, int, boolean, boolean)
*/
default EffectInstance createInstance(int amplifier, int duration, boolean visible) {
return createInstance(amplifier, duration, false, visible);
Expand All @@ -48,8 +33,8 @@ default EffectInstance createInstance(int amplifier, int duration, boolean visib
* Creates a new instance of this effect with the given amplifier, duration, ambient and visibility.
*
* @param amplifier The amplifier of the effect.
* @param duration The duration of the effect.
* @param ambient Whether the effect is ambient.
* @param duration The duration of the effect in ticks.
* @param ambient Whether the effect is ambient. Note that ambient 0 is level 1, and ambient 1 is level 2.
* @param visible Whether the effect is visible.
*
* @return A new instance of this effect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public interface ItemCustomTags {
Map<String, ItemTag> NAME_TO_TAG = new HashMap<>();

ItemTag BEACON_PAYMENT = create("allay:beacon_payment");

static ItemTag create(String name) {
var tag = new ItemTag(name);
NAME_TO_TAG.put(name, tag);
Expand Down
7 changes: 7 additions & 0 deletions data/resources/block_tags_custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,12 @@
"allay:lava": [
"minecraft:lava",
"minecraft:flowing_lava"
],
"allay:beacon_base": [
"minecraft:iron_block",
"minecraft:gold_block",
"minecraft:diamond_block",
"minecraft:emerald_block",
"minecraft:netherite_block"
]
}
10 changes: 9 additions & 1 deletion data/resources/item_tags_custom.json
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
{}
{
"allay:beacon_payment": [
"minecraft:iron_ingot",
"minecraft:gold_ingot",
"minecraft:diamond",
"minecraft:emerald",
"minecraft:netherite_ingot"
]
}
1 change: 1 addition & 0 deletions server/src/jmh/java/org/allaymc/server/ChunkJMHTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ChunkJMHTest {

@Setup
public void init() throws MissingImplementationException {
Allay.initI18n();
Allay.initAllay();
chunk = AllayUnsafeChunk.builder().newChunk(0, 0, DimensionInfo.OVERWORLD).toSafeChunk();
for (int i = 0; i < 16; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.allaymc.server;

import org.allaymc.api.MissingImplementationException;
import org.allaymc.api.world.DimensionInfo;
import org.allaymc.api.world.Weather;
import org.allaymc.server.world.chunk.AllayUnsafeChunk;
Expand All @@ -23,7 +24,9 @@ public class LightServiceJMHTest {
private AllayLightService lightService;

@Setup
public void setup() {
public void setup() throws MissingImplementationException {
Allay.initI18n();
Allay.initAllay();
lightService = new AllayLightService(DimensionInfo.THE_END, () -> 0, () -> Set.of(Weather.CLEAR));
for (int x = -3; x <= 3; x++) {
for (int z = -3; z <= 3; z++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ThroughList2ArrayJMHTest {

@Setup
public void setup() throws MissingImplementationException {
Allay.initI18n();
Allay.initAllay();
data1[0] = BlockPropertyTypes.AGE_16.createValue(5);
data1[1] = BlockPropertyTypes.ACTIVE.createValue(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.allaymc.server.block.component;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.dto.PlayerInteractInfo;
import org.allaymc.api.block.type.BlockType;
import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.math.position.Position3i;
import org.allaymc.api.world.Dimension;

/**
* @author daoge_cmd
*/
public class BlockBeaconBaseComponentImpl extends BlockBaseComponentImpl {
public BlockBeaconBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) {
super(blockType);
}

@Override
public boolean onInteract(ItemStack itemStack, Dimension dimension, PlayerInteractInfo interactInfo) {
if (super.onInteract(itemStack, dimension, interactInfo)) {
return true;
}

var player = interactInfo.player();
if (player.isSneaking()) {
return false;
}

var beaconContainer = player.getContainer(FullContainerType.BEACON);
beaconContainer.setBlockPos(new Position3i(interactInfo.clickedBlockPos(), interactInfo.player().getDimension()));
beaconContainer.addViewer(player);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.allaymc.api.block.type.BlockType;
import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.math.position.Position3i;
import org.allaymc.api.world.Dimension;

/**
Expand All @@ -23,7 +24,7 @@ public boolean onInteract(ItemStack itemStack, Dimension dimension, PlayerIntera
if (player.isSneaking()) return false;

var craftingTableContainer = player.getContainer(FullContainerType.CRAFTING_TABLE);
craftingTableContainer.setBlockPos(interactInfo.clickedBlockPos());
craftingTableContainer.setBlockPos(new Position3i(interactInfo.clickedBlockPos(), interactInfo.player().getDimension()));
craftingTableContainer.addViewer(player);
return true;
}
Expand Down
Loading

0 comments on commit af7a852

Please sign in to comment.