55import com .calemi .nexus .block .NexusPortalBlock ;
66import com .calemi .nexus .block .NexusPortalCoreBlock ;
77import com .calemi .nexus .capability .NexusCapabilityHandler ;
8- import com .calemi .nexus .util .NexusMessengers ;
98import com .calemi .nexus .client .model .NexusPortalCoreBakedModel ;
9+ import com .calemi .nexus .config .NexusConfig ;
10+ import com .calemi .nexus .util .NexusMessengers ;
11+ import com .calemi .nexus .util .NexusSoundHelper ;
12+ import com .calemi .nexus .util .TeleportHelper ;
1013import com .calemi .nexus .util .scanner .PortalScanner ;
1114import com .calemi .nexus .util .scanner .PortalSpaceScanner ;
1215import com .calemi .nexus .world .dimension .NexusDimensionHelper ;
13- import com .calemi .nexus .util .NexusSoundHelper ;
14- import com .calemi .nexus .util .TeleportHelper ;
1516import net .minecraft .ChatFormatting ;
1617import net .minecraft .core .BlockPos ;
1718import net .minecraft .core .Direction ;
3940import net .minecraft .world .level .block .state .BlockState ;
4041import net .neoforged .neoforge .client .model .data .ModelData ;
4142import org .jetbrains .annotations .Nullable ;
43+
4244import java .util .HashMap ;
4345import java .util .List ;
4446import java .util .Map ;
@@ -96,10 +98,12 @@ public void setCamoState(BlockState camoState) {
9698 }
9799
98100 public boolean isValidCamoState (BlockState state ) {
101+ if (!NexusConfig .server .portalCoreCamo .get ()) return false ;
99102 if (state == null ) return true ;
100103 if (state .getBlock () == Blocks .AIR ) return false ;
101104 if (state .getBlock () instanceof NexusPortalCoreBlock ) return false ;
102105 if (state .getRenderShape () != RenderShape .MODEL ) return false ;
106+ if (getCamoState () != null && getCamoState ().is (state .getBlock ())) return false ;
103107 return state .isCollisionShapeFullBlock (getLevel (), getBlockPos ());
104108 }
105109
@@ -228,7 +232,7 @@ public boolean isPortalActive() {
228232 }
229233
230234 public List <BlockPos > getPortalPositions () {
231- PortalScanner scanner = new PortalScanner (new Location (level , getProjectionPosition ()), getProjectionAxis (), true , 1000 );
235+ PortalScanner scanner = new PortalScanner (new Location (level , getProjectionPosition ()), getProjectionAxis (), true , NexusConfig . server . maxPortalSize . get () );
232236 scanner .start ();
233237 return scanner .getCollectedPositions ();
234238 }
@@ -257,6 +261,14 @@ public void togglePortal(@Nullable Entity feedbackEntity) {
257261
258262 BlockPos projectionPosition = getProjectionPosition ();
259263
264+ BlockState projectionState = level .getBlockState (projectionPosition );
265+
266+ if (!(projectionState .getBlock () instanceof NexusPortalBlock ) && !level .getBlockState (projectionPosition ).isAir ()) {
267+ NexusMessengers .NEXUS_PORTAL_CORE .send (Component .translatable ("message.nexus.light_portal.obstructed" ).withStyle (ChatFormatting .RED ), feedbackEntity );
268+ NexusSoundHelper .playErrorSound (getLocation ());
269+ return ;
270+ }
271+
260272 if (isPortalActive ()) {
261273 unlightPortal ();
262274 }
@@ -288,11 +300,22 @@ public void lightPortal(@Nullable Entity feedbackEntity) {
288300 BlockPos projectionPosition = getProjectionPosition ();
289301 Direction .Axis projectionAxis = getProjectionAxis ();
290302
291- PortalSpaceScanner scanner = new PortalSpaceScanner (new Location (level , projectionPosition ), projectionAxis , 1000 );
303+ PortalSpaceScanner scanner = new PortalSpaceScanner (new Location (level , projectionPosition ), projectionAxis , NexusConfig . server . maxPortalSize . get () + 1 );
292304 scanner .start ();
293305
294- if (! scanner .isHalted ()) {
306+ List < BlockPos > collectedPositions = scanner .getCollectedPositions ();
295307
308+ if (scanner .isHalted ()) {
309+ NexusMessengers .NEXUS_PORTAL_CORE .send (Component .translatable ("message.nexus.light_portal.invalid_frame" ).withStyle (ChatFormatting .RED ), feedbackEntity );
310+ NexusSoundHelper .playErrorSound (getLocation ());
311+ }
312+
313+ else if (collectedPositions .size () > scanner .getMaxCollectionSize () - 1 ) {
314+ NexusMessengers .NEXUS_PORTAL_CORE .send (Component .translatable ("message.nexus.light_portal.overflowing_frame" ).withStyle (ChatFormatting .RED ), feedbackEntity );
315+ NexusSoundHelper .playErrorSound (getLocation ());
316+ }
317+
318+ else {
296319 scanner .getCollectedPositions ().forEach (blockPos -> {
297320
298321 Block portalBlock = NexusPortalBlock .fromDye (portalColorPattern .getOrDefault (blockPos , getPortalColorBase ()));
@@ -306,11 +329,6 @@ public void lightPortal(@Nullable Entity feedbackEntity) {
306329 NexusMessengers .NEXUS_PORTAL_CORE .send (Component .translatable ("message.nexus.light_portal.success" ).withStyle (ChatFormatting .GREEN ), feedbackEntity );
307330 NexusSoundHelper .playSuccessSound (getLocation ());
308331 }
309-
310- else {
311- NexusMessengers .NEXUS_PORTAL_CORE .send (Component .translatable ("message.nexus.light_portal.invalid_frame" ).withStyle (ChatFormatting .RED ), feedbackEntity );
312- NexusSoundHelper .playErrorSound (getLocation ());
313- }
314332 }
315333
316334 public void teleportEntity (Entity feedbackEntity ) {
0 commit comments