WIP: portals
This commit is contained in:
parent
0c36cb3b9e
commit
df8e285757
4 changed files with 55 additions and 3 deletions
30
src/main/java/ru/betterend/item/EternalCrystal.java
Normal file
30
src/main/java/ru/betterend/item/EternalCrystal.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package ru.betterend.item;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.blocks.RunedFlavolite;
|
||||
import ru.betterend.registry.ItemRegistry;
|
||||
import ru.betterend.util.PortalFrameHelper;
|
||||
|
||||
public class EternalCrystal extends Item {
|
||||
|
||||
public EternalCrystal() {
|
||||
super(ItemRegistry.makeSettings());
|
||||
}
|
||||
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos usedPos = context.getBlockPos();
|
||||
BlockState usedBlock = world.getBlockState(usedPos);
|
||||
if (world instanceof ServerWorld && (usedBlock.getBlock() instanceof RunedFlavolite) && !usedBlock.get(RunedFlavolite.ACTIVATED)) {
|
||||
PortalFrameHelper.checkPortalFrame((ServerWorld) world, usedPos, usedBlock.getBlock());
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ import ru.betterend.item.EndHammer;
|
|||
import ru.betterend.item.EndHoe;
|
||||
import ru.betterend.item.EndPickaxe;
|
||||
import ru.betterend.item.EndToolMaterial;
|
||||
import ru.betterend.item.EternalCrystal;
|
||||
import ru.betterend.tab.CreativeTab;
|
||||
import ru.betterend.util.TagHelper;
|
||||
|
||||
|
@ -75,6 +76,9 @@ public class ItemRegistry {
|
|||
public static final ToolItem DIAMOND_HAMMER = registerTool("diamond_hammer", new EndHammer(ToolMaterials.DIAMOND, 5.5F, -3.1F, 0.2D, makeSettings()));
|
||||
public static final ToolItem NETHERITE_HAMMER = registerTool("netherite_hammer", new EndHammer(ToolMaterials.NETHERITE, 5.0F, -3.0F, 0.2D, makeSettings()));
|
||||
|
||||
// Other //
|
||||
public static final Item ETERNAL_CRYSTAL = registerItem("eternal_crystal", new EternalCrystal());
|
||||
|
||||
protected static Item registerItem(String name, Item item) {
|
||||
if (item != Items.AIR) {
|
||||
Registry.register(Registry.ITEM, BetterEnd.makeID(name), item);
|
||||
|
@ -122,7 +126,7 @@ public class ItemRegistry {
|
|||
return registerItem(name, item);
|
||||
}
|
||||
|
||||
private static Settings makeSettings() {
|
||||
public static Settings makeSettings() {
|
||||
return new Item.Settings().group(CreativeTab.END_TAB);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,18 @@ import net.minecraft.server.world.ServerWorld;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.registry.FeatureRegistry;
|
||||
|
||||
public class PortalFrameHelper {
|
||||
|
||||
public static boolean checkPortalFrame(World world, BlockPos pos, Block frameBlock) {
|
||||
public static boolean checkPortalFrame(ServerWorld world, BlockPos pos, Block frameBlock) {
|
||||
if (world == null || pos == null) return false;
|
||||
if (!world.getBlockState(pos).isOf(frameBlock)) return false;
|
||||
BlockPos bottomCorner = findBottomCorner(world, pos, frameBlock);
|
||||
if (bottomCorner == null) return false;
|
||||
boolean valid = true;
|
||||
Direction.Axis axis = Direction.Axis.X;
|
||||
BlockPos checkPos = bottomCorner.up();
|
||||
Direction moveDir = Direction.UP;
|
||||
while(!checkPos.equals(bottomCorner)) {
|
||||
|
@ -27,11 +28,13 @@ public class PortalFrameHelper {
|
|||
if (!valid) {
|
||||
switch(moveDir) {
|
||||
case UP: {
|
||||
checkPos = checkPos.down();
|
||||
if (world.getBlockState(checkPos.east()).isOf(frameBlock)) {
|
||||
checkPos = checkPos.east();
|
||||
moveDir = Direction.EAST;
|
||||
valid = true;
|
||||
} else if (world.getBlockState(checkPos.north()).isOf(frameBlock)) {
|
||||
axis = Direction.Axis.Z;
|
||||
checkPos = checkPos.north();
|
||||
moveDir = Direction.NORTH;
|
||||
valid = true;
|
||||
|
@ -39,6 +42,7 @@ public class PortalFrameHelper {
|
|||
break;
|
||||
}
|
||||
case DOWN: {
|
||||
checkPos = checkPos.up();
|
||||
if (world.getBlockState(checkPos.west()).isOf(frameBlock)) {
|
||||
checkPos = checkPos.west();
|
||||
moveDir = Direction.WEST;
|
||||
|
@ -52,6 +56,7 @@ public class PortalFrameHelper {
|
|||
}
|
||||
case NORTH:
|
||||
case EAST: {
|
||||
checkPos = moveDir.equals(Direction.NORTH) ? checkPos.south() : checkPos.west();
|
||||
if (world.getBlockState(checkPos.down()).isOf(frameBlock)) {
|
||||
checkPos = checkPos.down();
|
||||
moveDir = Direction.DOWN;
|
||||
|
@ -93,6 +98,13 @@ public class PortalFrameHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (valid) {
|
||||
if (world.getBlockState(bottomCorner).isOf(BlockRegistry.FLAVOLITE_RUNED)) {
|
||||
generatePortalFrame(world, bottomCorner, axis, true);
|
||||
} else {
|
||||
generateEternalPortalFrame(world, bottomCorner, axis, true);
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "betterend:item/crystal_shards"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue