Skip to content

Commit

Permalink
fix portal activation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
luxtracon committed Nov 4, 2024
1 parent 4126228 commit 3939103
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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;
import net.minecraft.world.entity.LivingEntity;
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
Expand All @@ -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());
}
}
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 3939103

Please sign in to comment.