diff --git a/src/main/java/ru/betterend/blocks/EndPortalBlock.java b/src/main/java/ru/betterend/blocks/EndPortalBlock.java index 60532d69..ff4ab7d6 100644 --- a/src/main/java/ru/betterend/blocks/EndPortalBlock.java +++ b/src/main/java/ru/betterend/blocks/EndPortalBlock.java @@ -87,6 +87,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable MinecraftServer server = ((ServerWorld) world).getServer(); ServerWorld destination = isOverworld ? server.getWorld(World.END) : EndPortals.getWorld(server, state.get(PORTAL)); BlockPos exitPos = this.findExitPos(destination, pos, entity); + System.out.println(exitPos); if (exitPos == null) return; if (entity instanceof ServerPlayerEntity) { ServerPlayerEntity player = (ServerPlayerEntity) entity; @@ -124,7 +125,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable Registry registry = world.getRegistryManager().getDimensionTypes(); double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale(); BlockPos.Mutable basePos; - if (world.getRegistryKey().equals(World.OVERWORLD)) { + if (!world.getRegistryKey().equals(World.END)) { basePos = pos.mutableCopy().set(pos.getX() / mult, pos.getY(), pos.getZ() / mult); } else { basePos = pos.mutableCopy().set(pos.getX() * mult, pos.getY(), pos.getZ() * mult); diff --git a/src/main/java/ru/betterend/blocks/EternalPedestal.java b/src/main/java/ru/betterend/blocks/EternalPedestal.java index 8a5ff3cb..e1a7911e 100644 --- a/src/main/java/ru/betterend/blocks/EternalPedestal.java +++ b/src/main/java/ru/betterend/blocks/EternalPedestal.java @@ -9,13 +9,16 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.loot.context.LootContext; import net.minecraft.loot.context.LootContextParameters; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; @@ -23,7 +26,7 @@ import net.minecraft.world.explosion.Explosion; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.entities.EternalPedestalEntity; import ru.betterend.registry.EndBlocks; -import ru.betterend.registry.EndItems; +import ru.betterend.registry.EndPortals; import ru.betterend.rituals.EternalRitual; public class EternalPedestal extends PedestalBlock { @@ -43,12 +46,15 @@ public class EternalPedestal extends PedestalBlock { if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) { if (pedestal.hasRitual()) { EternalRitual ritual = pedestal.getRitual(); - ritual.removePortal(); + Item item = pedestal.getStack(0).getItem(); + int dim = EndPortals.getPortalState(Registry.ITEM.getId(item)); + ritual.removePortal(dim); } world.setBlockState(pos, updatedState.with(ACTIVATED, false)); } else { ItemStack itemStack = pedestal.getStack(0); - if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) { + Identifier id = Registry.ITEM.getId(itemStack.getItem()); + if (EndPortals.isAvailableItem(id)) { world.setBlockState(pos, updatedState.with(ACTIVATED, true)); if (pedestal.hasRitual()) { pedestal.getRitual().checkStructure(); diff --git a/src/main/java/ru/betterend/registry/EndPortals.java b/src/main/java/ru/betterend/registry/EndPortals.java index 0c5e4733..2ff462af 100644 --- a/src/main/java/ru/betterend/registry/EndPortals.java +++ b/src/main/java/ru/betterend/registry/EndPortals.java @@ -65,6 +65,15 @@ public class EndPortals { return portals[state].color; } + public static boolean isAvailableItem(Identifier item) { + for (int i = 0; i < portals.length; i++) { + if (portals[i].item.equals(item)) { + return true; + } + } + return false; + } + private static JsonObject makeDefault(File file) { JsonObject jsonObject = new JsonObject(); JsonFactory.storeJson(file, jsonObject); @@ -119,6 +128,7 @@ public class EndPortals { JsonObject toJson() { JsonObject obj = new JsonObject(); obj.addProperty("dimension", dimension.toString()); + obj.addProperty("item", item.toString()); obj.addProperty("colorRed", (color >> 16) & 255); obj.addProperty("colorGreen", (color >> 8) & 255); obj.addProperty("colorBlue", color & 255); diff --git a/src/main/java/ru/betterend/rituals/EternalRitual.java b/src/main/java/ru/betterend/rituals/EternalRitual.java index e633adea..3d203fc3 100644 --- a/src/main/java/ru/betterend/rituals/EternalRitual.java +++ b/src/main/java/ru/betterend/rituals/EternalRitual.java @@ -10,6 +10,7 @@ import com.google.common.collect.Sets; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Material; +import net.minecraft.item.Item; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtHelper; import net.minecraft.particle.BlockStateParticleEffect; @@ -23,7 +24,6 @@ import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.Heightmap; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -35,6 +35,7 @@ import ru.betterend.blocks.RunedFlavolite; import ru.betterend.blocks.entities.EternalPedestalEntity; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; +import ru.betterend.registry.EndPortals; public class EternalRitual { private final static Set STRUCTURE_MAP = Sets.newHashSet( @@ -97,13 +98,24 @@ public class EternalRitual { moveY = Direction.EAST; } boolean valid = this.checkFrame(); + Item item = null; for (Point pos : STRUCTURE_MAP) { BlockPos.Mutable checkPos = center.mutableCopy(); checkPos.move(moveX, pos.x).move(moveY, pos.y); valid &= this.isActive(checkPos); + if (valid) { + EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(checkPos); + Item pItem = pedestal.getStack(0).getItem(); + if (item == null) { + item = pItem; + } + else if (!item.equals(pItem)) { + valid = false; + } + } } - if (valid) { - this.activatePortal(); + if (valid && item != null) { + this.activatePortal(item); } } @@ -126,20 +138,21 @@ public class EternalRitual { return this.active; } - private void activatePortal() { + private void activatePortal(Item item) { if (active) return; - this.activatePortal(world, center); + int state = EndPortals.getPortalState(Registry.ITEM.getId(item)); + this.activatePortal(world, center, state); this.doEffects((ServerWorld) world, center); if (exit == null) { - this.exit = this.findPortalPos(); + this.exit = this.findPortalPos(state); } else { - World targetWorld = this.getTargetWorld(); + World targetWorld = this.getTargetWorld(state); if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) { - this.exit = this.findPortalPos(); + this.exit = this.findPortalPos(state); } else { - this.activatePortal(targetWorld, exit); + this.activatePortal(targetWorld, exit, state); } } this.active = true; @@ -164,7 +177,7 @@ public class EternalRitual { serverWorld.playSound(null, center, SoundEvents.BLOCK_END_PORTAL_SPAWN, SoundCategory.NEUTRAL, 16, 1); } - private void activatePortal(World world, BlockPos center) { + private void activatePortal(World world, BlockPos center, int dim) { BlockPos framePos = center.down(); Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST; BlockState frame = FRAME.getDefaultState().with(ACTIVE, true); @@ -181,7 +194,7 @@ public class EternalRitual { } }); Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X; - BlockState portal = PORTAL.getDefaultState().with(EndPortalBlock.AXIS, portalAxis); + BlockState portal = PORTAL.getDefaultState().with(EndPortalBlock.AXIS, portalAxis).with(EndPortalBlock.PORTAL, dim); ParticleEffect effect = new BlockStateParticleEffect(ParticleTypes.BLOCK, portal); ServerWorld serverWorld = (ServerWorld) world; @@ -201,9 +214,9 @@ public class EternalRitual { }); } - public void removePortal() { + public void removePortal(int state) { if (!active || isInvalid()) return; - World targetWorld = this.getTargetWorld(); + World targetWorld = this.getTargetWorld(state); this.removePortal(world, center); this.removePortal(targetWorld, exit); } @@ -236,10 +249,10 @@ public class EternalRitual { this.active = false; } - private BlockPos findPortalPos() { + private BlockPos findPortalPos(int state) { MinecraftServer server = world.getServer(); assert server != null; - ServerWorld targetWorld = (ServerWorld) this.getTargetWorld(); + ServerWorld targetWorld = (ServerWorld) this.getTargetWorld(state); Registry registry = server.getRegistryManager().getDimensionTypes(); double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale(); BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult); @@ -281,9 +294,11 @@ public class EternalRitual { return basePos.toImmutable(); } - private World getTargetWorld() { - RegistryKey target = world.getRegistryKey() == World.END ? World.OVERWORLD : World.END; - return Objects.requireNonNull(world.getServer()).getWorld(target); + private World getTargetWorld(int state) { + if (world.getRegistryKey() == World.END) { + return EndPortals.getWorld(world.getServer(), state); + } + return Objects.requireNonNull(world.getServer()).getWorld(World.END); } private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) {