From 393910339a25b77c66939ad0ab412fe4d6f3ced3 Mon Sep 17 00:00:00 2001 From: luxtracon Date: Tue, 5 Nov 2024 00:54:27 +0100 Subject: [PATCH] fix portal activation issues --- gradle.properties | 2 +- .../common/entity/GreekFireGrenadeEntity.java | 58 +++++++++++++------ 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index d6547ba62..951ed5157 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ mod_name=Lands of Icaria # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GNU GENERAL PUBLIC LICENSE # The mod version. See https://semver.org/ -mod_version=1.20.6-2.1.0.0-beta +mod_version=1.20.6-2.2.0.0-beta # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/com/axanthic/icaria/common/entity/GreekFireGrenadeEntity.java b/src/main/java/com/axanthic/icaria/common/entity/GreekFireGrenadeEntity.java index 1cf041635..d44097a63 100644 --- a/src/main/java/com/axanthic/icaria/common/entity/GreekFireGrenadeEntity.java +++ b/src/main/java/com/axanthic/icaria/common/entity/GreekFireGrenadeEntity.java @@ -1,12 +1,13 @@ package com.axanthic.icaria.common.entity; -import com.axanthic.icaria.common.block.IcariaPortalBlock; import com.axanthic.icaria.common.registry.IcariaBlocks; import com.axanthic.icaria.common.registry.IcariaEntityTypes; import com.axanthic.icaria.common.registry.IcariaItems; +import com.axanthic.icaria.common.util.IcariaPortalShape; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.EntityType; @@ -14,8 +15,10 @@ import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.phys.HitResult; +import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @MethodsReturnNonnullByDefault @@ -38,26 +41,33 @@ public boolean displayFireAnimation() { return false; } - @Override - public void onHit(HitResult pResult) { - if (IcariaBlocks.ICARIA_PORTAL.get() instanceof IcariaPortalBlock portalBlock) { - if (portalBlock.spawnPortal(this.level(), this.blockPosition())) { - this.discard(); - return; - } + public boolean spawnPortal(LevelAccessor pLevel, BlockPos pPos) { + var portalShape = this.getPortalShape(pLevel, pPos); + if (portalShape != null) { + portalShape.createPortalBlocks(); + return true; + } else { + return false; } + } + @Override + public void onHit(HitResult pResult) { if (!this.level().isClientSide()) { - this.level().explode(this, this.getX(), this.getY(), this.getZ(), 1.5F, Level.ExplosionInteraction.NONE); - this.discard(); - for (int i = -2; i <= 2; i++) { - var negPos = BlockPos.containing(this.getX() - i, this.getY() - i, this.getZ() - i); - var posPos = BlockPos.containing(this.getX() + i, this.getY() + i, this.getZ() + i); - for (var blockPos : BlockPos.betweenClosed(negPos, posPos)) { - if (this.random.nextInt(10) == 0) { - if (this.level().getBlockState(blockPos).isAir()) { - if (this.level().getBlockState(blockPos.below()).isSolidRender(this.level(), blockPos.below())) { - this.level().setBlockAndUpdate(blockPos, IcariaBlocks.GREEK_FIRE.get().defaultBlockState()); + if (this.spawnPortal(this.level(), BlockPos.containing(pResult.getLocation().x(), pResult.getLocation().y(), pResult.getLocation().z()))) { + this.discard(); + } else { + this.level().explode(this, this.getX(), this.getY(), this.getZ(), 1.5F, Level.ExplosionInteraction.NONE); + this.discard(); + for (int i = -2; i <= 2; i++) { + var negPos = BlockPos.containing(this.getX() - i, this.getY() - i, this.getZ() - i); + var posPos = BlockPos.containing(this.getX() + i, this.getY() + i, this.getZ() + i); + for (var blockPos : BlockPos.betweenClosed(negPos, posPos)) { + if (this.random.nextInt(10) == 0) { + if (this.level().getBlockState(blockPos).isAir()) { + if (this.level().getBlockState(blockPos.below()).isSolidRender(this.level(), blockPos.below())) { + this.level().setBlockAndUpdate(blockPos, IcariaBlocks.GREEK_FIRE.get().defaultBlockState()); + } } } } @@ -66,6 +76,18 @@ public void onHit(HitResult pResult) { } } + public @Nullable IcariaPortalShape getPortalShape(LevelAccessor pLevel, BlockPos pPos) { + var icariaPortalShapeX = new IcariaPortalShape(pLevel, pPos, Direction.Axis.X); + var icariaPortalShapeZ = new IcariaPortalShape(pLevel, pPos, Direction.Axis.Z); + if (icariaPortalShapeX.isValid() && icariaPortalShapeX.numPortalBlocks == 0) { + return icariaPortalShapeX; + } else if (icariaPortalShapeZ.isValid() && icariaPortalShapeZ.numPortalBlocks == 0) { + return icariaPortalShapeZ; + } else { + return null; + } + } + @Override public ItemStack getDefaultPickupItem() { return ItemStack.EMPTY;