Skip to content

Commit

Permalink
Explosion, Hitbox and Throwing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Nov 19, 2024
1 parent 5f087a7 commit c9984b4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
7 changes: 2 additions & 5 deletions projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import dev.pswg.item.GrenadeItem;
import dev.pswg.item.ThermalDetonatorItem;
import dev.pswg.registry.Registrar;
import net.fabricmc.fabric.api.item.v1.FabricItem;
import net.minecraft.block.AbstractBlock;
import net.minecraft.component.ComponentType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
Expand Down Expand Up @@ -51,10 +49,9 @@ public static Identifier id(String path)
public static final EntityType<ThermalDetonatorEntity> THERMAL_DETONATOR_ENTITY = Registrar.entityType(
id("thermal_detonator"),
EntityType.Builder.create(ThermalDetonatorEntity::new, SpawnGroup.MISC)
.dimensions(0.4f, 0.4f)
.eyeHeight(0.2f)
.dimensions(0.2f, 0.2f)
.dropsNothing()
.maxTrackingRange(4)
.maxTrackingRange(100)
.trackingTickInterval(20)
);
public static final ComponentType<Long> PRIMING_TIME = Registry.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GrenadeEntity extends ThrownEntity

private int delay = 0;
private boolean shouldExplode = false;
private float explosionPower = 5f;
private float explosionPower = 4f;
private boolean isVisible = true;
protected GrenadeEntity(EntityType<? extends ThrownEntity> entityType, World world)
{
Expand Down Expand Up @@ -139,7 +139,9 @@ public boolean shouldRender(double distance)
return isVisible() && super.shouldRender(distance);
}

protected void createParticles(double x, double y, double z, ServerWorld serverWorld){};
protected void createParticles(double x, double y, double z, ServerWorld serverWorld)
{
}
@Override
public boolean damage(ServerWorld world, DamageSource source, float amount)
{
Expand All @@ -164,7 +166,7 @@ public void explode()
{
if (getWorld() instanceof ServerWorld serverWorld)
{
getWorld().createExplosion(this, (DamageSource)null, (ExplosionBehavior)null, this.getX(), this.getY(), this.getZ(), explosionPower, false, World.ExplosionSourceType.TRIGGER);
getWorld().createExplosion(this, (DamageSource)null, (ExplosionBehavior)null, this.getX(), this.getY() + 0.1f, this.getZ(), explosionPower, false, World.ExplosionSourceType.TRIGGER);
createParticles(getX(), getY(), getZ(), serverWorld);
}
this.discard();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.pswg.entity;

import dev.pswg.Gadgets;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -20,7 +22,6 @@ public ThermalDetonatorEntity(EntityType<ThermalDetonatorEntity> type, World wor
super(type, world);
setExplosionPower(5f);
}

@Override
public void explode()
{
Expand All @@ -35,6 +36,7 @@ public void tick()
// SoundHelper.playDetonatorEntitySound(this);

this.speed = this.speed * 0.95f;
velocityModified = true;
super.tick();
}

Expand Down Expand Up @@ -76,7 +78,7 @@ protected void onCollision(HitResult hitResult)
this.bounce(blockHitResult);

if (getVelocity().length() > 0.01f)
this.playSound(state.getBlock().asItem().getBreakSound(), 1f, 1f);
this.playSound(state.getSoundGroup().getHitSound(), 0.5f, 1f);
}

super.onCollision(hitResult);
Expand All @@ -85,14 +87,11 @@ protected void onCollision(HitResult hitResult)
@Override
public ActionResult interact(PlayerEntity player, Hand hand)
{
/*if (!isPrimed() && age > MIN_PICKUP_AGE && player.getInventory().getMainHandStack().isEmpty())
if (!isPrimed() && age > MIN_PICKUP_AGE && player.getMainHandStack().isEmpty())
{
if (getWorld() instanceof ServerWorld)
player.giveItemStack(new ItemStack(SwgItems.Explosives.ThermalDetonator));
this.discard();
}*/
setPrimed(true);
setLife(0);
player.giveItemStack(new ItemStack(Gadgets.THERMAL_DETONATOR_ITEM));
this.remove(RemovalReason.KILLED);
}
return super.interact(player, hand);
}

Expand Down
35 changes: 28 additions & 7 deletions projects/pswg_gadgets/src/main/java/dev/pswg/item/GrenadeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.item.consume.UseAction;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -71,15 +72,12 @@ public void spawnEntity(World world, int power, ItemStack stack ,Entity player)

}


public void createExplosion(World world, int power, Entity player)
{
if(player instanceof LivingEntity livingEntity)
spawnEntity(world, power, livingEntity.getMainHandStack(), player);
}

;

public void createExplosion(World world, Entity player)
{
createExplosion(world, 4, player);
Expand Down Expand Up @@ -170,13 +168,35 @@ public UseAction getUseAction(ItemStack stack)
@Override
public ActionResult use(World world, PlayerEntity user, Hand hand)
{
ItemStack itemStack = user.getStackInHand(hand);
user.setCurrentHand(hand);
throwEntity(world, itemStack, user);

return ActionResult.CONSUME;
}

@Override
public boolean onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)
{
if (user instanceof PlayerEntity playerEntity)
{
boolean inCreative = playerEntity.getAbilities().creativeMode;
ItemStack itemStack = playerEntity.getStackInHand(Hand.MAIN_HAND);
if (!itemStack.isEmpty())
{
GrenadeItem throwableExplosiveItem = (GrenadeItem)(itemStack.getItem() instanceof GrenadeItem ? itemStack.getItem() : item);
throwEntity(world, itemStack, playerEntity);

//playerEntity.getItemCooldownManager().remove(itemStack.getItem().);
stack.remove(Gadgets.PRIMING_TIME);

//sounds.playThrowSound(playerEntity);
if (!inCreative)
{
stack.decrement(1);
}
playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
}
}
return super.onStoppedUsing(stack, world, user, remainingUseTicks);
}

@Override
public ActionResult useLeft(World world, LivingEntity user, Hand hand)
{
Expand All @@ -201,6 +221,7 @@ public ActionResult useLeft(World world, LivingEntity user, Hand hand)
}
return ActionResult.SUCCESS;
}

/*
@Override
public boolean allowRepeatedLeftHold(World world, PlayerEntity player, Hand mainHand)
Expand Down

0 comments on commit c9984b4

Please sign in to comment.