Skip to content

Commit

Permalink
fix portal
Browse files Browse the repository at this point in the history
  • Loading branch information
gemsb committed Aug 21, 2024
1 parent 0aaf611 commit 31d9ed2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, Worl

BlockPos portalFramePos = PortalFrame.getFramePos(state.get(FACING),pos, world);
if (portalFramePos != null){
PortalFrame.genFrame(portalFramePos,world);

if ( state.get(FACING) == Direction.SOUTH || state.get(FACING) == Direction.NORTH )
PortalFrame.genPortalX(portalFramePos.up(3),world, 0);
if ( state.get(FACING) == Direction.WEST || state.get(FACING) == Direction.EAST )
PortalFrame.genPortalZ(portalFramePos.up(3),world, 0);
boolean fullFrame = PortalFrame.genFrame(portalFramePos,world);

if (fullFrame) {
if (state.get(FACING) == Direction.SOUTH || state.get(FACING) == Direction.NORTH)
PortalFrame.genPortalX(portalFramePos.up(3), world, 0);
if (state.get(FACING) == Direction.WEST || state.get(FACING) == Direction.EAST)
PortalFrame.genPortalZ(portalFramePos.up(3), world, 0);
}
}


Expand Down
76 changes: 70 additions & 6 deletions src/main/java/net/ugi/sculk_depths/portal/PortalFrame.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package net.ugi.sculk_depths.portal;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.ugi.sculk_depths.block.ModBlocks;
import net.ugi.sculk_depths.state.property.ModProperties;

import static net.minecraft.block.DoorBlock.HALF;
import static net.ugi.sculk_depths.block.custom.SculkDepthsPortalBlock.AXIS;

public class PortalFrame {
Expand Down Expand Up @@ -75,17 +72,84 @@ private static BlockPos getNextFrameBlockPos(BlockPos pos, World world){
return null;
}

public static void genFrame(BlockPos pos, World world){
private static Boolean chekcfullFrame(BlockPos pos1,BlockPos pos2, World world){
int countActivatedAmalgamite = 0;

if (pos1 != null) {

if (world.getBlockState(pos1.north()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos1.south()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos1.east()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos1.west()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos1.up()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos1.down()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}

if (countActivatedAmalgamite >= 2)
return true;
return false;
}

if (pos1 != null) {

if (world.getBlockState(pos2.north()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos2.south()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos2.east()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos2.west()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos2.up()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}
if (world.getBlockState(pos2.down()).getBlock() == ModBlocks.ACTIVATED_AMALGAMITE) {
countActivatedAmalgamite++;
}

if (countActivatedAmalgamite >= 2)
return true;
return false;
}
return false;
}

public static boolean genFrame(BlockPos pos, World world){
BlockPos nextPos1 = pos;
BlockPos nextPos2 = pos;

world.setBlockState(pos,ModBlocks.ACTIVATED_AMALGAMITE.getDefaultState());

while (nextPos1 != null && nextPos2 != null){
world.setBlockState(nextPos1,ModBlocks.ACTIVATED_AMALGAMITE.getDefaultState());

nextPos1 = getNextFrameBlockPos(nextPos1,world);
if (nextPos1 != null){
world.setBlockState(nextPos1,ModBlocks.ACTIVATED_AMALGAMITE.getDefaultState());
break;
}

world.setBlockState(nextPos2,ModBlocks.ACTIVATED_AMALGAMITE.getDefaultState());
nextPos2 = getNextFrameBlockPos(nextPos2,world);
if (nextPos2 != null){
world.setBlockState(nextPos2,ModBlocks.ACTIVATED_AMALGAMITE.getDefaultState());
break;
}
}
return chekcfullFrame(nextPos1, nextPos2, world);
}

public static void genPortalX(BlockPos pos, World world, int depth){
Expand Down

0 comments on commit 31d9ed2

Please sign in to comment.