Compare commits

...

2 commits

Author SHA1 Message Date
4472b68eca
"Optimized" EntityShockwave
Do less shit per onUpdate(), its good for your tps

Split explosion into a bunch of phases that run every onUpdate, code is
ass but stopped the server from crashing

Will need to do the same to EntityFalloutRain too but that's tomorrows
problem

Also tomorrows problem: make this less ass

Also vim fixed a lot of whitespace things and I dont feel like dealing
with that right now
2021-11-15 02:43:01 -05:00
f351d614d6
gradlew +x 2021-11-15 02:42:04 -05:00
2 changed files with 108 additions and 63 deletions

0
gradlew vendored Normal file → Executable file
View file

View file

@ -45,13 +45,28 @@ import trinity.handler.Vec3;
import trinity.init.ModBlocks; import trinity.init.ModBlocks;
public class EntityShockwave extends Entity { public class EntityShockwave extends Entity {
private static final DataParameter<Integer> SCALE = EntityDataManager.<Integer>createKey(EntityShockwave.class, DataSerializers.VARINT); private static final DataParameter<Integer> SCALE = EntityDataManager.<Integer>createKey(EntityShockwave.class, DataSerializers.VARINT);
public int revProgress; public int revProgress;
public int radProgress; public int radProgress;
private int iCounter = 0;
private boolean needsInit = true;
private int blastState = 0; // Not started
private int blastCount = 0;
private MutableBlockPos pos;
private MutableBlockPos pos2;
private MutableBlockPos pos3;
private MutableBlockPos pos4;
private MutableBlockPos pos5;
private double dist;
private double circum;
public EntityShockwave(World p_i1582_1_) { public EntityShockwave(World p_i1582_1_) {
super(p_i1582_1_); super(p_i1582_1_);
this.setSize(0, 0); this.setSize(0, 0);
@ -83,87 +98,117 @@ public class EntityShockwave extends Entity {
return bb; return bb;
//return this.getEntityBoundingBox(); //return this.getEntityBoundingBox();
} }
@Override @Override
public void onUpdate() { public void onUpdate() {
if(!world.isRemote) { if(!world.isRemote) {
MutableBlockPos pos = new BlockPos.MutableBlockPos(); if(needsInit) {
MutableBlockPos pos2 = new BlockPos.MutableBlockPos(); pos = new BlockPos.MutableBlockPos();
MutableBlockPos pos3 = new BlockPos.MutableBlockPos(); pos2 = new BlockPos.MutableBlockPos();
MutableBlockPos pos4 = new BlockPos.MutableBlockPos(); pos3 = new BlockPos.MutableBlockPos();
MutableBlockPos pos5 = new BlockPos.MutableBlockPos(); pos4 = new BlockPos.MutableBlockPos();
for(int i = 0; i < 512; i++) { pos5 = new BlockPos.MutableBlockPos();
needsInit = false;
Vec3 vec = Vec3.createVectorHelper(radProgress * 0.5, 0, 0); }
double circum = radProgress * 2 * Math.PI * 2; if(iCounter < 512*3) {
if(blastState == 0) { // Not started
/// Vec3 vec = Vec3.createVectorHelper(radProgress * 0.5, 0, 0);
if(circum == 0) circum = radProgress * 2 * Math.PI * 2;
circum = 1;
/// ///
if(circum == 0)
double part = 360D / circum; circum = 1;
///
vec.rotateAroundY((float) (part * revProgress));
double part = 360D / circum;
int x = (int) (posX + vec.xCoord);
int z = (int) (posZ + vec.zCoord); vec.rotateAroundY((float) (part * revProgress));
double dist = radProgress * 100 / getScale() * 0.5; int x = (int) (posX + vec.xCoord);
pos.setPos(x, posY, z); int z = (int) (posZ + vec.zCoord);
pos2.setPos(x-1, posY, z);
pos3.setPos(x+1, posY, z); dist = radProgress * 100 / getScale() * 0.5;
pos4.setPos(x, posY, z-1); pos.setPos(x, posY, z);
pos5.setPos(x, posY, z-1); pos2.setPos(x-1, posY, z);
blast(pos, dist); pos3.setPos(x+1, posY, z);
blast(pos2, dist); pos4.setPos(x, posY, z-1);
blast(pos3, dist); pos5.setPos(x, posY, z-1);
blast(pos4, dist); blastState = 1;
blast(pos5, dist); } else if(blastState == 1) {
switch(blastCount) {
revProgress++; case 0:
blast(pos, dist);
if(revProgress > circum) { blastCount++;
revProgress = 0; break;
radProgress++; case 1:
} blast(pos2, dist);
blastCount++;
if(radProgress > getScale() * 2D) { break;
case 2:
this.setDead(); blast(pos3, dist);
} blastCount++;
break;
case 3:
blast(pos4, dist);
blastCount++;
break;
case 4:
blast(pos5, dist);
blastCount++;
break;
case 5:
blastState = 2;
blastCount = 0;
break;
}
} else if(blastState == 2) {
revProgress++;
if(revProgress > circum) {
revProgress = 0;
radProgress++;
}
if(radProgress > getScale() * 2D) {
this.setDead();
blastState = 4;
}
blastState = 0;
}
} }
iCounter++;
} }
} }
private void blast(MutableBlockPos pos, double dist) { private void blast(MutableBlockPos pos, double dist) {
int depth = 0; int depth = 0;
int topBlock =world.getTopSolidOrLiquidBlock(pos).getY(); int topBlock =world.getTopSolidOrLiquidBlock(pos).getY();
for(int y = (topBlock-8); y <= topBlock+48; y++) { for(int y = (topBlock-8); y <= topBlock+48; y++) {
pos.setY(y); pos.setY(y);
IBlockState b = world.getBlockState(pos); IBlockState b = world.getBlockState(pos);
//int meta = world.getBlockMetadata(x, y, z); //int meta = world.getBlockMetadata(x, y, z);
BlockPos left = new BlockPos(pos.getX()+1,pos.getY(),pos.getZ()); BlockPos left = new BlockPos(pos.getX()+1,pos.getY(),pos.getZ());
BlockPos right = new BlockPos(pos.getX()-1,pos.getY(),pos.getZ()); BlockPos right = new BlockPos(pos.getX()-1,pos.getY(),pos.getZ());
BlockPos up = new BlockPos(pos.getX(),pos.getY()+1,pos.getZ()); BlockPos up = new BlockPos(pos.getX(),pos.getY()+1,pos.getZ());
//BlockPos down = pos.add(0, -1, 0); //BlockPos down = pos.add(0, -1, 0);
BlockPos down2 = new BlockPos(pos.getX(),pos.getY()-1,pos.getZ()); BlockPos down2 = new BlockPos(pos.getX(),pos.getY()-1,pos.getZ());
BlockPos front = pos.add(0, 0, 1); BlockPos front = pos.add(0, 0, 1);
BlockPos back = pos.add(0, 0, -1); BlockPos back = pos.add(0, 0, -1);
boolean LR = (world.isAirBlock(left) && world.isAirBlock(right)); boolean LR = (world.isAirBlock(left) && world.isAirBlock(right));
//boolean UD = (world.isAirBlock(up) && world.isAirBlock(down)); //boolean UD = (world.isAirBlock(up) && world.isAirBlock(down));
boolean FB = (world.isAirBlock(front) && world.isAirBlock(back)); boolean FB = (world.isAirBlock(front) && world.isAirBlock(back));
IBlockState bd = world.getBlockState(down2); IBlockState bd = world.getBlockState(down2);
if((b.getMaterial() != Material.AIR || (b.getBlock()instanceof BlockFluidClassic)) && bd.getMaterial() == Material.AIR) if((b.getMaterial() != Material.AIR || (b.getBlock()instanceof BlockFluidClassic)) && bd.getMaterial() == Material.AIR)
{ {
if(b.getBlock().getExplosionResistance(null)<=100) if(b.getBlock().getExplosionResistance(null)<=100)
@ -174,13 +219,13 @@ public class EntityShockwave extends Entity {
continue; continue;
} }
} }
if(b.getMaterial() != Material.AIR && (LR || FB)) if(b.getMaterial() != Material.AIR && (LR || FB))
{ {
world.setBlockToAir(pos); world.setBlockToAir(pos);
continue; continue;
} }
if(b.getMaterial() == Material.AIR) if(b.getMaterial() == Material.AIR)
continue; continue;
@ -206,7 +251,7 @@ public class EntityShockwave extends Entity {
p_70014_1_.setInteger("scale", getScale()); p_70014_1_.setInteger("scale", getScale());
p_70014_1_.setInteger("revProgress", revProgress); p_70014_1_.setInteger("revProgress", revProgress);
p_70014_1_.setInteger("radProgress", radProgress); p_70014_1_.setInteger("radProgress", radProgress);
} }
public void setScale(int i) { public void setScale(int i) {
@ -216,7 +261,7 @@ public class EntityShockwave extends Entity {
public int getScale() { public int getScale() {
int scale = this.dataManager.get(SCALE); int scale = this.dataManager.get(SCALE);
return scale == 0 ? 1 : scale; return scale == 0 ? 1 : scale;
} }
} }