Targeted portals (WIP, bugged)
This commit is contained in:
parent
3446848287
commit
83fd4603ac
8 changed files with 102 additions and 92 deletions
|
@ -1,8 +1,5 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
@ -21,6 +18,7 @@ import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.IntProperty;
|
import net.minecraft.state.property.IntProperty;
|
||||||
import net.minecraft.util.BlockRotation;
|
import net.minecraft.util.BlockRotation;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Direction.Axis;
|
import net.minecraft.util.math.Direction.Axis;
|
||||||
|
@ -38,6 +36,9 @@ import ru.betterend.interfaces.TeleportingEntity;
|
||||||
import ru.betterend.registry.EndParticles;
|
import ru.betterend.registry.EndParticles;
|
||||||
import ru.betterend.registry.EndPortals;
|
import ru.betterend.registry.EndPortals;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable, IColorProvider {
|
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable, IColorProvider {
|
||||||
public static final IntProperty PORTAL = BlockProperties.PORTAL;
|
public static final IntProperty PORTAL = BlockProperties.PORTAL;
|
||||||
|
|
||||||
|
@ -83,11 +84,12 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||||
if (world instanceof ServerWorld && !entity.hasVehicle() && !entity.hasPassengers() && entity.canUsePortals()) {
|
if (world instanceof ServerWorld && !entity.hasVehicle() && !entity.hasPassengers() && entity.canUsePortals()) {
|
||||||
if (entity.hasNetherPortalCooldown()) return;
|
if (entity.hasNetherPortalCooldown()) return;
|
||||||
boolean isOverworld = world.getRegistryKey().equals(World.OVERWORLD);
|
ServerWorld currentWorld = (ServerWorld) world;
|
||||||
MinecraftServer server = ((ServerWorld) world).getServer();
|
MinecraftServer server = currentWorld.getServer();
|
||||||
ServerWorld destination = isOverworld ? server.getWorld(World.END) : EndPortals.getWorld(server, state.get(PORTAL));
|
ServerWorld targetWorld = EndPortals.getWorld(server, state.get(PORTAL));
|
||||||
BlockPos exitPos = this.findExitPos(destination, pos, entity);
|
boolean isTarget = world.getRegistryKey().equals(targetWorld.getRegistryKey());
|
||||||
System.out.println(exitPos);
|
ServerWorld destination = isTarget ? server.getWorld(World.END) : targetWorld;
|
||||||
|
BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity);
|
||||||
if (exitPos == null) return;
|
if (exitPos == null) return;
|
||||||
if (entity instanceof ServerPlayerEntity) {
|
if (entity instanceof ServerPlayerEntity) {
|
||||||
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
||||||
|
@ -119,31 +121,33 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
return ERenderLayer.TRANSLUCENT;
|
return ERenderLayer.TRANSLUCENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos findExitPos(ServerWorld world, BlockPos pos, Entity entity) {
|
private BlockPos findExitPos(ServerWorld current, ServerWorld target, BlockPos pos, Entity entity) {
|
||||||
if (world == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
Registry<DimensionType> registry = world.getRegistryManager().getDimensionTypes();
|
Registry<DimensionType> registry = target.getRegistryManager().getDimensionTypes();
|
||||||
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
Identifier targetWorldId = target.getRegistryKey().getValue();
|
||||||
BlockPos.Mutable basePos;
|
Identifier currentWorldId = current.getRegistryKey().getValue();
|
||||||
if (!world.getRegistryKey().equals(World.END)) {
|
double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale();
|
||||||
basePos = pos.mutableCopy().set(pos.getX() / mult, pos.getY(), pos.getZ() / mult);
|
double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).getCoordinateScale();
|
||||||
} else {
|
double multiplier = targetMultiplier > currentMultiplier ? currentMultiplier / targetMultiplier : currentMultiplier;
|
||||||
basePos = pos.mutableCopy().set(pos.getX() * mult, pos.getY(), pos.getZ() * mult);
|
BlockPos.Mutable basePos = pos.mutableCopy().set(pos.getX() * multiplier, pos.getY(), pos.getZ() * multiplier);
|
||||||
}
|
System.out.println(basePos);
|
||||||
Direction direction = Direction.EAST;
|
Direction direction = Direction.EAST;
|
||||||
BlockPos.Mutable checkPos = basePos.mutableCopy();
|
BlockPos.Mutable checkPos = basePos.mutableCopy();
|
||||||
for (int step = 1; step < 128; step++) {
|
for (int step = 1; step < 128; step++) {
|
||||||
for (int i = 0; i < (step >> 1); i++) {
|
for (int i = 0; i < (step >> 1); i++) {
|
||||||
Chunk chunk = world.getChunk(checkPos);
|
Chunk chunk = target.getChunk(checkPos);
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
int ceil = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15);
|
int surfaceY = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15);
|
||||||
|
int motionY = chunk.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, checkPos.getX() & 15, checkPos.getZ() & 15);
|
||||||
|
int ceil = Math.max(surfaceY, motionY) + 1;
|
||||||
if (ceil > 5) {
|
if (ceil > 5) {
|
||||||
checkPos.setY(ceil);
|
checkPos.setY(ceil);
|
||||||
while (checkPos.getY() > 5) {
|
while (checkPos.getY() > 5) {
|
||||||
BlockState state = world.getBlockState(checkPos);
|
BlockState state = target.getBlockState(checkPos);
|
||||||
if (state.isOf(this)) {
|
if (state.isOf(this)) {
|
||||||
Axis axis = state.get(AXIS);
|
Axis axis = state.get(AXIS);
|
||||||
checkPos = this.findCenter(world, checkPos, axis);
|
checkPos = findCenter(target, checkPos, axis);
|
||||||
|
|
||||||
Direction frontDir = Direction.from(axis, AxisDirection.POSITIVE).rotateYClockwise();
|
Direction frontDir = Direction.from(axis, AxisDirection.POSITIVE).rotateYClockwise();
|
||||||
Direction entityDir = entity.getMovementDirection();
|
Direction entityDir = entity.getMovementDirection();
|
||||||
|
@ -195,15 +199,11 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockColorProvider getProvider() {
|
public BlockColorProvider getProvider() {
|
||||||
return (state, world, pos, tintIndex) -> {
|
return (state, world, pos, tintIndex) -> EndPortals.getColor(state.get(PORTAL));
|
||||||
return EndPortals.getColor(state.get(PORTAL));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemColorProvider getItemProvider() {
|
public ItemColorProvider getItemProvider() {
|
||||||
return (stack, tintIndex) -> {
|
return (stack, tintIndex) -> EndPortals.getColor(0);
|
||||||
return EndPortals.getColor(0);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class EternalPedestal extends PedestalBlock {
|
||||||
|
|
||||||
public EternalPedestal() {
|
public EternalPedestal() {
|
||||||
super(EndBlocks.FLAVOLITE_RUNED_ETERNAL);
|
super(EndBlocks.FLAVOLITE_RUNED_ETERNAL);
|
||||||
this.setDefaultState(this.getDefaultState().with(ACTIVATED, false));
|
this.setDefaultState(getDefaultState().with(ACTIVATED, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,12 +50,12 @@ public class EternalPedestal extends PedestalBlock {
|
||||||
int dim = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
int dim = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
||||||
ritual.removePortal(dim);
|
ritual.removePortal(dim);
|
||||||
}
|
}
|
||||||
world.setBlockState(pos, updatedState.with(ACTIVATED, false));
|
world.setBlockState(pos, updatedState.with(ACTIVATED, false).with(HAS_LIGHT, false));
|
||||||
} else {
|
} else {
|
||||||
ItemStack itemStack = pedestal.getStack(0);
|
ItemStack itemStack = pedestal.getStack(0);
|
||||||
Identifier id = Registry.ITEM.getId(itemStack.getItem());
|
Identifier id = Registry.ITEM.getId(itemStack.getItem());
|
||||||
if (EndPortals.isAvailableItem(id)) {
|
if (EndPortals.isAvailableItem(id)) {
|
||||||
world.setBlockState(pos, updatedState.with(ACTIVATED, true));
|
world.setBlockState(pos, updatedState.with(ACTIVATED, true).with(HAS_LIGHT, true));
|
||||||
if (pedestal.hasRitual()) {
|
if (pedestal.hasRitual()) {
|
||||||
pedestal.getRitual().checkStructure();
|
pedestal.getRitual().checkStructure();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -86,9 +86,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
|
||||||
protected float height = 1.0F;
|
protected float height = 1.0F;
|
||||||
|
|
||||||
public PedestalBlock(Block parent) {
|
public PedestalBlock(Block parent) {
|
||||||
super(FabricBlockSettings.copyOf(parent).luminance(state -> {
|
super(FabricBlockSettings.copyOf(parent).luminance(state -> state.get(HAS_LIGHT) ? 12 : 0));
|
||||||
return state.get(HAS_LIGHT) ? 12 : 0;
|
|
||||||
}));
|
|
||||||
this.setDefaultState(stateManager.getDefaultState().with(STATE, PedestalState.DEFAULT).with(HAS_ITEM, false).with(HAS_LIGHT, false));
|
this.setDefaultState(stateManager.getDefaultState().with(STATE, PedestalState.DEFAULT).with(HAS_ITEM, false).with(HAS_LIGHT, false));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
@ -119,6 +117,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid
|
||||||
ItemStack itemStack = pedestal.getStack(0);
|
ItemStack itemStack = pedestal.getStack(0);
|
||||||
if (player.giveItemStack(itemStack)) {
|
if (player.giveItemStack(itemStack)) {
|
||||||
pedestal.removeStack(0);
|
pedestal.removeStack(0);
|
||||||
|
checkRitual(world, pos);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class EternalPedestalEntity extends PedestalBlockEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRitual() {
|
public boolean hasRitual() {
|
||||||
return this.linkedRitual != null;
|
return linkedRitual != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void linkRitual(EternalRitual ritual) {
|
public void linkRitual(EternalRitual ritual) {
|
||||||
|
@ -23,14 +23,14 @@ public class EternalPedestalEntity extends PedestalBlockEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EternalRitual getRitual() {
|
public EternalRitual getRitual() {
|
||||||
return this.linkedRitual;
|
return linkedRitual;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLocation(World world, BlockPos pos) {
|
public void setLocation(World world, BlockPos pos) {
|
||||||
super.setLocation(world, pos);
|
super.setLocation(world, pos);
|
||||||
if (hasRitual()) {
|
if (hasRitual()) {
|
||||||
this.linkedRitual.setWorld(world);
|
linkedRitual.setWorld(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,14 +38,14 @@ public class EternalPedestalEntity extends PedestalBlockEntity {
|
||||||
public void fromTag(BlockState state, CompoundTag tag) {
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
super.fromTag(state, tag);
|
super.fromTag(state, tag);
|
||||||
if (tag.contains("ritual")) {
|
if (tag.contains("ritual")) {
|
||||||
this.linkedRitual = new EternalRitual(world);
|
linkedRitual = new EternalRitual(world);
|
||||||
this.linkedRitual.fromTag(tag.getCompound("ritual"));
|
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag toTag(CompoundTag tag) {
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
if (this.hasRitual()) {
|
if (hasRitual()) {
|
||||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||||
}
|
}
|
||||||
return super.toTag(tag);
|
return super.toTag(tag);
|
||||||
|
|
|
@ -19,26 +19,26 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||||
public void setLocation(World world, BlockPos pos) {
|
public void setLocation(World world, BlockPos pos) {
|
||||||
super.setLocation(world, pos);
|
super.setLocation(world, pos);
|
||||||
if (hasRitual()) {
|
if (hasRitual()) {
|
||||||
this.linkedRitual.setLocation(world, pos);
|
linkedRitual.setLocation(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void linkRitual(InfusionRitual ritual) {
|
public void linkRitual(InfusionRitual ritual) {
|
||||||
this.linkedRitual = ritual;
|
linkedRitual = ritual;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfusionRitual getRitual() {
|
public InfusionRitual getRitual() {
|
||||||
return this.linkedRitual;
|
return linkedRitual;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRitual() {
|
public boolean hasRitual() {
|
||||||
return this.linkedRitual != null;
|
return linkedRitual != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (hasRitual()) {
|
if (hasRitual()) {
|
||||||
this.linkedRitual.tick();
|
linkedRitual.tick();
|
||||||
}
|
}
|
||||||
super.tick();
|
super.tick();
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||||
public void fromTag(BlockState state, CompoundTag tag) {
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
super.fromTag(state, tag);
|
super.fromTag(state, tag);
|
||||||
if (tag.contains("ritual")) {
|
if (tag.contains("ritual")) {
|
||||||
this.linkedRitual = new InfusionRitual(world, pos);
|
linkedRitual = new InfusionRitual(world, pos);
|
||||||
this.linkedRitual.fromTag(tag.getCompound("ritual"));
|
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package ru.betterend.registry;
|
package ru.betterend.registry;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.ibm.icu.impl.UResource;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
@ -14,6 +11,8 @@ import ru.betterend.config.ConfigWriter;
|
||||||
import ru.betterend.util.JsonFactory;
|
import ru.betterend.util.JsonFactory;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class EndPortals {
|
public class EndPortals {
|
||||||
private static PortalInfo[] portals;
|
private static PortalInfo[] portals;
|
||||||
|
|
||||||
|
@ -23,8 +22,7 @@ public class EndPortals {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
json = makeDefault(file);
|
json = makeDefault(file);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
json = JsonFactory.getJsonObject(file);
|
json = JsonFactory.getJsonObject(file);
|
||||||
}
|
}
|
||||||
if (!json.has("portals") || !json.get("portals").isJsonArray()) {
|
if (!json.has("portals") || !json.get("portals").isJsonArray()) {
|
||||||
|
@ -66,8 +64,8 @@ public class EndPortals {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAvailableItem(Identifier item) {
|
public static boolean isAvailableItem(Identifier item) {
|
||||||
for (int i = 0; i < portals.length; i++) {
|
for (PortalInfo portal : portals) {
|
||||||
if (portals[i].item.equals(item)) {
|
if (portal.item.equals(item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,9 +112,7 @@ public class EndPortals {
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
Iterator<ServerWorld> iterator = server.getWorlds().iterator();
|
for (ServerWorld world : server.getWorlds()) {
|
||||||
while (iterator.hasNext()) {
|
|
||||||
ServerWorld world = iterator.next();
|
|
||||||
if (world.getRegistryKey().getValue().equals(dimension)) {
|
if (world.getRegistryKey().getValue().equals(dimension)) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
return world;
|
return world;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
@ -97,25 +98,26 @@ public class EternalRitual {
|
||||||
moveX = Direction.SOUTH;
|
moveX = Direction.SOUTH;
|
||||||
moveY = Direction.EAST;
|
moveY = Direction.EAST;
|
||||||
}
|
}
|
||||||
boolean valid = this.checkFrame();
|
boolean valid = checkFrame();
|
||||||
Item item = null;
|
Item item = null;
|
||||||
for (Point pos : STRUCTURE_MAP) {
|
for (Point pos : STRUCTURE_MAP) {
|
||||||
BlockPos.Mutable checkPos = center.mutableCopy();
|
BlockPos.Mutable checkPos = center.mutableCopy();
|
||||||
checkPos.move(moveX, pos.x).move(moveY, pos.y);
|
checkPos.move(moveX, pos.x).move(moveY, pos.y);
|
||||||
valid &= this.isActive(checkPos);
|
valid &= isActive(checkPos);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(checkPos);
|
EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(checkPos);
|
||||||
|
if (pedestal != null) {
|
||||||
Item pItem = pedestal.getStack(0).getItem();
|
Item pItem = pedestal.getStack(0).getItem();
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
item = pItem;
|
item = pItem;
|
||||||
}
|
} else if (!item.equals(pItem)) {
|
||||||
else if (!item.equals(pItem)) {
|
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (valid && item != null) {
|
if (valid && item != null) {
|
||||||
this.activatePortal(item);
|
activatePortal(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,18 +143,17 @@ public class EternalRitual {
|
||||||
private void activatePortal(Item item) {
|
private void activatePortal(Item item) {
|
||||||
if (active) return;
|
if (active) return;
|
||||||
int state = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
int state = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
||||||
this.activatePortal(world, center, state);
|
System.out.println(state);
|
||||||
this.doEffects((ServerWorld) world, center);
|
activatePortal(world, center, state);
|
||||||
|
doEffects((ServerWorld) world, center);
|
||||||
if (exit == null) {
|
if (exit == null) {
|
||||||
this.exit = this.findPortalPos(state);
|
this.exit = findPortalPos(state);
|
||||||
}
|
} else {
|
||||||
else {
|
World targetWorld = getTargetWorld(state);
|
||||||
World targetWorld = this.getTargetWorld(state);
|
|
||||||
if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) {
|
if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) {
|
||||||
this.exit = this.findPortalPos(state);
|
this.exit = findPortalPos(state);
|
||||||
}
|
} else {
|
||||||
else {
|
activatePortal(targetWorld, exit, state);
|
||||||
this.activatePortal(targetWorld, exit, state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.active = true;
|
this.active = true;
|
||||||
|
@ -216,9 +217,8 @@ public class EternalRitual {
|
||||||
|
|
||||||
public void removePortal(int state) {
|
public void removePortal(int state) {
|
||||||
if (!active || isInvalid()) return;
|
if (!active || isInvalid()) return;
|
||||||
World targetWorld = this.getTargetWorld(state);
|
removePortal(getTargetWorld(state), exit);
|
||||||
this.removePortal(world, center);
|
removePortal(world, center);
|
||||||
this.removePortal(targetWorld, exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePortal(World world, BlockPos center) {
|
private void removePortal(World world, BlockPos center) {
|
||||||
|
@ -252,10 +252,11 @@ public class EternalRitual {
|
||||||
private BlockPos findPortalPos(int state) {
|
private BlockPos findPortalPos(int state) {
|
||||||
MinecraftServer server = world.getServer();
|
MinecraftServer server = world.getServer();
|
||||||
assert server != null;
|
assert server != null;
|
||||||
ServerWorld targetWorld = (ServerWorld) this.getTargetWorld(state);
|
ServerWorld targetWorld = (ServerWorld) getTargetWorld(state);
|
||||||
|
Identifier targetWorldId = targetWorld.getRegistryKey().getValue();
|
||||||
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
|
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
|
||||||
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
double multiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale();
|
||||||
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult);
|
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / multiplier, center.getY(), center.getZ() / multiplier);
|
||||||
Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
|
Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
|
||||||
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
|
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
|
||||||
EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
|
EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
|
||||||
|
@ -465,9 +466,15 @@ public class EternalRitual {
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
if (state.isOf(PEDESTAL)) {
|
if (state.isOf(PEDESTAL)) {
|
||||||
EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(pos);
|
EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(pos);
|
||||||
assert pedestal != null;
|
if (pedestal != null) {
|
||||||
if (!pedestal.hasRitual()) {
|
if (!pedestal.hasRitual()) {
|
||||||
pedestal.linkRitual(this);
|
pedestal.linkRitual(this);
|
||||||
|
} else {
|
||||||
|
EternalRitual ritual = pedestal.getRitual();
|
||||||
|
if (!ritual.equals(this)) {
|
||||||
|
pedestal.linkRitual(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return state.get(ACTIVE);
|
return state.get(ACTIVE);
|
||||||
}
|
}
|
||||||
|
@ -492,4 +499,14 @@ public class EternalRitual {
|
||||||
this.exit = NbtHelper.toBlockPos(tag.getCompound("exit"));
|
this.exit = NbtHelper.toBlockPos(tag.getCompound("exit"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
EternalRitual ritual = (EternalRitual) o;
|
||||||
|
return world.equals(ritual.world) &&
|
||||||
|
Objects.equals(center, ritual.center) &&
|
||||||
|
Objects.equals(exit, ritual.exit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package ru.betterend.rituals;
|
package ru.betterend.rituals;
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
|
@ -17,6 +14,8 @@ import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||||
import ru.betterend.particle.InfusionParticleType;
|
import ru.betterend.particle.InfusionParticleType;
|
||||||
import ru.betterend.recipe.builders.InfusionRecipe;
|
import ru.betterend.recipe.builders.InfusionRecipe;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class InfusionRitual implements Inventory {
|
public class InfusionRitual implements Inventory {
|
||||||
private static final Point[] PEDESTALS_MAP = new Point[] {
|
private static final Point[] PEDESTALS_MAP = new Point[] {
|
||||||
new Point(0, 3), new Point(2, 2), new Point(3, 0), new Point(2, -2),
|
new Point(0, 3), new Point(2, 2), new Point(3, 0), new Point(2, -2),
|
||||||
|
@ -32,7 +31,7 @@ public class InfusionRitual implements Inventory {
|
||||||
private int time = 0;
|
private int time = 0;
|
||||||
|
|
||||||
private InfusionPedestalEntity input;
|
private InfusionPedestalEntity input;
|
||||||
private PedestalBlockEntity[] catalysts = new PedestalBlockEntity[8];
|
private final PedestalBlockEntity[] catalysts = new PedestalBlockEntity[8];
|
||||||
|
|
||||||
public InfusionRitual(World world, BlockPos pos) {
|
public InfusionRitual(World world, BlockPos pos) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
@ -108,7 +107,6 @@ public class InfusionRitual implements Inventory {
|
||||||
if (!checkRecipe()) return;
|
if (!checkRecipe()) return;
|
||||||
progress++;
|
progress++;
|
||||||
if (progress == time) {
|
if (progress == time) {
|
||||||
BlockState inputState = world.getBlockState(input.getPos());
|
|
||||||
input.removeStack(0);
|
input.removeStack(0);
|
||||||
input.setStack(0, activeRecipe.craft(this));
|
input.setStack(0, activeRecipe.craft(this));
|
||||||
for (PedestalBlockEntity catalyst : catalysts) {
|
for (PedestalBlockEntity catalyst : catalysts) {
|
||||||
|
@ -198,7 +196,7 @@ public class InfusionRitual implements Inventory {
|
||||||
if (slot == 0) {
|
if (slot == 0) {
|
||||||
return input.removeStack(0);
|
return input.removeStack(0);
|
||||||
} else {
|
} else {
|
||||||
return catalysts[slot - 1].getStack(0);
|
return catalysts[slot - 1].removeStack(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue