Skip to content

Commit

Permalink
LocationTag.ring_bell
Browse files Browse the repository at this point in the history
for #2110
  • Loading branch information
mcmonkey4eva committed Dec 4, 2021
1 parent da63ad3 commit f2bf73f
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 17 deletions.
2 changes: 1 addition & 1 deletion paper/pom.xml
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class EntityDeathScriptEvent extends BukkitScriptEvent implements Listene
// @Group Entity
//
// @Location true
// @Switch by:<entity type> to only process the event if the killer is of a specified entity type.
// @Switch by:<entity> to only process the event if the killer is known and matches the specified entity matcher.
// @Switch cause:<cause> to only process the event if it was caused by a specific damage cause.
//
// @Triggers when an entity dies. Note that this fires *after* the entity dies, and thus some data may be lost from the entity.
Expand Down
Expand Up @@ -5,9 +5,7 @@
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.world.PortalCreateEvent;

Expand Down Expand Up @@ -83,4 +81,8 @@ default void doRandomTick(Location location) {
default Instrument getInstrumentFor(Material mat) {
throw new UnsupportedOperationException();
}

default void ringBell(Bell block) {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -4563,6 +4563,25 @@ else if (state instanceof Dropper) {
}
}

// <--[mechanism]
// @object LocationTag
// @name ring_bell
// @input None
// @description
// Causes the bell to ring.
// @tags
// <LocationTag.campfire_items>
// -->
if (mechanism.matches("ring_bell")) {
BlockState state = getBlockState();
if (!(state instanceof Bell)) {
Debug.echoError("'ring_bell' mechanism can only be called on Bell blocks.");
}
else {
NMSHandler.getBlockHelper().ringBell((Bell) state);
}
}

CoreUtilities.autoPropertyMechanism(this, mechanism);
}

Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizen.scripts.commands.world;

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.objects.properties.material.MaterialSwitchable;
import com.denizenscript.denizen.utilities.debugging.Debug;
Expand All @@ -16,6 +17,8 @@
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Bell;
import org.bukkit.block.Block;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
Expand Down Expand Up @@ -56,6 +59,7 @@ public SwitchCommand() {
// - Single-use interactables like buttons, note blocks, dispensers, droppers, ...
// - Redstone interactables like repeaters, ...
// - Special interactables like tripwires, ...
// - Bells as a special case will ring when you use 'switch' on them, ...
// - Almost any other block with an interaction handler.
//
// This will generally (but not always) function equivalently to a user right-clicking the block
Expand Down Expand Up @@ -170,6 +174,10 @@ public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, Swit
Debug.echoError("Cannot switch block of type '" + materialTag.getMaterial().name() + "'");
return;
}
if (materialTag.getMaterial() == Material.BELL) {
NMSHandler.getBlockHelper().ringBell((Bell) block.getState());
return;
}
boolean currentState = switchable.getState();
if ((switchState.equals(SwitchState.ON) && !currentState) || (switchState.equals(SwitchState.OFF) && currentState) || switchState.equals(SwitchState.TOGGLE)) {
switchable.setState(!currentState);
Expand Down
Expand Up @@ -12,11 +12,13 @@
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BellBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -26,15 +28,11 @@
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_17_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockEntityState;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftSkull;
import org.bukkit.craftbukkit.v1_17_R1.block.*;
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
Expand Down Expand Up @@ -287,4 +285,27 @@ public Instrument getInstrumentFor(Material mat) {
NoteBlockInstrument nmsInstrument = NoteBlockInstrument.byState(blockType.defaultBlockState());
return Instrument.values()[(nmsInstrument.ordinal())];
}

@Override
public void ringBell(Bell block) {
org.bukkit.block.data.type.Bell bellData = (org.bukkit.block.data.type.Bell) block.getBlockData();
Direction face = Direction.byName(bellData.getFacing().name());
Direction dir = Direction.NORTH;
switch (bellData.getAttachment()) {
case DOUBLE_WALL:
case SINGLE_WALL:
switch (face) {
case NORTH:
case SOUTH:
dir = Direction.EAST;
break;
}
break;
case FLOOR:
dir = face;
break;
}
CraftBlock craftBlock = (CraftBlock) block.getBlock();
((BellBlock) Blocks.BELL).attemptToRing(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition(), dir);
}
}
Expand Up @@ -12,11 +12,13 @@
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BellBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
Expand All @@ -26,15 +28,11 @@
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockEntityState;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_18_R1.block.CraftSkull;
import org.bukkit.craftbukkit.v1_18_R1.block.*;
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers;
Expand Down Expand Up @@ -286,4 +284,27 @@ public Instrument getInstrumentFor(Material mat) {
NoteBlockInstrument nmsInstrument = NoteBlockInstrument.byState(blockType.defaultBlockState());
return Instrument.values()[(nmsInstrument.ordinal())];
}

@Override
public void ringBell(Bell block) {
org.bukkit.block.data.type.Bell bellData = (org.bukkit.block.data.type.Bell) block.getBlockData();
Direction face = Direction.byName(bellData.getFacing().name());
Direction dir = Direction.NORTH;
switch (bellData.getAttachment()) {
case DOUBLE_WALL:
case SINGLE_WALL:
switch (face) {
case NORTH:
case SOUTH:
dir = Direction.EAST;
break;
}
break;
case FLOOR:
dir = face;
break;
}
CraftBlock craftBlock = (CraftBlock) block.getBlock();
((BellBlock) Blocks.BELL).attemptToRing(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition(), dir);
}
}

0 comments on commit f2bf73f

Please sign in to comment.