finish update and fix immersive portals integration
This commit is contained in:
@@ -57,6 +57,7 @@ public class ColourfulPortalsMod implements ModInitializer {
|
||||
public static final ColourfulAirBottleItem COLOURFUL_AIR_BOTTLE_ITEM = new ColourfulAirBottleItem(COLOURFUL_AIR, new Item.Settings().rarity(Rarity.RARE).component(DataComponentTypes.BASE_COLOR, DyeColor.BLACK));
|
||||
|
||||
public static final EnumMap<DyeColor, SimpleParticleType> COLOURFUL_AIR_PARTICLE_BY_COLOUR;
|
||||
|
||||
static {
|
||||
COLOURFUL_AIR_PARTICLE_BY_COLOUR = new EnumMap<>(DyeColor.class);
|
||||
for (DyeColor dyeColor : DyeColor.values()) {
|
||||
@@ -104,14 +105,14 @@ public class ColourfulPortalsMod implements ModInitializer {
|
||||
ColourfulPortalConfig.registerListener(this::onConfigUpdate);
|
||||
|
||||
onConfigUpdate();
|
||||
if (!ColourfulPortalConfig.disableImmersivePortals && hasImmPtl()) {
|
||||
Registry.register(PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY, ImmersivePortalsLinkingSystem.IMMERSIVE_PORTALS_LINKING_SYSTEM, new PrioritizedPortalLinkingSystemBuilder(ImmersivePortalsLinkingSystem::new, 100));
|
||||
if (hasImmPtl()) {
|
||||
Registry.register(PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY, ImmersivePortalsLinkingSystem.IMMERSIVE_PORTALS_LINKING_SYSTEM, new PrioritizedPortalLinkingSystemBuilder(ImmersivePortalsLinkingSystem::new, () -> ColourfulPortalConfig.disableImmersivePortals ? -1 : 100));
|
||||
}
|
||||
for (Map.Entry<DyeColor, SimpleParticleType> entry : COLOURFUL_AIR_PARTICLE_BY_COLOUR.entrySet()) {
|
||||
Registry.register(Registries.PARTICLE_TYPE, Identifier.of(MOD_ID, entry.getKey().getName() + "_colourful_air_sparkle"), entry.getValue());
|
||||
}
|
||||
|
||||
Registry.register(PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY, DefaultLinkingSystem.DEFAULT_LINKING_SYSTEM, new PrioritizedPortalLinkingSystemBuilder(DefaultLinkingSystem::new, 90));
|
||||
Registry.register(PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY, DefaultLinkingSystem.DEFAULT_LINKING_SYSTEM, new PrioritizedPortalLinkingSystemBuilder(DefaultLinkingSystem::new, () -> 90));
|
||||
|
||||
Identifier identifier = Identifier.of(MOD_ID, "portal_block");
|
||||
|
||||
@@ -151,7 +152,7 @@ public class ColourfulPortalsMod implements ModInitializer {
|
||||
}
|
||||
DIMENSION_WEIGHTS_COLOURFUL_PEARL.clear();
|
||||
for (Map.Entry<String, Integer> weight : ColourfulPortalConfig.pearlDimensionWeights.entrySet()) {
|
||||
DIMENSION_WEIGHTS_COLOURFUL_PEARL.add(Identifier.of(weight.getKey()),weight.getValue());
|
||||
DIMENSION_WEIGHTS_COLOURFUL_PEARL.add(Identifier.of(weight.getKey()), weight.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ public class ColourfulPortalsMod implements ModInitializer {
|
||||
PortalListComponent portalList = PORTAL_LIST.get(minecraftServer.getSaveProperties().getMainWorldProperties());
|
||||
|
||||
PortalLinkingSystem currentLinkingSystem = getCurrentlyConfiguredLinkingSystem(minecraftServer);
|
||||
if (currentLinkingSystem.getLinkingSystemId() != portalList.lastPortalLinkingSystemId() || currentLinkingSystem.needsReInit()) {
|
||||
if (!Objects.equals(currentLinkingSystem.getLinkingSystemId(), portalList.lastPortalLinkingSystemId()) || currentLinkingSystem.needsReInit()) {
|
||||
PrioritizedPortalLinkingSystemBuilder prevSystem;
|
||||
if ((prevSystem = PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY.get(portalList.lastPortalLinkingSystemId())) != null) {
|
||||
PortalLinkingSystem prevLS = prevSystem.portalLinkingSystemBuilder().build(minecraftServer);
|
||||
@@ -191,7 +192,8 @@ public class ColourfulPortalsMod implements ModInitializer {
|
||||
private PortalLinkingSystem getCurrentlyConfiguredLinkingSystem(MinecraftServer minecraftServer) {
|
||||
return PORTAL_LINKING_SYSTEM_BUILDER_REGISTRY
|
||||
.stream()
|
||||
.min(Comparator.comparing(PrioritizedPortalLinkingSystemBuilder::priority))
|
||||
.filter(prio -> prio.priority().getAsInt() >= 0)
|
||||
.max(Comparator.comparing(prio -> prio.priority().getAsInt()))
|
||||
.map(PrioritizedPortalLinkingSystemBuilder::portalLinkingSystemBuilder)
|
||||
.orElse(DefaultLinkingSystem::new)
|
||||
.build(minecraftServer);
|
||||
|
||||
@@ -15,8 +15,8 @@ public class Components implements LevelComponentInitializer {
|
||||
|
||||
@Override
|
||||
public void registerLevelComponentFactories(LevelComponentFactoryRegistry registry) {
|
||||
registry.register(PORTAL_LIST, PortalListComponent::new);
|
||||
registry.register(PORTAL_CANDIDATE_LIST, PortalListComponent::new);
|
||||
registry.register(PORTAL_LIST, worldProperties1 -> new PortalListComponent());
|
||||
registry.register(PORTAL_CANDIDATE_LIST, worldProperties -> new PortalListComponent());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,12 +180,9 @@ public class CommonPortalFluidRendererV2 implements CommonPortalFluidRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.info("{} {} {}\n{} {} {}\n{} {} {}", amounts[0], amounts[1], amounts[2], amounts[3], amounts[4], amounts[5], amounts[6], amounts[7], amounts[8]);
|
||||
|
||||
for (int a = 0; a < 9; a++) {
|
||||
heights[a] = heights[a] / heightsC[a];
|
||||
}
|
||||
LOGGER.info("{} {} {}\n{} {} {}\n{} {} {}", heights[0], heights[1], heights[2], heights[3], heights[4], heights[5], heights[6], heights[7], heights[8]);
|
||||
for (int i = 0; i < quads.length / 3; i++) {
|
||||
int x = (int) ((quads[i * 3] + 0.5f) * 2);
|
||||
int z = (int) ((quads[i * 3 + 2] + 0.5f) * 2);
|
||||
|
||||
@@ -3,8 +3,6 @@ package quimufu.colourful_portals.item;
|
||||
import net.minecraft.advancement.criterion.Criteria;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -17,7 +15,6 @@ import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import quimufu.colourful_portals.ColourfulAirBlock;
|
||||
import quimufu.colourful_portals.ColourfulPortalsMod;
|
||||
import quimufu.colourful_portals.client.mixin.MinecraftClientAccessor;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
|
||||
|
||||
@Override
|
||||
public void linkPortals(LinkedList<PortalRepresentation> portalRepresentations) {
|
||||
LOGGER.info("start linkPortals");
|
||||
LOGGER.debug("start linkPortals");
|
||||
for (Node<PortalRepresentation> node = portalRepresentations.getNode(0); node != null; node = node.getNext()) {
|
||||
PortalRepresentation portalRepresentation = node.getValue();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
|
||||
portalsAtPosition.add(finalNode);
|
||||
});
|
||||
}
|
||||
LOGGER.info("end linkPortals");
|
||||
LOGGER.debug("end linkPortals");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,7 +72,6 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
|
||||
prevEntityPos = new Vec3d(entity.prevX, entity.prevY, entity.prevZ);
|
||||
}
|
||||
if (RaycastHelper.passedOnAxis(prevEntityPos, entity.getPos(), pos, axis)) {
|
||||
//LOGGER.info("passed on Axis!");
|
||||
if (onPortalPassed(entity, pos, world, axis)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import net.minecraft.util.TypeFilter;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
import qouteall.imm_ptl.core.api.PortalAPI;
|
||||
import qouteall.imm_ptl.core.portal.Portal;
|
||||
import qouteall.imm_ptl.core.portal.global_portals.GlobalPortalStorage;
|
||||
import qouteall.q_misc_util.my_util.DQuaternion;
|
||||
import quimufu.colourful_portals.general_util.LinkedList;
|
||||
|
||||
@@ -44,17 +46,17 @@ public class ImmersivePortalsLinkingSystem implements PortalLinkingSystem {
|
||||
BlockBox linkedToPortalBlockBox = linkedToPortalRepresentation.location();
|
||||
Box linkedToPortalBox = Box.from(linkedToPortalBlockBox);
|
||||
|
||||
List<qouteall.imm_ptl.core.portal.Portal> outgoingPortals = new ArrayList<>(getPortalList(fromPortalRepresentation));
|
||||
List<Portal> outgoingPortals = new ArrayList<>(getPortalList(fromPortalRepresentation));
|
||||
|
||||
if (outgoingPortals.size() > 2) {
|
||||
LOGGER.warn("Found more then 2 portals in {}, cleaning up", fromPortalBox);
|
||||
for (int i = 2; i < outgoingPortals.size(); i++) {
|
||||
qouteall.imm_ptl.core.portal.Portal outgoingPortal = outgoingPortals.get(i);
|
||||
outgoingPortal.kill();
|
||||
Portal outgoingPortal = outgoingPortals.get(i);
|
||||
PortalAPI.removeGlobalPortal(getPortalWorld(fromPortalRepresentation), outgoingPortal);
|
||||
}
|
||||
}
|
||||
if (outgoingPortals.isEmpty()) {
|
||||
qouteall.imm_ptl.core.portal.Portal portal = qouteall.imm_ptl.core.portal.Portal.ENTITY_TYPE.create(fromPortalWorld);
|
||||
Portal portal = Portal.ENTITY_TYPE.create(fromPortalWorld);
|
||||
if (portal == null) {
|
||||
LOGGER.error("could not create PortalRepresentation entity for {}", fromPortalRepresentation);
|
||||
return;
|
||||
@@ -72,25 +74,19 @@ public class ImmersivePortalsLinkingSystem implements PortalLinkingSystem {
|
||||
);
|
||||
portal.setRotationTransformation(DQuaternion.getRotationBetween(axisW, Vec3d.of(PortalHelper.getAxisW(linkedToPortalBlockBox).getVector())));
|
||||
outgoingPortals.add(portal);
|
||||
if (!fromPortalWorld.spawnEntity(portal)) {
|
||||
LOGGER.error("could not spawn PortalRepresentation entity for {}", fromPortalRepresentation);
|
||||
return;
|
||||
}
|
||||
PortalAPI.addGlobalPortal(fromPortalWorld, portal);
|
||||
}
|
||||
if (outgoingPortals.size() == 1) {
|
||||
qouteall.imm_ptl.core.portal.Portal portal = PortalAPI.createFlippedPortal(outgoingPortals.getFirst());
|
||||
Portal portal = PortalAPI.createFlippedPortal(outgoingPortals.getFirst());
|
||||
outgoingPortals.add(portal);
|
||||
if (!fromPortalWorld.spawnEntity(portal)) {
|
||||
LOGGER.error("could not spawn second PortalRepresentation entity for {}", fromPortalRepresentation);
|
||||
return;
|
||||
}
|
||||
PortalAPI.addGlobalPortal(fromPortalWorld, portal);
|
||||
}
|
||||
for (qouteall.imm_ptl.core.portal.Portal outgoingPortal : outgoingPortals) {
|
||||
for (Portal outgoingPortal : outgoingPortals) {
|
||||
outgoingPortal.setDestinationDimension(linkedToPortalWorldRegKey);
|
||||
outgoingPortal.setDestination(linkedToPortalBox.getCenter());
|
||||
Vec3d axisW = Vec3d.of(PortalHelper.getAxisW(fromPortalBlockBox).getVector());
|
||||
outgoingPortal.setRotationTransformation(DQuaternion.getRotationBetween(axisW, Vec3d.of(PortalHelper.getAxisW(linkedToPortalBlockBox).getVector())));
|
||||
outgoingPortal.reloadAndSyncToClient();
|
||||
GlobalPortalStorage.get(getPortalWorld(fromPortalRepresentation)).onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +102,7 @@ public class ImmersivePortalsLinkingSystem implements PortalLinkingSystem {
|
||||
|
||||
@Override
|
||||
public void unLinkPortal(PortalRepresentation portalRepresentation) {
|
||||
List<qouteall.imm_ptl.core.portal.Portal> portals = getPortalList(portalRepresentation);
|
||||
List<Portal> portals = getPortalList(portalRepresentation);
|
||||
portals.forEach(portalEntity -> PortalAPI.removeGlobalPortal(getPortalWorld(portalRepresentation), portalEntity));
|
||||
}
|
||||
|
||||
@@ -131,10 +127,12 @@ public class ImmersivePortalsLinkingSystem implements PortalLinkingSystem {
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<qouteall.imm_ptl.core.portal.Portal> getPortalList(PortalRepresentation portalRepresentation) {
|
||||
private List<Portal> getPortalList(PortalRepresentation portalRepresentation) {
|
||||
Box portalBox = Box.from(portalRepresentation.location());
|
||||
return getPortalWorld(portalRepresentation)
|
||||
.getEntitiesByType(TypeFilter.instanceOf(qouteall.imm_ptl.core.portal.Portal.class), portalBox, e -> e.isAlive() && contains(portalBox, e.getBoundingBox()));
|
||||
getPortalWorld(portalRepresentation)
|
||||
.getEntitiesByType(TypeFilter.instanceOf(Portal.class), portalBox, e -> e.isAlive() && contains(portalBox, e.getBoundingBox()))
|
||||
.forEach(GlobalPortalStorage::convertNormalPortalIntoGlobalPortal);
|
||||
return GlobalPortalStorage.get(getPortalWorld(portalRepresentation)).data.stream().filter(portal -> contains(portalBox, portal.getThinBoundingBox())).toList();
|
||||
}
|
||||
|
||||
private boolean contains(Box outside, Box inside) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldProperties;
|
||||
import org.ladysnake.cca.api.v3.component.Component;
|
||||
import quimufu.colourful_portals.general_util.LinkedList;
|
||||
import quimufu.colourful_portals.general_util.Node;
|
||||
@@ -21,13 +20,11 @@ import static quimufu.colourful_portals.ColourfulPortalsMod.*;
|
||||
|
||||
public class PortalListComponent implements Component {
|
||||
public static final int CURRENT_VERSION = 1;
|
||||
private final WorldProperties worldProperties;
|
||||
HashMap<Identifier, LinkedList<PortalRepresentation>> portalsPerPortalBlock = new HashMap<>();
|
||||
|
||||
Identifier lastPortalLinkingSystem = Identifier.of(MOD_ID, "immersive_portals_linking_system");
|
||||
|
||||
public PortalListComponent(WorldProperties worldProperties) {
|
||||
this.worldProperties = worldProperties;
|
||||
public PortalListComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +37,7 @@ public class PortalListComponent implements Component {
|
||||
LOGGER.warn("portals component comes from a newer version! Hopefully backwards compatible. Proceeding");
|
||||
}
|
||||
if (tag.contains("linking_system")) {
|
||||
lastPortalLinkingSystem = Identifier.tryParse(tag.getString("version"));
|
||||
lastPortalLinkingSystem = Identifier.tryParse(tag.getString("linking_system"));
|
||||
}
|
||||
NbtCompound blocks = tag.getCompound("blocks");
|
||||
for (String block : blocks.getKeys()) {
|
||||
@@ -116,7 +113,7 @@ public class PortalListComponent implements Component {
|
||||
}
|
||||
|
||||
}
|
||||
LOGGER.info("portals {}", tag);
|
||||
LOGGER.debug("portals {}", tag);
|
||||
|
||||
|
||||
}
|
||||
@@ -147,16 +144,12 @@ public class PortalListComponent implements Component {
|
||||
}
|
||||
|
||||
public PortalRepresentation getNext(Identifier blockId, PortalRepresentation portalRepresentationWithDim) {
|
||||
LOGGER.info("gn");
|
||||
LinkedList<PortalRepresentation> portals = getPortals(blockId);
|
||||
Node<PortalRepresentation> node;
|
||||
if ((node = portals.getNodeOf(portalRepresentationWithDim)) == null) {
|
||||
|
||||
return portals.getFirst();
|
||||
}
|
||||
PortalRepresentation portalRepresentation = node.getNext() == null ? portals.getFirst() : node.getNext().getValue();
|
||||
LOGGER.info("gne");
|
||||
return portalRepresentation;
|
||||
return node.getNext() == null ? portals.getFirst() : node.getNext().getValue();
|
||||
}
|
||||
|
||||
public boolean containsPortal(Identifier blockId, PortalRepresentation portalRepresentation) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package quimufu.colourful_portals.portal;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public record PrioritizedPortalLinkingSystemBuilder(PortalLinkingSystemBuilder portalLinkingSystemBuilder,
|
||||
int priority) {}
|
||||
IntSupplier priority) {}
|
||||
|
||||
@@ -3,7 +3,6 @@ package quimufu.colourful_portals.util;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import quimufu.colourful_portals.ColourfulPortalsMod;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -72,8 +71,6 @@ public class RaycastHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
//ColourfulPortalsMod.LOGGER.info("{}, {}: {} -> {}", hitAfter,axis, from, to);
|
||||
|
||||
return BlockPos.ofFloored(from.add(diff.multiply(hitAfter)))
|
||||
.equals(blockPos);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user