Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Nov 4, 2022
1 parent ca8c487 commit ca44363
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/volmit/wormholes/Content.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.volmit.wormholes;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/volmit/wormholes/ItemWand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.sound.SoundEvent;

import java.util.HashSet;
import java.util.Set;

public class ItemWand extends Item {
public ItemWand(Properties properties) {
super(properties.stacksTo(1).fireResistant()
Expand Down Expand Up @@ -97,6 +100,19 @@ public String getDimension(ItemStack stack) {
}

public Direction computeDirection(BlockPos point, BlockPos toward, Cuboid cc) {
Set<Direction> allowed = new HashSet<>();

if(cc.getSizeY() == 1) {
allowed.add(Direction.UP);
allowed.add(Direction.DOWN);
} else if(cc.getSizeX() == 1) {
allowed.add(Direction.EAST);
allowed.add(Direction.WEST);
} else if(cc.getSizeZ() == 1) {
allowed.add(Direction.NORTH);
allowed.add(Direction.SOUTH);
}

BlockPos vec = toward.subtract(point);
double x = vec.getX();
double y = vec.getY();
Expand All @@ -111,7 +127,7 @@ public Direction computeDirection(BlockPos point, BlockPos toward, Cuboid cc) {
double m = Double.MAX_VALUE;
Direction d = Direction.NORTH;

for (Direction i : Direction.values()) {
for (Direction i : allowed) {
double dx = v.distanceTo(new Vec3(i.getStepX(), i.getStepY(), i.getStepZ()));

if (dx < m) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/volmit/wormholes/PortalUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.volmit.wormholes;

import com.mojang.math.Quaternion;
import net.minecraft.client.particle.AshParticle;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
Expand Down Expand Up @@ -31,6 +32,7 @@ public static boolean linkPortals(Player player, ServerLevel level, Direction di
Set<BlockPos> positions2 = new HashSet<>();
ServerLevel l1 = level.getServer().getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dim1)));
ServerLevel l2 = level.getServer().getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dim2)));

for (BlockPos i : c1.getBlockPositions()) {
if (l1.getBlockState(i).getBlock().equals(Content.Blocks.FRAME.get())) {
positions1.add(i);
Expand Down Expand Up @@ -69,10 +71,10 @@ public static boolean linkPortals(Player player, ServerLevel level, Direction di

PortalExtension.get(portal).bindCluster = true;
PortalExtension.get(portal2).bindCluster = true;
McHelper.spawnServerEntity(portal);
McHelper.spawnServerEntity(portal2);
McHelper.spawnServerEntity(PortalManipulation.createFlippedPortal(portal, (EntityType<Portal>) portal.getType()));
McHelper.spawnServerEntity(PortalManipulation.createFlippedPortal(portal2, (EntityType<Portal>) portal2.getType()));
McHelper.spawnServerEntity(configure(portal));
McHelper.spawnServerEntity(configure(portal2));
McHelper.spawnServerEntity(configure(PortalManipulation.createFlippedPortal(portal, (EntityType<Portal>) portal.getType())));
McHelper.spawnServerEntity(configure(PortalManipulation.createFlippedPortal(portal2, (EntityType<Portal>) portal2.getType())));

for (BlockPos i : positions1) {
if (l1.getBlockState(i).getBlock().equals(Content.Blocks.FRAME.get())) {
Expand All @@ -91,6 +93,11 @@ public static boolean linkPortals(Player player, ServerLevel level, Direction di
return true;
}

private static Portal configure(Portal p)
{
return p;
}

private static DQuaternion getQuaternion(Vec3 angle1, Vec3 angle2, boolean flip) {
if(flip) {
return DQuaternion.identity; // DQuaternion.rotationByDegrees(angle1, 180);
Expand Down

0 comments on commit ca44363

Please sign in to comment.