Skip to content

Commit

Permalink
Updating Fragmentation Grenade Parts
Browse files Browse the repository at this point in the history
Increase of Grab
Blaster Bolts set off C-25 FG Blocks
Ticking Sound when it's primed
Updating Fragmentation Grenade Item class
Adding FG tooltip to lang file
Adding Off texture for block
Starting work on item renderer
Creating GrenadeItemSoundInstance as a superclass
  • Loading branch information
DeltaHelios committed Mar 28, 2024
1 parent 21e890c commit 7af3291
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 281 deletions.
3 changes: 1 addition & 2 deletions projects/pswg/src/main/java/com/parzivail/pswg/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.parzivail.pswg.client.screen.MoistureVaporatorScreen;
import com.parzivail.pswg.client.sound.EnvironmentSoundManager;
import com.parzivail.pswg.container.*;
import com.parzivail.pswg.entity.FragmentationGrenadeEntity;
import com.parzivail.pswg.entity.ship.ShipEntity;
import com.parzivail.pswg.features.blasters.BlasterItem;
import com.parzivail.pswg.features.blasters.BlasterUtil;
Expand All @@ -45,7 +44,7 @@
import com.parzivail.pswg.features.lightsabers.LightsaberItem;
import com.parzivail.pswg.features.lightsabers.client.LightsaberItemRenderer;
import com.parzivail.pswg.features.lightsabers.client.forge.LightsaberForgeScreen;
import com.parzivail.pswg.features.thermaldetonator.client.ThermalDetonatorItemRenderer;
import com.parzivail.pswg.features.grenades.client.ThermalDetonatorItemRenderer;
import com.parzivail.pswg.item.ThermalDetonatorItem;
import com.parzivail.pswg.item.jetpack.JetpackItem;
import com.parzivail.pswg.mixin.BufferBuilderStorageAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class SwgModelPredicateProviders
{
public static final Identifier ThermalDetonatorPrimed = Resources.id("thermal_detonator_primed");
public static final Identifier FragmentationGrenadePrimed = Resources.id("fragmentation_grenade_primed");

public static void register()
{
Expand All @@ -20,5 +21,13 @@ public static void register()
return entity != null && tag.primed ? 1.0F : 0.0F;
}
);
ModelPredicateProviderRegistry.register(
SwgItems.Explosives.FragmentationGrenade,
FragmentationGrenadePrimed,
(stack, world, entity, seed) -> {
var tag = new ThrowableExplosiveTag(stack.getOrCreateNbt());
return entity != null && tag.primed ? 1.0F : 0.0F;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@

public class SwgSoundTimelines
{
public static final Identifier THERMAL_DETONATOR_BEEP_ID = Resources.id("beep");
public static final Identifier THERMAL_DETONATOR_BEEP_ID = Resources.id("beep_td");
public static final Identifier FRAGMENTATION_GRENADE_BEEP_ID = Resources.id("beep_fg");

public static final SoundTimelineEvents THERMAL_DETONATOR_BEEP_TIMELINE = new SoundTimelineEvents(SwgSounds.Explosives.THERMAL_DETONATOR_BEEP, List.of(
new SoundTimelineEvent(THERMAL_DETONATOR_BEEP_ID, 0.072891f, 0.417551f),
new SoundTimelineEvent(THERMAL_DETONATOR_BEEP_ID, 0.815305f, 1.159964f),
new SoundTimelineEvent(THERMAL_DETONATOR_BEEP_ID, 1.579315f, 1.923975f)
));
public static final SoundTimelineEvents FRAGMENTATION_GRENADE_BEEP_TIMELINE = new SoundTimelineEvents(SwgSounds.Explosives.THERMAL_DETONATOR_BEEP, List.of(
new SoundTimelineEvent(FRAGMENTATION_GRENADE_BEEP_ID, 0.072891f, 0.417551f),
new SoundTimelineEvent(FRAGMENTATION_GRENADE_BEEP_ID, 0.815305f, 1.159964f),
new SoundTimelineEvent(FRAGMENTATION_GRENADE_BEEP_ID, 1.579315f, 1.923975f)
));

private static void register()
{
SoundTimelineManager.register(THERMAL_DETONATOR_BEEP_TIMELINE);
SoundTimelineManager.register(FRAGMENTATION_GRENADE_BEEP_TIMELINE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.parzivail.p3d.P3dModel;
import com.parzivail.pswg.Resources;
import com.parzivail.pswg.entity.FragmentationGrenadeEntity;
import net.minecraft.client.render.Frustum;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
Expand All @@ -16,6 +17,7 @@ public class FragmentationGrenadeRenderer extends EntityRenderer<FragmentationGr
{
public static final Identifier MODEL = Resources.id("item/fragmentation_grenade/fragmentation_grenade");
public static final Identifier TEXTURE = Resources.id("textures/item/model/fragmentation_grenade/fragmentation_grenade.png");
public static final Identifier TEXTURE_OFF = Resources.id("textures/item/model/fragmentation_grenade/fragmentation_grenade_off.png");

public P3dModel model;

Expand All @@ -27,7 +29,11 @@ public FragmentationGrenadeRenderer(EntityRendererFactory.Context ctx)
@Override
public Identifier getTexture(FragmentationGrenadeEntity entity)
{
return TEXTURE;
if (entity.isPrimed())
{
return TEXTURE;
}
return TEXTURE_OFF;
}

@Override
Expand All @@ -45,4 +51,14 @@ public void render(FragmentationGrenadeEntity entity, float yaw, float tickDelta
matrices.pop();
super.render(entity, yaw, tickDelta, matrices, vertexConsumers, light);
}

@Override
public boolean shouldRender(FragmentationGrenadeEntity entity, Frustum frustum, double x, double y, double z)
{
if (entity.IS_EXPLODING)
{
return false;
}
return super.shouldRender(entity, frustum, x, y, z);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.parzivail.pswg.client.sound;

import com.parzivail.pswg.container.SwgSounds;
import com.parzivail.pswg.item.FragmentationGrenadeItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;

@Environment(EnvType.CLIENT)
public class FragmentationGrenadeItemSoundInstance extends GrenadeItemSoundInstance implements ISoftRepeatSound
{
public FragmentationGrenadeItemSoundInstance(PlayerEntity player)
{
super(player, SwgSounds.Explosives.THERMAL_DETONATOR_BEEP);
}

@Override
public boolean isItem(ItemStack stack)
{
if (stack.getItem() instanceof FragmentationGrenadeItem)
{
return true;
}
return false;
}

;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.parzivail.pswg.client.sound;

import com.parzivail.pswg.item.ThrowableExplosiveTag;
import com.parzivail.util.sound.DopplerSoundInstance;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;

@Environment(EnvType.CLIENT)
public class GrenadeItemSoundInstance extends DopplerSoundInstance implements ISoftRepeatSound
{
private final PlayerEntity player;

public GrenadeItemSoundInstance(PlayerEntity player, SoundEvent soundEvent)
{
super(player, soundEvent, SoundCategory.PLAYERS, SoundInstance.createRandom());
this.player = player;
this.repeat = true;
this.repeatDelay = 0;
this.volume = 0.75F;
this.x = (float)player.getX();
this.y = (float)player.getY();
this.z = (float)player.getZ();
}

@Override
public boolean canPlay()
{
return !this.player.isSilent();
}

@Override
public boolean shouldAlwaysPlay()
{
return true;
}

public PlayerEntity getPlayer()
{
return player;
}

@Override
public void tick()
{
super.tick();

if (this.player.isRemoved())
{
this.setDone();
return;
}

var foundItem = false;

if (isItem(player.getMainHandStack()) && isPrimed(player.getMainHandStack()))
foundItem = true;

if (isItem(player.getOffHandStack()) && isPrimed(player.getOffHandStack()))
foundItem = true;

if (!areConditionsMet(player))
{
this.setDone();
return;
}
if (foundItem)
volume = 0.75f;
else
volume = 0.25f;

this.x = (float)this.player.getX();
this.y = (float)this.player.getY();
this.z = (float)this.player.getZ();
}

public boolean areConditionsMet(PlayerEntity player)
{
for (int i = 0; i < player.getInventory().size(); i++)
if (isItem(player.getInventory().getStack(i)) && isPrimed(player.getInventory().getStack(i)))
return true;
return false;
}

public boolean isItem(ItemStack stack)
{
return false;
}

;

private boolean isPrimed(ItemStack stack)
{
if (!(isItem(stack)))
return false;

var tet = new ThrowableExplosiveTag(stack.getOrCreateNbt());
return tet.primed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static void playDetonatorItemSound(PlayerEntity player)
minecraft.getSoundManager().play(new ThermalDetonatorItemSoundInstance(player));
}

public static void playFragmentationGrenadeItemSound(PlayerEntity player)
{
var minecraft = MinecraftClient.getInstance();
minecraft.getSoundManager().play(new FragmentationGrenadeItemSoundInstance(player));
}

public static void playDetonatorEntitySound(ThermalDetonatorEntity entity)
{
var minecraft = MinecraftClient.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,22 @@
import net.minecraft.sound.SoundCategory;

@Environment(EnvType.CLIENT)
public class ThermalDetonatorItemSoundInstance extends DopplerSoundInstance implements ISoftRepeatSound
public class ThermalDetonatorItemSoundInstance extends GrenadeItemSoundInstance implements ISoftRepeatSound
{
private final PlayerEntity player;

public ThermalDetonatorItemSoundInstance(PlayerEntity player)
{
super(player, SwgSounds.Explosives.THERMAL_DETONATOR_BEEP, SoundCategory.PLAYERS, SoundInstance.createRandom());
this.player = player;
this.repeat = true;
this.repeatDelay = 0;
this.volume = 0.75F;
this.x = (float)player.getX();
this.y = (float)player.getY();
this.z = (float)player.getZ();
super(player, SwgSounds.Explosives.THERMAL_DETONATOR_BEEP);
}

@Override
public boolean canPlay()
public boolean isItem(ItemStack stack)
{
return !this.player.isSilent();
}

@Override
public boolean shouldAlwaysPlay()
{
return true;
}

public PlayerEntity getPlayer()
{
return player;
}

@Override
public void tick()
{
super.tick();

if (this.player.isRemoved())
if (stack.getItem() instanceof ThermalDetonatorItem)
{
this.setDone();
return;
return true;
}

var foundDetonator = false;

if (player.getMainHandStack().getItem() instanceof ThermalDetonatorItem && isPrimed(player.getMainHandStack()))
foundDetonator = true;

if (!foundDetonator && player.getOffHandStack().getItem() instanceof ThermalDetonatorItem && isPrimed(player.getOffHandStack()))
foundDetonator = true;

if (!areConditionsMet(player))
{
this.setDone();
return;
}
if (foundDetonator)
volume = 0.75f;
else
volume = 0.25f;

this.x = (float)this.player.getX();
this.y = (float)this.player.getY();
this.z = (float)this.player.getZ();
}

public static boolean areConditionsMet(PlayerEntity player)
{
for (int i = 0; i < player.getInventory().size(); i++)
if (player.getInventory().getStack(i).getItem() instanceof ThermalDetonatorItem && isPrimed(player.getInventory().getStack(i)))
return true;
return false;
}

private static boolean isPrimed(ItemStack stack)
{
if (!(stack.getItem() instanceof ThermalDetonatorItem))
return false;

var tdt = new ThrowableExplosiveTag(stack.getOrCreateNbt());
return tdt.primed;
}
;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.parzivail.pswg.entity;

import com.parzivail.pswg.Resources;
import com.parzivail.pswg.block.FragmentationGrenadeBlock;
import com.parzivail.pswg.block.ThermalDetonatorBlock;
import com.parzivail.pswg.container.*;
import com.parzivail.pswg.features.lightsabers.LightsaberItem;
Expand Down Expand Up @@ -335,6 +336,10 @@ else if (state.getBlock() instanceof ThermalDetonatorBlock tdb)
{
tdb.explode(getWorld(), blockPos, 6f);
}
else if (state.getBlock() instanceof FragmentationGrenadeBlock fgb)
{
fgb.explode(getWorld(), blockPos, 6f);
}
else
{
// TODO: explosion power registry?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void tick()
});
for (LivingEntity entity : entities)
{
float x = (float)(entity.getX() - getX()) / 4f;
float z = (float)(entity.getZ() - getZ()) / 4f;
float x = (float)(entity.getX() - getX()) / 3f;
float z = (float)(entity.getZ() - getZ()) / 3f;
entity.addVelocity(-x, 0, -z);
}
}
Expand Down
Loading

0 comments on commit 7af3291

Please sign in to comment.