mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-26 18:39:11 +00:00
Added slab and stair top/bottom totem conditions, and included some comments.
This commit is contained in:
@@ -29,6 +29,7 @@ import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.property.AxisImpl;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.property.FaceImpl;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.TotemBlock;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.property.HalfImpl;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.property.TotemBlockProperty;
|
||||
import net.momirealms.customfishing.mechanic.totem.block.type.TypeCondition;
|
||||
import net.momirealms.customfishing.mechanic.totem.particle.DustParticleSetting;
|
||||
@@ -37,6 +38,7 @@ import net.momirealms.customfishing.util.LocationUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -393,14 +395,21 @@ public class TotemManagerImpl implements TotemManager, Listener {
|
||||
String key = split[0];
|
||||
String value = split[1];
|
||||
switch (key) {
|
||||
// Block face
|
||||
case "face" -> {
|
||||
BlockFace blockFace = BlockFace.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
propertyList.add(new FaceImpl(blockFace));
|
||||
}
|
||||
// Block axis
|
||||
case "axis" -> {
|
||||
Axis axis = Axis.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
propertyList.add(new AxisImpl(axis));
|
||||
}
|
||||
// Slab, Stair half
|
||||
case "half" -> {
|
||||
Bisected.Half half = Bisected.Half.valueOf(value.toUpperCase(Locale.ENGLISH));
|
||||
propertyList.add(new HalfImpl(half));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ public class TotemBlock implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw text of the totem block.
|
||||
* @return The raw text of the totem block.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringJoiner stringJoiner = new StringJoiner(";");
|
||||
|
||||
@@ -37,6 +37,10 @@ public class AxisImpl implements TotemBlockProperty, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the block axis 90 degrees. (X -> Z, Z -> X)
|
||||
* @return The rotated block axis.
|
||||
*/
|
||||
@Override
|
||||
public TotemBlockProperty rotate90() {
|
||||
if (this.axis == Axis.X) {
|
||||
@@ -47,6 +51,11 @@ public class AxisImpl implements TotemBlockProperty, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block has the property.
|
||||
* @param block The block to check.
|
||||
* @return True if the block has the property.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPropertyMet(Block block) {
|
||||
if (block.getBlockData() instanceof Orientable orientable) {
|
||||
|
||||
@@ -33,6 +33,11 @@ public class FaceImpl implements TotemBlockProperty, Serializable {
|
||||
this.blockFace = blockFace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the block face if the axis is X or Z.
|
||||
* @param axis The axis to mirror.
|
||||
* @return The mirrored block face.
|
||||
*/
|
||||
@Override
|
||||
public TotemBlockProperty mirror(Axis axis) {
|
||||
if (axis == Axis.X) {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.momirealms.customfishing.mechanic.totem.block.property;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
public class HalfImpl implements TotemBlockProperty, Serializable {
|
||||
private final Bisected.Half half;
|
||||
|
||||
public HalfImpl(Bisected.Half half) {
|
||||
this.half = half;
|
||||
}
|
||||
|
||||
/**
|
||||
* half is not affected by mirroring.
|
||||
* @param axis The axis to mirror.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public TotemBlockProperty mirror(Axis axis) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* half is not affected by rotation.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public TotemBlockProperty rotate90() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block's half is the same as the half of this property.
|
||||
* @param block The block to check.
|
||||
* @return true if the block's half is the same as the half of this property.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPropertyMet(Block block) {
|
||||
if (block.getBlockData() instanceof Bisected bisected) {
|
||||
return bisected.getHalf().equals(this.half);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw text of the half property.
|
||||
* @return The raw text of the half property.
|
||||
*/
|
||||
@Override
|
||||
public String getRawText() {
|
||||
return "half=" + half.name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,29 @@ import org.bukkit.block.Block;
|
||||
|
||||
public interface TotemBlockProperty {
|
||||
|
||||
|
||||
/**
|
||||
* Mirrors the block face if the axis is X or Z.
|
||||
* @param axis The axis to mirror.
|
||||
* @return The mirrored block face.
|
||||
*/
|
||||
TotemBlockProperty mirror(Axis axis);
|
||||
|
||||
/**
|
||||
* Rotates the block face 90 degrees.
|
||||
* @return The rotated block face.
|
||||
*/
|
||||
TotemBlockProperty rotate90();
|
||||
|
||||
/**
|
||||
* Checks if the block has the property.
|
||||
* @param block The block to check.
|
||||
* @return True if the block has the property.
|
||||
*/
|
||||
boolean isPropertyMet(Block block);
|
||||
|
||||
/**
|
||||
* Gets the raw text of the property.
|
||||
* @return The raw text of the property.
|
||||
*/
|
||||
String getRawText();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ double_loot_totem:
|
||||
core: 3,1,2 # layer:3 line:1 index:2 -> CRYING_OBSIDIAN
|
||||
layer:
|
||||
4:
|
||||
- '*_STAIRS{face=east} OBSERVER{face=south} *_STAIRS{face=west}'
|
||||
- '*_STAIRS{face=east;half=top} OBSERVER{face=south} *_STAIRS{face=west;half=top}'
|
||||
3:
|
||||
- 'AIR CRYING_OBSIDIAN AIR'
|
||||
2:
|
||||
|
||||
Reference in New Issue
Block a user