Skip to content

Commit

Permalink
we all gud now yay
Browse files Browse the repository at this point in the history
  • Loading branch information
ANightDazingZoroark committed Feb 14, 2024
1 parent 9fe18d6 commit 436d75c
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package anightdazingzoroark.prift.compat.simpledifficulty;

import anightdazingzoroark.prift.RiftUtil;
import anightdazingzoroark.prift.config.DimetrodonConfig;
import anightdazingzoroark.prift.server.entity.creature.Dimetrodon;
import com.charles445.simpledifficulty.temperature.ModifierBase;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.AxisAlignedBB;
Expand All @@ -12,6 +18,8 @@
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Set;

public class ModifierDimetrodon extends ModifierBase {
public ModifierDimetrodon() {
Expand All @@ -20,8 +28,7 @@ public ModifierDimetrodon() {

@Override
public float getWorldInfluence(World world, BlockPos pos) {
AxisAlignedBB playerAABB = new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY() + 1, pos.getZ());
float dimetrodonTemperature = 0f;
float temperature = 0f;
for (EntityLivingBase entityLivingBase : world.getEntities(EntityLiving.class, new Predicate<EntityLiving>() {
@Override
public boolean apply(@Nullable EntityLiving input) {
Expand All @@ -30,45 +37,68 @@ public boolean apply(@Nullable EntityLiving input) {
})) {
if (entityLivingBase instanceof Dimetrodon) {
Dimetrodon dimetrodon = (Dimetrodon) entityLivingBase;
if (dimetrodon.getEntityBoundingBox().grow(8.0D).intersects(playerAABB)) {
switch (dimetrodon.getTemperature()) {
case VERY_COLD:
dimetrodonTemperature += this.changeByDistance(DimetrodonConfig.dimetrodonVeryColdValue, pos, dimetrodon.getEntityBoundingBox());
break;
case COLD:
dimetrodonTemperature += this.changeByDistance(DimetrodonConfig.dimetrodonColdValue, pos, dimetrodon.getEntityBoundingBox());
break;
case WARM:
dimetrodonTemperature += this.changeByDistance(DimetrodonConfig.dimetrodonWarmValue, pos, dimetrodon.getEntityBoundingBox());
break;
case VERY_WARM:
dimetrodonTemperature += this.changeByDistance(DimetrodonConfig.dimetrodonVeryWarmValue, pos, dimetrodon.getEntityBoundingBox());
break;
List<BlockPos> affectedBlockPositions = Lists.<BlockPos>newArrayList();
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = ((float)j / 15.0F * 2.0F - 1.0F);
double d1 = ((float)k / 15.0F * 2.0F - 1.0F);
double d2 = ((float)l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = 8f * (0.7F + world.rand.nextFloat() * 0.6F);
double d4 = dimetrodon.posX;
double d6 = dimetrodon.posY;
double d8 = dimetrodon.posZ;

for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = world.getBlockState(blockpos);
if (iblockstate.getMaterial() == Material.AIR) {
set.add(blockpos);
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
} else {
// If a solid block is encountered, stop the propagation in this direction
break;
}
}
}
}
}
}
affectedBlockPositions.addAll(set);
for (BlockPos blockPos : affectedBlockPositions) {
if (blockPos.equals(pos)) {
switch (dimetrodon.getTemperature()) {
case VERY_COLD:
temperature += this.changeByDistance(DimetrodonConfig.dimetrodonVeryColdValue, dimetrodon.getPosition(), pos);
break;
case COLD:
temperature += this.changeByDistance(DimetrodonConfig.dimetrodonColdValue, dimetrodon.getPosition(), pos);
break;
case WARM:
temperature += this.changeByDistance(DimetrodonConfig.dimetrodonWarmValue, dimetrodon.getPosition(), pos);
break;
case VERY_WARM:
temperature += this.changeByDistance(DimetrodonConfig.dimetrodonVeryWarmValue, dimetrodon.getPosition(), pos);
break;
}
}
}
}
}
return dimetrodonTemperature;
return temperature;
}

private float changeByDistance(float temperatureValue, BlockPos blockPos, AxisAlignedBB dimetrodonAABB) {
// First bounding box, grown by double its size
AxisAlignedBB firstBoundingBox = dimetrodonAABB.grow(2.0D);

// Second bounding box, grown to a fixed 8-block radius from the center
AxisAlignedBB secondBoundingBox = dimetrodonAABB.grow(8.0D);

Vec3d posVec = new Vec3d(blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (firstBoundingBox.contains(posVec) && secondBoundingBox.contains(posVec)) return temperatureValue;
else if (!firstBoundingBox.contains(posVec) && secondBoundingBox.contains(posVec)) {
double distFromCenterX = blockPos.getX() - dimetrodonAABB.getCenter().x;
double distFromCenterY = blockPos.getY() - dimetrodonAABB.getCenter().y;
double distFromCenterZ = blockPos.getZ() - dimetrodonAABB.getCenter().z;
double dist = Math.sqrt(distFromCenterX * distFromCenterX + distFromCenterY * distFromCenterY + distFromCenterZ * distFromCenterZ);
if (dist > 2 && dist <= 8) {
return (-temperatureValue * ((float) dist - 8f))/6f;
}
}
return 0f;
private float changeByDistance(float origTemperature, BlockPos blockPos, BlockPos playerBlockPos) {
float distance = (float)Math.sqrt(blockPos.distanceSq(playerBlockPos.getX(), playerBlockPos.getY(), playerBlockPos.getZ()));
return ((-origTemperature/8f) * RiftUtil.clamp(distance, 0f, 8f)) + origTemperature;
}
}
76 changes: 62 additions & 14 deletions src/main/java/anightdazingzoroark/prift/server/entity/RiftEgg.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.charles445.simpledifficulty.api.temperature.TemperatureEnum;
import com.charles445.simpledifficulty.config.ModConfig;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -49,6 +51,7 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class RiftEgg extends EntityTameable implements IAnimatable {
private static final DataParameter<Integer> HATCH_TIME = EntityDataManager.<Integer>createKey(RiftEgg.class, DataSerializers.VARINT);
Expand Down Expand Up @@ -186,20 +189,59 @@ public boolean apply(@Nullable EntityLiving input) {
})) {
if (entityLivingBase instanceof Dimetrodon) {
Dimetrodon dimetrodon = (Dimetrodon) entityLivingBase;
if (dimetrodon.getEntityBoundingBox().grow(8.0D).intersects(this.getEntityBoundingBox())) {
switch (dimetrodon.getTemperature()) {
case VERY_COLD:
temperatureValue += this.changeByDistanceFromDimetrodon(DimetrodonConfig.dimetrodonVeryColdValue, dimetrodon.getEntityBoundingBox());
break;
case COLD:
temperatureValue += this.changeByDistanceFromDimetrodon(DimetrodonConfig.dimetrodonColdValue, dimetrodon.getEntityBoundingBox());
break;
case WARM:
temperatureValue += this.changeByDistanceFromDimetrodon(DimetrodonConfig.dimetrodonWarmValue, dimetrodon.getEntityBoundingBox());
break;
case VERY_WARM:
temperatureValue += this.changeByDistanceFromDimetrodon(DimetrodonConfig.dimetrodonVeryWarmValue, dimetrodon.getEntityBoundingBox());
break;
List<BlockPos> affectedBlockPositions = Lists.<BlockPos>newArrayList();
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = ((float)j / 15.0F * 2.0F - 1.0F);
double d1 = ((float)k / 15.0F * 2.0F - 1.0F);
double d2 = ((float)l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= d3;
d1 /= d3;
d2 /= d3;
float f = 8f * (0.7F + this.world.rand.nextFloat() * 0.6F);
double d4 = dimetrodon.posX;
double d6 = dimetrodon.posY;
double d8 = dimetrodon.posZ;

for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (iblockstate.getMaterial() == Material.AIR) {
set.add(blockpos);
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
} else {
// If a solid block is encountered, stop the propagation in this direction
break;
}
}
}
}
}
}
affectedBlockPositions.addAll(set);
for (BlockPos blockPos : affectedBlockPositions) {
if (blockPos.equals(this.getPosition())) {
switch (dimetrodon.getTemperature()) {
case VERY_COLD:
temperatureValue += this.changeTempByDistance(DimetrodonConfig.dimetrodonVeryColdValue, dimetrodon.getPosition());
break;
case COLD:
temperatureValue += this.changeTempByDistance(DimetrodonConfig.dimetrodonColdValue, dimetrodon.getPosition());
break;
case WARM:
temperatureValue += this.changeTempByDistance(DimetrodonConfig.dimetrodonWarmValue, dimetrodon.getPosition());
break;
case VERY_WARM:
temperatureValue += this.changeTempByDistance(DimetrodonConfig.dimetrodonVeryWarmValue, dimetrodon.getPosition());
break;
}
}
}
}
Expand Down Expand Up @@ -233,6 +275,12 @@ public boolean apply(@Nullable Dimetrodon input) {
}

//for simple difficulty compat

private float changeTempByDistance(float origTemperature, BlockPos blockPos) {
float distance = (float)Math.sqrt(blockPos.distanceSq(this.posX, this.posY, this.posZ));
return ((-origTemperature/8f) * RiftUtil.clamp(distance, 0f, 8f)) + origTemperature;
}

private float normalizeToPlusMinus(float value) {
return (value * 2.0f) - 1.0f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ private void roarBreakBlocks(float strength) {
if (canBreak) {
if (!this.world.isRemote) {
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
Expand Down

0 comments on commit 436d75c

Please sign in to comment.