Skip to content

Commit

Permalink
Changes - 5
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Dec 23, 2023
1 parent 441b4f1 commit 285d3d5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ protected void onCollision(HitResult hitResult)

if (hitResult.getType() == HitResult.Type.BLOCK)
{
BlockHitResult blockHitResult = (BlockHitResult)hitResult;
/*
if (hitResult.squaredDistanceTo(this) < 0.01)
{
this.setVelocity(0, 0, 0);
}
BlockHitResult blockHitResult = (BlockHitResult)hitResult;
Vec3d velocity = this.getVelocity();
Vec3d pos = hitResult.getPos();
Expand Down Expand Up @@ -149,6 +151,8 @@ else if (this.getX() - pos.getX() > 0 && this.getZ() - pos.getZ() < 0)
}
}
this.setVelocity(velocity.x * modX, velocity.y * modY, velocity.z * modZ);
*/
this.deflect(blockHitResult);
}
super.onCollision(hitResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.parzivail.pswg.container.SwgTags;
import com.parzivail.util.entity.IPrecisionSpawnEntity;
import com.parzivail.util.entity.IPrecisionVelocityEntity;
import com.parzivail.util.math.MathUtil;
import com.parzivail.util.network.PreciseEntitySpawnS2CPacket;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
Expand All @@ -16,6 +18,11 @@
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.registry.tag.DamageTypeTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.ExplosionBehavior;

Expand All @@ -28,6 +35,7 @@ public abstract class ThrowableExplosive extends ThrownEntity implements IPrecis
boolean shouldExplode= false;
float explosionPower =5f;
public boolean shouldRenderVar = true;
boolean gravity=true;

protected ThrowableExplosive(EntityType<? extends ThrownEntity> entityType, World world)
{
Expand All @@ -44,6 +52,46 @@ public void onSpawnPacket(EntitySpawnS2CPacket packet)
this.readSpawnData(pes.getData());
}
}
protected void deflect(HitResult hit)
{
var velocity = this.getVelocity();
BlockHitResult blockHit = (BlockHitResult)hit;

if (blockHit.getSide().equals(Direction.UP))
{
if (hit.squaredDistanceTo(this)<0.01)
{
stopMovement();
}else{
velocity=velocity.multiply(0.75f,-0.2 ,0.75f);
this.setVelocity(velocity);
}
}else
{
var dir = velocity.normalize();

var normal = new Vec3d(blockHit.getSide().getUnitVector());
var newDir = MathUtil.reflect(dir, normal);
this.setVelocity(newDir.multiply(velocity.length() * 0.5f));
}
}
protected void stopMovement(){
this.setVelocity(0f,0f,0f);
gravity=false;

}

@Override
protected float getGravity()
{
if(gravity)
{
return super.getGravity();
}else{
return 0f;
}
}

@Override
public void tick() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"animation": {
"interpolate": true,
"frametime": 4
"frametime": 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
"minecraft:crimson_roots",
"minecraft:frogspawn",
"minecraft:torch",
"minecraft:wall_torch",
"minecraft:soul_torch",
"minecraft:soul_wall_torch",
"minecraft:redstone_torch",
"minecraft:redstone_wall_torch",
"minecraft:kelp",
"minecraft:end_rod",
"minecraft:hanging_roots",
Expand Down Expand Up @@ -81,6 +84,22 @@
"minecraft:brewing_stand",
"minecraft:lever",
"minecraft:tripwire_hook",
"pswg:dried_poonten_grass",
"pswg:poonten_grass",
"pswg:funnel_flower",
"pswg:blossoming_funnel_flower",
"pswg:hkak_bush",
"pswg:tuber_stalk",
"pswg:vaporator_mushroom_colony",
"pswg:scaffold",
"pswg:scaffold_stairs",
"pswg:red_hangar_light",
"pswg:blue_hangar_light",
"pswg:tall_lamp",
"pswg:molo_shrub",
"pswg:power_coupling",
"pswg:wall_cluster_light",
"pswg:electrostatic_repeller",
"#minecraft:crops",
"#minecraft:doors",
"#minecraft:fences",
Expand All @@ -97,5 +116,6 @@
"#minecraft:wool_carpets",
"#minecraft:candles",
"#minecraft:banners",
"#minecraft:fence_gates",
"#c:buds"
]}

0 comments on commit 285d3d5

Please sign in to comment.