-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Almost) Working sounds for thermal detonator,
Beggining on placeble thermal detonator
- Loading branch information
1 parent
f0d2f07
commit 9ade2be
Showing
21 changed files
with
408 additions
and
20 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
projects/pswg/src/main/java/com/parzivail/pswg/block/ThermalDetonatorBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.parzivail.pswg.block; | ||
|
||
import com.parzivail.pswg.container.SwgEntities; | ||
import com.parzivail.pswg.entity.BlasterBoltEntity; | ||
import com.parzivail.pswg.entity.ThermalDetonatorEntity; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.ArrowEntity; | ||
import net.minecraft.entity.projectile.ProjectileEntity; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.explosion.Explosion; | ||
|
||
public class ThermalDetonatorBlock extends Block | ||
{ | ||
|
||
public ThermalDetonatorBlock(Settings settings) | ||
{ | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) | ||
{ | ||
if (entity instanceof BlasterBoltEntity) | ||
{ | ||
var tde = new ThermalDetonatorEntity(SwgEntities.Misc.ThermalDetonator, world); | ||
tde.setPos(pos.getX(), pos.getY(), pos.getZ()); | ||
tde.setPrimed(true); | ||
tde.setLife(0); | ||
world.spawnEntity(tde); | ||
} | ||
if (entity instanceof PlayerEntity player) | ||
{ | ||
player.sendMessage(Text.of("IHATEYOU"), true); | ||
} | ||
super.onEntityCollision(state, world, pos, entity); | ||
} | ||
|
||
@Override | ||
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) | ||
{ | ||
if (projectile instanceof BlasterBoltEntity bbe) | ||
{ | ||
explode(world, hit.getBlockPos()); | ||
} | ||
super.onProjectileHit(world, state, hit, projectile); | ||
} | ||
|
||
@Override | ||
public void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) | ||
{ | ||
explode(world, pos); | ||
super.onDestroyedByExplosion(world, pos, explosion); | ||
} | ||
|
||
public void explode(World world, BlockPos blockPos) | ||
{ | ||
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL | Block.REDRAW_ON_MAIN_THREAD); | ||
var tde = new ThermalDetonatorEntity(SwgEntities.Misc.ThermalDetonator, world); | ||
tde.setPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()); | ||
tde.setPrimed(true); | ||
tde.setLife(0); | ||
|
||
world.spawnEntity(tde); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...wg/src/main/java/com/parzivail/pswg/client/sound/ThermalDetonatorEntitySoundInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.parzivail.pswg.client.sound; | ||
|
||
import com.parzivail.pswg.container.SwgSounds; | ||
import com.parzivail.pswg.entity.ThermalDetonatorEntity; | ||
import com.parzivail.pswg.item.ThermalDetonatorItem; | ||
import com.parzivail.pswg.item.ThermalDetonatorTag; | ||
import com.parzivail.util.sound.DopplerSoundInstance; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.sound.MovingSoundInstance; | ||
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.text.Text; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ThermalDetonatorEntitySoundInstance extends MovingSoundInstance | ||
{ | ||
private final ThermalDetonatorEntity detonatorEntity; | ||
|
||
public ThermalDetonatorEntitySoundInstance(ThermalDetonatorEntity detonatorEntity) | ||
{ | ||
super(SwgSounds.Explosives.THERMAL_DETONATOR_BEEP, SoundCategory.PLAYERS, SoundInstance.createRandom()); | ||
this.detonatorEntity = detonatorEntity; | ||
this.repeat = true; | ||
this.repeatDelay = 0; | ||
this.volume = 1F; | ||
this.x = (float)detonatorEntity.getX(); | ||
this.y = (float)detonatorEntity.getY(); | ||
this.z = (float)detonatorEntity.getZ(); | ||
} | ||
|
||
@Override | ||
public void tick() | ||
{ | ||
|
||
if (detonatorEntity.isRemoved() || !areConditionsMet(detonatorEntity)) | ||
{ | ||
setDone(); | ||
return; | ||
} | ||
x = (float)this.detonatorEntity.getX(); | ||
y = (float)this.detonatorEntity.getY(); | ||
z = (float)this.detonatorEntity.getZ(); | ||
float distanceToPlayer32 = 32; | ||
if (detonatorEntity.getWorld().getClosestPlayer(detonatorEntity, 32) != null) | ||
{ | ||
distanceToPlayer32 = detonatorEntity.getWorld().getClosestPlayer(detonatorEntity, 32).distanceTo(detonatorEntity); | ||
} | ||
volume = ((32 - distanceToPlayer32) / 32); | ||
//detonatorEntity.getWorld().getClosestPlayer(detonatorEntity, 32).sendMessage(Text.of(""+volume), true); | ||
|
||
} | ||
|
||
public static boolean areConditionsMet(ThermalDetonatorEntity tde) | ||
{ | ||
if (tde.isPrimed()) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...pswg/src/main/java/com/parzivail/pswg/client/sound/ThermalDetonatorItemSoundInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.parzivail.pswg.client.sound; | ||
|
||
import com.parzivail.pswg.container.SwgSounds; | ||
import com.parzivail.pswg.features.lightsabers.LightsaberItem; | ||
import com.parzivail.pswg.features.lightsabers.data.LightsaberTag; | ||
import com.parzivail.pswg.item.ThermalDetonatorItem; | ||
import com.parzivail.pswg.item.ThermalDetonatorTag; | ||
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; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ThermalDetonatorItemSoundInstance extends DopplerSoundInstance | ||
{ | ||
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(); | ||
} | ||
|
||
@Override | ||
public boolean canPlay() | ||
{ | ||
return !this.player.isSilent(); | ||
} | ||
|
||
@Override | ||
public boolean shouldAlwaysPlay() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public void tick() | ||
{ | ||
super.tick(); | ||
|
||
if (this.player.isRemoved()) | ||
{ | ||
this.setDone(); | ||
return; | ||
} | ||
|
||
var foundDetonator = false; | ||
|
||
if (player.getMainHandStack().getItem() instanceof ThermalDetonatorItem) | ||
foundDetonator = true; | ||
|
||
if (!foundDetonator && player.getOffHandStack().getItem() instanceof ThermalDetonatorItem) | ||
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) | ||
{ | ||
//return isPrimed(player.getMainHandStack()) || isPrimed(player.getOffHandStack()); | ||
for (int i = 0; i < player.getInventory().size(); i++) | ||
if (player.getInventory().getStack(i).getItem() instanceof ThermalDetonatorItem) | ||
{ | ||
return isPrimed(player.getInventory().getStack(i)); | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean isPrimed(ItemStack stack) | ||
{ | ||
if (!(stack.getItem() instanceof ThermalDetonatorItem)) | ||
return false; | ||
|
||
var tdt = new ThermalDetonatorTag(stack.getOrCreateNbt()); | ||
return tdt.primed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.