Skip to content

Commit

Permalink
Merge pull request #33 from aidan99davis/AD/aiReworking
Browse files Browse the repository at this point in the history
Ad/ai reworking
  • Loading branch information
aidan99davis authored May 19, 2022
2 parents 42088bd + c80a85f commit e8bb0fd
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 425 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package com.spectrobes.spectrobesmod.client.gui.prizmod.Components;

import com.mojang.blaze3d.systems.RenderSystem;
import com.spectrobes.spectrobesmod.client.gui.prizmod.Pages.PrizmodPage;
import com.spectrobes.spectrobesmod.client.gui.prizmod.PrizmodScreen;
import com.spectrobes.spectrobesmod.common.spectrobes.Spectrobe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -27,13 +21,10 @@ public class AllSpectrobesList extends Widget {

public int currentPage = 0;

private PrizmodPage parent;

public AllSpectrobesList(PrizmodPage parent) {
super(parent.x, parent.y, 0, 0, new StringTextComponent(""));
this.parent = parent;
gridData_paged = new HashMap<>();
int specCount = this.parent.parent.getMenu().getOwnedSpectrobesCount();
int specCount = parent.parent.getMenu().getOwnedSpectrobesCount();
int remainder = specCount % 25;
this.pages = specCount / 25;
if(remainder > 0) {
Expand All @@ -54,25 +45,9 @@ public AllSpectrobesList(PrizmodPage parent) {
gridData = gridData_paged.get(currentPage);
}

@OnlyIn(Dist.CLIENT)
public void draw() {
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
// SpectrobePiece p = gridData[i][j];
//
// RenderSystem.pushMatrix();
// Minecraft.getInstance().textureManager.bind(PrizmodScreen.SPECTROBE_SLOT_TEXTURE);
// RenderSystem.enableAlphaTest();
// RenderSystem.translatef(i * 32, j * 32, 0);
// //p.draw();
// RenderSystem.popMatrix();
}
}
}

public void addSpectrobe(Spectrobe piece) {
int i = 0;
int j = 0;
int i;
int j;
boolean added = false;

for(int a = 0; a < this.pages && !added; a++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.spectrobes.spectrobesmod.client.gui.prizmod.Components;

import com.mojang.blaze3d.systems.RenderSystem;
import com.spectrobes.spectrobesmod.SpectrobesInfo;
import com.spectrobes.spectrobesmod.client.gui.prizmod.Pages.PrizmodPage;
import com.spectrobes.spectrobesmod.client.gui.prizmod.PrizmodScreen;
import com.spectrobes.spectrobesmod.common.spectrobes.Spectrobe;
import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TeamSpectrobesList extends Widget {
Expand All @@ -21,7 +17,7 @@ public class TeamSpectrobesList extends Widget {

public SpectrobePiece[] gridData;

private PrizmodPage parent;
private final PrizmodPage parent;

public TeamSpectrobesList(PrizmodPage parent) {
super(parent.x, parent.y, 64, 128, new StringTextComponent(""));
Expand All @@ -36,25 +32,6 @@ public TeamSpectrobesList(PrizmodPage parent) {
gridData[6] = new SpectrobePiece(null, 6, 3);
}

@OnlyIn(Dist.CLIENT)
public void draw() {
for (int i = 0; i < GRID_SIZE; i++) {
// SpectrobePiece p = gridData[i];
//
// RenderSystem.pushMatrix();
// Minecraft.getInstance().textureManager.bind(PrizmodScreen.SPECTROBE_SLOT_TEXTURE);
// RenderSystem.enableAlphaTest();
// RenderSystem.translatef(i * 32, p.posY, 0);
// //p.draw();
// RenderSystem.popMatrix();

}
}

public static boolean exists(int x) {
return x >= 0 && x < GRID_SIZE;
}

public void populateSlot(int index, Spectrobe piece) {
gridData[index].spectrobe = piece;
}
Expand Down Expand Up @@ -85,22 +62,14 @@ public void clear() {
}

public List<SpectrobePiece> getAll() {
List<SpectrobePiece> toReturn = new ArrayList<>();
for (int i = 0; i < GRID_SIZE; i++) {
toReturn.add(gridData[i]);
}
return toReturn;
return new ArrayList<>(Arrays.asList(gridData).subList(0, GRID_SIZE));
}

public boolean swapSpectrobes(int i, int j) {
SpectrobePiece s1 = gridData[i];
SpectrobePiece s2 = gridData[j];

if(i >= 0
&& i < 6
&& j >= 0
&& j < 6
&& i != j) {
if(i < 6 && j < 6 && i != j) {

Spectrobe temp;
temp = s1.spectrobe;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.spectrobes.spectrobesmod.common.entities.goals;

import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntityAquaticSpectrobe;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.goal.JumpGoal;
import net.minecraft.entity.passive.DolphinEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;

public class AquaticJumpGoal extends JumpGoal {
private static final int[] STEPS_TO_CHECK = new int[]{0, 1, 4, 5, 6, 7};
private final EntityAquaticSpectrobe spectrobe;
private final int interval;
private boolean breached;

public AquaticJumpGoal(EntityAquaticSpectrobe p_i50329_1_, int p_i50329_2_) {
this.spectrobe = p_i50329_1_;
this.interval = p_i50329_2_;
}

/**
* Returns whether execution should begin. You can also read and cache any state necessary for execution in this
* method as well.
*/
public boolean canUse() {
if (this.spectrobe.getRandom().nextInt(this.interval) != 0) {
return false;
} else {
Direction direction = this.spectrobe.getMotionDirection();
int i = direction.getStepX();
int j = direction.getStepZ();
BlockPos blockpos = this.spectrobe.blockPosition();

for(int k : STEPS_TO_CHECK) {
if (!this.waterIsClear(blockpos, i, j, k) || !this.surfaceIsClear(blockpos, i, j, k)) {
return false;
}
}

return true;
}
}

private boolean waterIsClear(BlockPos pPos, int pDx, int pDz, int pScale) {
BlockPos blockpos = pPos.offset(pDx * pScale, 0, pDz * pScale);
return this.spectrobe.level.getFluidState(blockpos).is(FluidTags.WATER) && !this.spectrobe.level.getBlockState(blockpos).getMaterial().blocksMotion();
}

private boolean surfaceIsClear(BlockPos pPos, int pDx, int pDz, int pScale) {
return this.spectrobe.level.getBlockState(pPos.offset(pDx * pScale, 1, pDz * pScale)).isAir() && this.spectrobe.level.getBlockState(pPos.offset(pDx * pScale, 2, pDz * pScale)).isAir();
}

/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean canContinueToUse() {
double d0 = this.spectrobe.getDeltaMovement().y;
return (!(d0 * d0 < (double)0.03F) || this.spectrobe.xRot == 0.0F || !(Math.abs(this.spectrobe.xRot) < 10.0F) || !this.spectrobe.isInWater()) && !this.spectrobe.isOnGround();
}

public boolean isInterruptable() {
return false;
}

/**
* Execute a one shot task or start executing a continuous task
*/
public void start() {
Direction direction = this.spectrobe.getMotionDirection();
this.spectrobe.setDeltaMovement(this.spectrobe.getDeltaMovement().add((double)direction.getStepX() * 0.6D, 0.7D, (double)direction.getStepZ() * 0.6D));
this.spectrobe.getNavigation().stop();
}

/**
* Reset the task's internal state. Called when this task is interrupted by another one
*/
public void stop() {
this.spectrobe.xRot = 0.0F;
}

/**
* Keep ticking a continuous task that has already been started
*/
public void tick() {
boolean flag = this.breached;
if (!flag) {
FluidState fluidstate = this.spectrobe.level.getFluidState(this.spectrobe.blockPosition());
this.breached = fluidstate.is(FluidTags.WATER);
}

if (this.breached && !flag) {
this.spectrobe.playSound(SoundEvents.DOLPHIN_JUMP, 1.0F, 1.0F);
}

Vector3d vector3d = this.spectrobe.getDeltaMovement();
if (vector3d.y * vector3d.y < (double)0.03F && this.spectrobe.xRot != 0.0F) {
this.spectrobe.xRot = MathHelper.rotlerp(this.spectrobe.xRot, 0.0F, 0.2F);
} else {
double d0 = Math.sqrt(Entity.getHorizontalDistanceSqr(vector3d));
double d1 = Math.signum(-vector3d.y) * Math.acos(d0 / vector3d.length()) * (double)(180F / (float)Math.PI);
this.spectrobe.xRot = (float)d1;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.spectrobes.spectrobesmod.common.entities.goals;

import com.spectrobes.spectrobesmod.SpectrobesInfo;
import com.spectrobes.spectrobesmod.common.entities.krawl.EntityKrawl;
import com.spectrobes.spectrobesmod.common.entities.krawl.EntityVortex;
import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe;
import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.goal.TargetGoal;

import java.util.List;
import java.util.stream.Collectors;

public class AttackKrawlGoal extends TargetGoal {
EntityKrawl target;
Expand All @@ -27,9 +30,10 @@ public boolean canUse() {
if(mob instanceof EntitySpectrobe && ((EntitySpectrobe)mob).getStage() == SpectrobeProperties.Stage.CHILD)
return false;

List<EntityKrawl> nearbyMobs = mob.level.getEntitiesOfClass(EntityKrawl.class, mob.getBoundingBox().inflate(20, 20, 20));
if (!nearbyMobs.isEmpty()) {
this.target = nearbyMobs.get(0);
List<EntityKrawl> nearbyMobs = mob.level.getEntitiesOfClass(EntityKrawl.class, mob.getBoundingBox().inflate(5, 5, 5));
List<EntityKrawl> nonVortexKrawl = nearbyMobs.stream().filter(entityKrawl -> !entityKrawl.isVortex()).collect(Collectors.toList());
if (!nonVortexKrawl.isEmpty()) {
this.target = nonVortexKrawl.get(0);
return true;
}
return false;
Expand All @@ -46,11 +50,20 @@ public boolean canContinueToUse() {
}
}

@Override
public void tick() {
super.tick();
this.mob.setTarget(this.target);
((EntitySpectrobe)this.mob).setIsAttacking(true);
this.mob.getMoveControl().setWantedPosition(this.target.getX(), this.target.getY(), this.target.getZ(), 5);
this.mob.setAggressive(true);
}

@Override
public void start() {
this.mob.setTarget(this.target);
((EntitySpectrobe)this.mob).setIsAttacking(true);
this.mob.getNavigation().moveTo(this.mob.getNavigation().createPath(this.target, 5), 5);
this.mob.getMoveControl().setWantedPosition(this.target.getX(), this.target.getY(), this.target.getZ(), 5);
this.mob.setAggressive(true);
super.start();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.spectrobes.spectrobesmod.common.entities.goals;

import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe;
import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties;
import net.minecraft.entity.CreatureEntity;
import net.minecraft.entity.ai.goal.AvoidEntityGoal;

public class AvoidKrawlGoal extends AvoidEntityGoal {
public AvoidKrawlGoal(CreatureEntity entity, Class toAvoid, float maxDist, double walkSpeedModifier, double sprintSpeedModifier) {
super(entity, toAvoid, maxDist, walkSpeedModifier, sprintSpeedModifier);
}

@Override
public boolean canUse() {
return ((EntitySpectrobe)mob).getStage() == SpectrobeProperties.Stage.CHILD && super.canUse();
}
}

This file was deleted.

Loading

0 comments on commit e8bb0fd

Please sign in to comment.