Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(actions): BlockPlayNoteAction #49

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kunlab.scenamatica.nms.types.world;

import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.NMSWrapped;
Expand Down Expand Up @@ -38,4 +39,14 @@ public interface NMSWorldServer extends NMSWrapped
@NotNull
@Versioned(from = "1.17")
NMSPersistentEntitySectionManager<Entity> getEntityManager();

/**
* ブロックのアクションを再生します。
* e.g. 音ブロックの再生
*
* @param block ブロック
* @param param1 ブロック固有パラメータ1
* @param param2 ブロック固有パラメータ2
*/
void playBlockAction(Block block, int param1, int param2);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_13_R1.world;

import net.minecraft.server.v1_13_R1.BlockPosition;
import net.minecraft.server.v1_13_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_13_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -58,4 +61,12 @@ public World getBukkit()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_13_R1.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_13_R2.world;

import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_13_R2.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -59,4 +62,12 @@ public NMSChunkProvider getChunkProvider()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_13_R2.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_14_R1.world;

import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -59,4 +62,12 @@ public NMSChunkProvider getChunkProvider()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_14_R1.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_15_R1.world;

import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -58,4 +61,12 @@ public World getBukkit()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_15_R1.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_16_R1.world;

import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -58,4 +61,12 @@ public World getBukkit()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_16_R1.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_16_R2.world;

import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R2.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -58,4 +61,12 @@ public World getBukkit()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_16_R2.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_16_R3.world;

import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.exceptions.UnsupportedNMSOperationException;
Expand Down Expand Up @@ -58,4 +61,12 @@ public World getBukkit()
NMSPersistentEntitySectionManager.class
);
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.server.v1_16_R3.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.kunlab.scenamatica.nms.impl.v1_17_R1.world;

import net.minecraft.core.BlockPosition;
import net.minecraft.server.level.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.types.world.NMSChunkProvider;
Expand Down Expand Up @@ -55,4 +58,12 @@ public World getBukkit()
{
return this.entityManager;
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
net.minecraft.world.level.block.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.playBlockAction(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.kunlab.scenamatica.nms.impl.v1_18_R1.world;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.kunlab.scenamatica.nms.types.world.NMSChunkProvider;
Expand Down Expand Up @@ -56,4 +59,12 @@ public World getBukkit()
{
return this.entityManager;
}

@Override
public void playBlockAction(Block block, int param1, int param2)
{
BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
net.minecraft.world.level.block.Block nmsBlock = CraftMagicNumbers.getBlock(block.getBlockData().getMaterial());
this.nmsWorld.blockEvent(blockPosition, nmsBlock, param1, param2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import org.kunlab.scenamatica.enums.YAMLNodeType;
import org.kunlab.scenamatica.exceptions.scenariofile.InvalidScenarioFileException;
import org.kunlab.scenamatica.exceptions.scenariofile.YamlParsingException;
import org.kunlab.scenamatica.interfaces.action.ActionContext;
import org.kunlab.scenamatica.interfaces.action.input.InputToken;
import org.kunlab.scenamatica.interfaces.action.input.Traverser;
import org.kunlab.scenamatica.interfaces.action.types.Requireable;
import org.kunlab.scenamatica.interfaces.scenariofile.Structure;
import org.kunlab.scenamatica.interfaces.scenariofile.StructureSerializer;
import org.kunlab.scenamatica.interfaces.scenariofile.StructuredYamlNode;
import org.kunlab.scenamatica.scenariofile.StructuredYamlNodeImpl;
Expand All @@ -28,6 +31,12 @@ else if (clazz == Double.class || clazz == double.class)
return clazz.cast(num.doubleValue());
else if (clazz == Float.class || clazz == float.class)
return clazz.cast(num.floatValue());
else if (clazz == Short.class || clazz == short.class)
return clazz.cast(num.shortValue());
else if (clazz == Byte.class || clazz == byte.class)
return clazz.cast(num.byteValue());
else if (clazz == Number.class)
return clazz.cast(num);
else
throw new IllegalArgumentException("Unknown number type: " + clazz);
}
Expand Down Expand Up @@ -151,16 +160,23 @@ else if (StructuredYamlNode.class.isAssignableFrom(toClass))

private static boolean canSmartCast(Class<?> clazz, Object obj)
{
boolean isStrNodeClass = StructuredYamlNode.class.isAssignableFrom(clazz);

return obj == null
|| clazz.isInstance(obj)
|| clazz == String.class
|| (Number.class.isAssignableFrom(clazz) && obj instanceof Number)
|| ((isStrNodeClass || List.class.isAssignableFrom(clazz)) && obj instanceof List)
|| ((isStrNodeClass || Map.class.isAssignableFrom(clazz)) && obj instanceof Map)
|| (Boolean.class.isAssignableFrom(clazz) && obj instanceof Boolean)
|| (obj instanceof StructuredYamlNode);
if (obj == null || clazz.isInstance(obj) || clazz == String.class
// Requireable のためのパッチ
|| Requireable.class.isAssignableFrom(clazz) || ActionContext.class.isAssignableFrom(clazz))
return true;

return isMatchingType(Number.class, obj, YAMLNodeType.NUMBER)
|| isMatchingType(Boolean.class, obj, YAMLNodeType.BOOLEAN)
|| isMatchingType(List.class, obj, YAMLNodeType.LIST)
|| ((Map.class.isAssignableFrom(clazz) || StructuredYamlNode.class.isAssignableFrom(clazz)) &&
(obj instanceof Map || obj instanceof StructuredYamlNode && ((StructuredYamlNode) obj).isType(YAMLNodeType.MAPPING)))
|| (Structure.class.isAssignableFrom(clazz) && obj instanceof StructuredYamlNode && ((StructuredYamlNode) obj).isType(YAMLNodeType.MAPPING));
}

private static boolean isMatchingType(Class<?> clazz, Object obj, YAMLNodeType nodeType)
{
return clazz.isAssignableFrom(obj.getClass())
|| (obj instanceof StructuredYamlNode && ((StructuredYamlNode) obj).isType(nodeType));
}

/* non-public */
Expand Down
Loading
Loading