-
-
Save TheRealMcrafter/9f460f45db6b094097b3 to your computer and use it in GitHub Desktop.
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
package TheRealMcrafter.SirenMod.tiles; | |
import java.util.List; | |
import net.minecraft.entity.EntityCreature; | |
import net.minecraft.entity.ai.EntityAIPanic; | |
import net.minecraft.entity.passive.EntityVillager; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.EntityPlayerMP; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.network.NetworkManager; | |
import net.minecraft.network.Packet; | |
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.AxisAlignedBB; | |
import net.minecraft.util.DamageSource; | |
import TheRealMcrafter.SirenMod.ExtendedEntityProperties.ExtendedVillager; | |
import TheRealMcrafter.SirenMod.entity.ai.VillagerAIPanic; | |
import TheRealMcrafter.SirenMod.packet.SirenModPacketDispatcher; | |
import TheRealMcrafter.SirenMod.packet.SirenModPlayLoopedSoundMessage; | |
public class AmericanSignalT121TileEntity extends TileEntity{ | |
private boolean isPlaying = false; | |
private boolean shouldStart = false; | |
private boolean shouldStop = false; | |
public void updateEntity(){ | |
if (worldObj.isRemote) return; | |
if (!worldObj.isRemote){ | |
if (this.isPlaying){ | |
List l = this.worldObj.getEntitiesWithinAABB(EntityVillager.class, AxisAlignedBB.getBoundingBox(this.xCoord - 20, this.yCoord - 20, this.zCoord - 20, this.xCoord + 20, this.yCoord + 20, this.zCoord + 20)); | |
if (!l.isEmpty()){ | |
for (int i = 0; i < l.size(); i++){ | |
EntityVillager villager = (EntityVillager) l.get(i); | |
ExtendedVillager props = ExtendedVillager.get(villager); | |
props.setIsScared(true); | |
} | |
} | |
} | |
//*/ | |
if (!isPlaying && shouldStart){ | |
shouldStart = false; | |
shouldStop = false; | |
isPlaying = true; | |
this.updateClientRender(); | |
SirenModPacketDispatcher.sendToAllAround(new SirenModPlayLoopedSoundMessage(xCoord, yCoord, zCoord, "sirenT121"), this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50000000); | |
} | |
} | |
} | |
public void playSound(){ | |
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "sirenmod:sirenT121", 8.0F, 1.0F); | |
} | |
public void updateClientRender(){ | |
worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); | |
} | |
public boolean isShouldStop(){ | |
return shouldStop;} | |
public void setShouldStart(boolean shouldStart){ | |
if (shouldStart == true){ | |
this.shouldStop = false; | |
} else { | |
this.shouldStop = true; | |
} | |
this.shouldStart = shouldStart; | |
this.updateClientRender(); | |
} | |
public void setShouldStop(boolean shouldStop){ | |
if (shouldStop){ | |
if (isPlaying){ | |
isPlaying = false; | |
this.shouldStop = true; | |
System.err.println("Should Stop"); | |
} | |
} else { | |
this.shouldStop = shouldStop; | |
} | |
//this.updateClientRender() just marks the blocks for update. More meaningful when I implement other features in the future | |
this.updateClientRender(); | |
} | |
public boolean isPlaying(){ | |
return isPlaying; | |
} | |
@Override | |
public void writeToNBT(NBTTagCompound nbt){ | |
super.writeToNBT(nbt); | |
nbt.setBoolean("shouldStop", this.shouldStop); | |
nbt.setBoolean("shouldStart", this.shouldStart); | |
nbt.setBoolean("isPlaying", this.isPlaying); | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound nbt){ | |
super.readFromNBT(nbt); | |
this.shouldStop = nbt.getBoolean("shouldStop"); | |
this.shouldStart = nbt.getBoolean("shouldStart"); | |
this.isPlaying = nbt.getBoolean("isPlaying"); | |
} | |
@Override | |
public Packet getDescriptionPacket() { | |
NBTTagCompound tileTag = new NBTTagCompound(); | |
this.writeToNBT(tileTag); | |
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tileTag); | |
} | |
@Override | |
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { | |
NBTTagCompound tag = packet.func_148857_g(); | |
readFromNBT(packet.func_148857_g()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment