Skip to content

Commit

Permalink
Added use to the KeyBlocksCache in other places in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jun 30, 2023
1 parent 46f6363 commit 730a042
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 170 deletions.
Expand Up @@ -2,20 +2,21 @@

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.algorithms.PaperGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.algorithms.SpigotGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.v117.menu.MenuBrewingStandBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v117.menu.MenuDispenserBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v117.menu.MenuFurnaceBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v117.menu.MenuHopperBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v117.world.KeyBlocksCache;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
Expand All @@ -24,12 +25,13 @@
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftFallingBlock;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftMinecart;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -108,18 +110,22 @@ public int compareMaterials(Material o1, Material o2) {

@Override
public Key getBlockKey(int combinedId) {
Material material = CraftMagicNumbers.getMaterial(Block.stateById(combinedId).getBlock());
return KeyImpl.of(material, (byte) 0);
Block block = Block.stateById(combinedId).getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getMinecartBlock(Minecart minecart) {
return KeyImpl.of(minecart.getDisplayBlockData().getMaterial(), (byte) 0);
public Key getMinecartBlock(org.bukkit.entity.Minecart bukkitMinecart) {
AbstractMinecart minecart = ((CraftMinecart) bukkitMinecart).getHandle();
Block block = minecart.getDisplayBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getFallingBlockType(FallingBlock fallingBlock) {
return KeyImpl.of(fallingBlock.getBlockData().getMaterial(), (byte) 0);
public Key getFallingBlockType(FallingBlock bukkitFallingBlock) {
FallingBlockEntity fallingBlock = ((CraftFallingBlock) bukkitFallingBlock).getHandle();
Block block = fallingBlock.getBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.bgsoftware.superiorskyblock.nms.algorithms.NMSCachedBlock;
import com.bgsoftware.superiorskyblock.nms.v117.generator.IslandsGeneratorImpl;
import com.bgsoftware.superiorskyblock.nms.v117.spawners.TickingSpawnerBlockEntityNotifier;
import com.bgsoftware.superiorskyblock.nms.v117.world.KeyBlocksCache;
import com.bgsoftware.superiorskyblock.nms.v117.world.PropertiesMapper;
import com.bgsoftware.superiorskyblock.nms.v117.world.WorldEditSessionImpl;
import com.bgsoftware.superiorskyblock.nms.world.WorldEditSession;
Expand Down Expand Up @@ -44,7 +45,6 @@
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
Expand Down Expand Up @@ -81,18 +81,17 @@ public NMSWorldImpl(SuperiorSkyblockPlugin plugin) {

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
BlockState blockState = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState();
Material type = chunkSnapshot.getBlockType(x, y, z);
short data = (short) (Block.getId(blockState) >> 12 & 15);

Block block = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState().getBlock();
Location location = new Location(
Bukkit.getWorld(chunkSnapshot.getWorldName()),
(chunkSnapshot.getX() << 4) + x,
y,
(chunkSnapshot.getZ() << 4) + z
);

return KeyImpl.of(KeyImpl.of(type, data), location);
Key rawBlockKey = KeyBlocksCache.getBlockKey(block);

return KeyImpl.of(rawBlockKey, location);
}

@Override
Expand Down
Expand Up @@ -2,20 +2,21 @@

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.algorithms.PaperGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.algorithms.SpigotGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.v1182.menu.MenuBrewingStandBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1182.menu.MenuDispenserBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1182.menu.MenuFurnaceBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1182.menu.MenuHopperBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1182.world.KeyBlocksCache;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
Expand All @@ -24,12 +25,13 @@
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftFallingBlock;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftMinecart;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftChatMessage;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -109,18 +111,22 @@ public int compareMaterials(Material o1, Material o2) {

@Override
public Key getBlockKey(int combinedId) {
Material material = CraftMagicNumbers.getMaterial(Block.stateById(combinedId).getBlock());
return KeyImpl.of(material, (byte) 0);
Block block = Block.stateById(combinedId).getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getMinecartBlock(Minecart minecart) {
return KeyImpl.of(minecart.getDisplayBlockData().getMaterial(), (byte) 0);
public Key getMinecartBlock(org.bukkit.entity.Minecart bukkitMinecart) {
AbstractMinecart minecart = ((CraftMinecart) bukkitMinecart).getHandle();
Block block = minecart.getDisplayBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getFallingBlockType(FallingBlock fallingBlock) {
return KeyImpl.of(fallingBlock.getBlockData().getMaterial(), (byte) 0);
public Key getFallingBlockType(FallingBlock bukkitFallingBlock) {
FallingBlockEntity fallingBlock = ((CraftFallingBlock) bukkitFallingBlock).getHandle();
Block block = fallingBlock.getBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.bgsoftware.superiorskyblock.nms.algorithms.NMSCachedBlock;
import com.bgsoftware.superiorskyblock.nms.v1182.generator.IslandsGeneratorImpl;
import com.bgsoftware.superiorskyblock.nms.v1182.spawners.TickingSpawnerBlockEntityNotifier;
import com.bgsoftware.superiorskyblock.nms.v1182.world.KeyBlocksCache;
import com.bgsoftware.superiorskyblock.nms.v1182.world.PropertiesMapper;
import com.bgsoftware.superiorskyblock.nms.v1182.world.WorldEditSessionImpl;
import com.bgsoftware.superiorskyblock.nms.world.WorldEditSession;
Expand Down Expand Up @@ -44,7 +45,6 @@
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
Expand Down Expand Up @@ -82,18 +82,17 @@ public NMSWorldImpl(SuperiorSkyblockPlugin plugin) {

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
BlockState blockState = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState();
Material type = chunkSnapshot.getBlockType(x, y, z);
short data = (short) (Block.getId(blockState) >> 12 & 15);

Block block = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState().getBlock();
Location location = new Location(
Bukkit.getWorld(chunkSnapshot.getWorldName()),
(chunkSnapshot.getX() << 4) + x,
y,
(chunkSnapshot.getZ() << 4) + z
);

return KeyImpl.of(KeyImpl.of(type, data), location);
Key rawBlockKey = KeyBlocksCache.getBlockKey(block);

return KeyImpl.of(rawBlockKey, location);
}

@Override
Expand Down
Expand Up @@ -2,20 +2,21 @@

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.algorithms.PaperGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.algorithms.SpigotGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.v119.menu.MenuBrewingStandBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v119.menu.MenuDispenserBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v119.menu.MenuFurnaceBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v119.menu.MenuHopperBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v119.world.KeyBlocksCache;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
Expand All @@ -24,12 +25,13 @@
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftFallingBlock;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftMinecart;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -109,18 +111,22 @@ public int compareMaterials(Material o1, Material o2) {

@Override
public Key getBlockKey(int combinedId) {
Material material = CraftMagicNumbers.getMaterial(Block.stateById(combinedId).getBlock());
return KeyImpl.of(material, (byte) 0);
Block block = Block.stateById(combinedId).getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getMinecartBlock(Minecart minecart) {
return KeyImpl.of(minecart.getDisplayBlockData().getMaterial(), (byte) 0);
public Key getMinecartBlock(org.bukkit.entity.Minecart bukkitMinecart) {
AbstractMinecart minecart = ((CraftMinecart) bukkitMinecart).getHandle();
Block block = minecart.getDisplayBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getFallingBlockType(FallingBlock fallingBlock) {
return KeyImpl.of(fallingBlock.getBlockData().getMaterial(), (byte) 0);
public Key getFallingBlockType(FallingBlock bukkitFallingBlock) {
FallingBlockEntity fallingBlock = ((CraftFallingBlock) bukkitFallingBlock).getHandle();
Block block = fallingBlock.getBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.bgsoftware.superiorskyblock.nms.algorithms.NMSCachedBlock;
import com.bgsoftware.superiorskyblock.nms.v119.generator.IslandsGeneratorImpl;
import com.bgsoftware.superiorskyblock.nms.v119.spawners.TickingSpawnerBlockEntityNotifier;
import com.bgsoftware.superiorskyblock.nms.v119.world.KeyBlocksCache;
import com.bgsoftware.superiorskyblock.nms.v119.world.PropertiesMapper;
import com.bgsoftware.superiorskyblock.nms.v119.world.WorldEditSessionImpl;
import com.bgsoftware.superiorskyblock.nms.world.WorldEditSession;
Expand Down Expand Up @@ -44,7 +45,6 @@
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
Expand Down Expand Up @@ -82,18 +82,17 @@ public NMSWorldImpl(SuperiorSkyblockPlugin plugin) {

@Override
public Key getBlockKey(ChunkSnapshot chunkSnapshot, int x, int y, int z) {
BlockState blockState = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState();
Material type = chunkSnapshot.getBlockType(x, y, z);
short data = (short) (Block.getId(blockState) >> 12 & 15);

Block block = ((CraftBlockData) chunkSnapshot.getBlockData(x, y, z)).getState().getBlock();
Location location = new Location(
Bukkit.getWorld(chunkSnapshot.getWorldName()),
(chunkSnapshot.getX() << 4) + x,
y,
(chunkSnapshot.getZ() << 4) + z
);

return KeyImpl.of(KeyImpl.of(type, data), location);
Key rawBlockKey = KeyBlocksCache.getBlockKey(block);

return KeyImpl.of(rawBlockKey, location);
}

@Override
Expand Down
Expand Up @@ -2,20 +2,21 @@

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.algorithms.PaperGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.algorithms.SpigotGlowEnchantment;
import com.bgsoftware.superiorskyblock.nms.v1191.menu.MenuBrewingStandBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1191.menu.MenuDispenserBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1191.menu.MenuFurnaceBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1191.menu.MenuHopperBlockEntity;
import com.bgsoftware.superiorskyblock.nms.v1191.world.KeyBlocksCache;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
Expand All @@ -24,12 +25,13 @@
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftFallingBlock;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftMinecart;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -109,18 +111,22 @@ public int compareMaterials(Material o1, Material o2) {

@Override
public Key getBlockKey(int combinedId) {
Material material = CraftMagicNumbers.getMaterial(Block.stateById(combinedId).getBlock());
return KeyImpl.of(material, (byte) 0);
Block block = Block.stateById(combinedId).getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getMinecartBlock(Minecart minecart) {
return KeyImpl.of(minecart.getDisplayBlockData().getMaterial(), (byte) 0);
public Key getMinecartBlock(org.bukkit.entity.Minecart bukkitMinecart) {
AbstractMinecart minecart = ((CraftMinecart) bukkitMinecart).getHandle();
Block block = minecart.getDisplayBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
public Key getFallingBlockType(FallingBlock fallingBlock) {
return KeyImpl.of(fallingBlock.getBlockData().getMaterial(), (byte) 0);
public Key getFallingBlockType(FallingBlock bukkitFallingBlock) {
FallingBlockEntity fallingBlock = ((CraftFallingBlock) bukkitFallingBlock).getHandle();
Block block = fallingBlock.getBlockState().getBlock();
return KeyBlocksCache.getBlockKey(block);
}

@Override
Expand Down

0 comments on commit 730a042

Please sign in to comment.