Skip to content

Commit

Permalink
Merge remote-tracking branch 'Gordon-Frohman/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed May 31, 2024
2 parents 45af289 + 7f029d5 commit ba128f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/main/java/twilightforest/TFCommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,6 @@ public boolean checkForSound(ChunkCoordinates chunkcoordinates) {
return true;
}

public void stopSound(World worldIn, int x, int y, int z) {}

}
30 changes: 7 additions & 23 deletions src/main/java/twilightforest/block/BlockTFCicada.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package twilightforest.block;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;

import twilightforest.TwilightForestMod;
import twilightforest.tileentity.TileEntityTFCicada;

public class BlockTFCicada extends BlockTFCritter {
Expand All @@ -33,13 +31,13 @@ public TileEntity createTileEntity(World world, int metadata) {
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
super.onEntityCollidedWithBlock(world, x, y, z, entity);
// stopSinging(worldIn, x, y, z);
// TwilightForestMod.proxy.stopSound(worldIn, x, y, z);
}

@Override
public boolean dropCritterIfCantStay(World world, int x, int y, int z) {
if (super.dropCritterIfCantStay(world, x, y, z)) {
stopSinging(world, x, y, z);
TwilightForestMod.proxy.stopSound(world, x, y, z);
return true;
}
return false;
Expand All @@ -49,21 +47,21 @@ public boolean dropCritterIfCantStay(World world, int x, int y, int z) {
* Called when the block is attempted to be harvested
*/
public void onBlockHarvested(World worldIn, int x, int y, int z, int meta, EntityPlayer player) {
stopSinging(worldIn, x, y, z);
TwilightForestMod.proxy.stopSound(worldIn, x, y, z);
}

/**
* Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
*/
public void onBlockDestroyedByPlayer(World worldIn, int x, int y, int z, int meta) {
stopSinging(worldIn, x, y, z);
TwilightForestMod.proxy.stopSound(worldIn, x, y, z);
}

/**
* Called upon the block being destroyed by an explosion
*/
public void onBlockDestroyedByExplosion(World worldIn, int x, int y, int z, Explosion explosionIn) {
stopSinging(worldIn, x, y, z);
TwilightForestMod.proxy.stopSound(worldIn, x, y, z);
}

/**
Expand All @@ -72,24 +70,10 @@ public void onBlockDestroyedByExplosion(World worldIn, int x, int y, int z, Expl
public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (super.onBlockActivated(worldIn, x, y, z, player, side, subX, subY, subZ)) {
stopSinging(worldIn, x, y, z);
TwilightForestMod.proxy.stopSound(worldIn, x, y, z);
return true;
}
return false;
}

public void stopSinging(World worldIn, int x, int y, int z) {
if (worldIn.isRemote) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(x, y, z);
Minecraft mc = Minecraft.getMinecraft();
ISound isound = (ISound) mc.renderGlobal.mapSoundPositions.get(chunkcoordinates);

while (isound != null) {
mc.getSoundHandler().stopSound(isound);
mc.renderGlobal.mapSoundPositions.remove(chunkcoordinates);
isound = (ISound) mc.renderGlobal.mapSoundPositions.get(chunkcoordinates);
}
}
}

}
12 changes: 12 additions & 0 deletions src/main/java/twilightforest/client/TFClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -863,4 +863,16 @@ public boolean checkForSound(ChunkCoordinates chunkcoordinates) {
return isound != null;
}

public void stopSound(World worldIn, int x, int y, int z) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(x, y, z);
Minecraft mc = Minecraft.getMinecraft();
ISound isound = (ISound) mc.renderGlobal.mapSoundPositions.get(chunkcoordinates);

while (isound != null) {
mc.getSoundHandler().stopSound(isound);
mc.renderGlobal.mapSoundPositions.remove(chunkcoordinates);
isound = (ISound) mc.renderGlobal.mapSoundPositions.get(chunkcoordinates);
}
}

}

0 comments on commit ba128f4

Please sign in to comment.