Improve active sound, add teleport sound, fix sync issues

This commit is contained in:
tterrag1098 committed 2015-02-28 14:45:20 -05:00
1 parent 96273cede4
commit d5abaa8003
9 files changed
+279 -27

No files matched your search

@@ -1,5 +1,6 @@
package crazypants.enderio.api.teleport;
import crazypants.enderio.EnderIO;
import crazypants.enderio.config.Config;
public enum TravelSource {
@@ -7,7 +8,7 @@ public enum TravelSource {
BLOCK(0, Config.travelAnchorMaxDistance),
STAFF(Config.travelStaffPowerPerBlockRF, Config.travelStaffMaxDistance),
STAFF_BLINK(Config.travelStaffPowerPerBlockRF, Config.travelStaffMaxBlinkDistance),
TELEPAD(0, 0);
TELEPAD(0, 0, EnderIO.MODID + ":telepad.teleport");
public static int getMaxDistance() {
return STAFF.maxDistanceTravelledSq;
@@ -20,11 +21,17 @@ public enum TravelSource {
public final float powerCostPerBlockTraveledRF;
public final int maxDistanceTravelled;
public final int maxDistanceTravelledSq;
public final String sound;
private TravelSource(float powerCostPerBlockTraveled, int maxDistanceTravelled) {
this(powerCostPerBlockTraveled, maxDistanceTravelled, "mob.endermen.portal");
}
private TravelSource(float powerCostPerBlockTraveled, int maxDistanceTravelled, String sound) {
this.powerCostPerBlockTraveledRF = powerCostPerBlockTraveled;
this.maxDistanceTravelled = maxDistanceTravelled;
maxDistanceTravelledSq = maxDistanceTravelled * maxDistanceTravelled;
this.sound = sound;
}
public boolean getConserveMomentum() {
@@ -612,7 +612,7 @@ public class TravelController {
}
return TravelSource.BLOCK.maxDistanceTravelledSq;
}
public boolean doClientTeleport(Entity entity, BlockCoord bc, TravelSource source, int powerUse, boolean conserveMomentum) {
TeleportEntityEvent evt = new TeleportEntityEvent(entity, source, bc.x, bc.y, bc.z);
@@ -0,0 +1,217 @@
package crazypants.enderio.teleport.anchor;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL14;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.api.teleport.ITravelAccessable;
import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.teleport.TravelController;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.RenderUtil;
import crazypants.util.BlockCoord;
import crazypants.util.Util;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vector4f;
@SideOnly(Side.CLIENT)
public class TravelEntitySpecialRenderer extends TileEntitySpecialRenderer {
private final Vector4f selectedColor;
private final Vector4f highlightColor;
public TravelEntitySpecialRenderer() {
this(new Vector4f(1, 0.25f, 0, 0.5f), new Vector4f(1, 1, 1, 0.25f));
}
public TravelEntitySpecialRenderer(Vector4f selectedColor, Vector4f highlightColor) {
this.selectedColor = selectedColor;
this.highlightColor = highlightColor;
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
if(!TravelController.instance.showTargets()) {
return;
}
ITravelAccessable ta = (ITravelAccessable) tileentity;
if(!ta.canSeeBlock(Minecraft.getMinecraft().thePlayer)) {
return;
}
Vector3d eye = Util.getEyePositionEio(Minecraft.getMinecraft().thePlayer);
Vector3d loc = new Vector3d(tileentity.xCoord + 0.5, tileentity.yCoord + 0.5, tileentity.zCoord + 0.5);
double maxDistance = TravelController.instance.isTravelItemActive(Minecraft.getMinecraft().thePlayer) ? TravelSource.STAFF.maxDistanceTravelledSq
: TravelSource.BLOCK.maxDistanceTravelledSq;
if(eye.distanceSquared(loc) > maxDistance) {
return;
}
double sf = TravelController.instance.getScaleForCandidate(loc);
BlockCoord bc = new BlockCoord(tileentity);
TravelController.instance.addCandidate(bc);
Minecraft.getMinecraft().entityRenderer.disableLightmap(0);
RenderUtil.bindBlockTexture();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glColor3f(1, 1, 1);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
Tessellator.instance.startDrawingQuads();
renderBlock(sf);
Tessellator.instance.draw();
Tessellator.instance.startDrawingQuads();
Tessellator.instance.setBrightness(15 << 20 | 15 << 4);
if(TravelController.instance.isBlockSelected(bc)) {
Tessellator.instance.setColorRGBA_F(selectedColor.x, selectedColor.y, selectedColor.z, selectedColor.w);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(sf + 0.05, sf + 0.05, sf + 0.05), getSelectedIcon());
} else {
Tessellator.instance.setColorRGBA_F(highlightColor.x, highlightColor.y, highlightColor.z, highlightColor.w);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(sf + 0.05, sf + 0.05, sf + 0.05), getHighlightIcon());
}
Tessellator.instance.draw();
GL11.glPopMatrix();
renderLabel(tileentity, x, y, z, ta, sf);
GL11.glPopAttrib();
GL11.glPopAttrib();
Minecraft.getMinecraft().entityRenderer.enableLightmap(0);
}
private void renderLabel(TileEntity tileentity, double x, double y, double z, ITravelAccessable ta, double sf) {
float globalScale = (float) sf;
ItemStack itemLabel = ta.getItemLabel();
if(itemLabel != null && itemLabel.getItem() != null) {
boolean isBlock = false;
Block block = Block.getBlockFromItem(itemLabel.getItem());
if(block != null && block != Blocks.air) {
isBlock = true;
}
float alpha = 0.5f;
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_COLOR);
float col = 0.5f;
GL14.glBlendColor(col, col, col, col);
GL11.glColor4f(1, 1, 1, 1);
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
if(!isBlock) {
GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);
}
{
GL11.glPushMatrix();
GL11.glScalef(globalScale, globalScale, globalScale);
{
GL11.glPushMatrix();
if(isBlock) {
GL11.glTranslatef(0f, -0.25f, 0);
} else {
GL11.glTranslatef(0f, -0.5f, 0);
}
GL11.glScalef(2, 2, 2);
EntityItem ei = new EntityItem(tileentity.getWorldObj(), x, y, z, itemLabel);
ei.age = 0;
ei.hoverStart = 0;
RenderManager.instance.getEntityRenderObject(ei).doRender(ei, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
}
String toRender = ta.getLabel();
if(toRender != null && toRender.trim().length() > 0) {
GL11.glColor4f(1, 1, 1, 1);
Vector4f bgCol = RenderUtil.DEFAULT_TEXT_BG_COL;
if(TravelController.instance.isBlockSelected(new BlockCoord(tileentity))) {
bgCol = new Vector4f(selectedColor.x, selectedColor.y, selectedColor.z, selectedColor.w);
}
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
{
GL11.glPushMatrix();
GL11.glScalef(globalScale, globalScale, globalScale);
Vector3f pos = new Vector3f(0, 1.2f, 0);
float size = 0.5f;
RenderUtil.drawBillboardedText(pos, toRender, size, bgCol);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
}
}
protected void renderBlock(double sf) {
Tessellator.instance.setColorRGBA_F(1, 1, 1, 0.75f);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(sf, sf, sf), EnderIO.blockTravelPlatform.getIcon(0, 0));
}
public Vector4f getSelectedColor() {
return selectedColor;
}
public IIcon getSelectedIcon() {
return EnderIO.blockTravelPlatform.selectedOverlayIcon;
}
public Vector4f getHighlightColor() {
return highlightColor;
}
public IIcon getHighlightIcon() {
return EnderIO.blockTravelPlatform.highlightOverlayIcon;
}
}
@@ -67,19 +67,20 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
int x = message.x, y = message.y, z = message.z;
TeleportEntityEvent evt = new TeleportEntityEvent(toTp, TravelSource.values()[message.source], x, y, z);
TravelSource source = TravelSource.values()[message.source];
TeleportEntityEvent evt = new TeleportEntityEvent(toTp, source, x, y, z);
if(!MinecraftForge.EVENT_BUS.post(evt)) {
doServerTeleport(toTp, x, y, z, message.powerUse, message.conserveMotion);
doServerTeleport(toTp, x, y, z, message.powerUse, message.conserveMotion, source);
}
return null;
}
public static boolean doServerTeleport(Entity toTp, int x, int y, int z, int powerUse, boolean conserveMotion) {
public static boolean doServerTeleport(Entity toTp, int x, int y, int z, int powerUse, boolean conserveMotion, TravelSource source) {
EntityPlayer player = toTp instanceof EntityPlayer ? (EntityPlayer) toTp : null;
toTp.worldObj.playSoundEffect(toTp.posX, toTp.posY, toTp.posZ, "mob.endermen.portal", 1.0F, 1.0F);
toTp.worldObj.playSoundEffect(toTp.posX, toTp.posY, toTp.posZ, source.sound, 1.0F, 1.0F);
toTp.playSound("mob.endermen.portal", 1.0F, 1.0F);
toTp.playSound(source.sound, 1.0F, 1.0F);
if(player != null) {
player.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
@@ -87,7 +88,7 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
toTp.setPosition(x, y, z);
}
toTp.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
toTp.worldObj.playSoundEffect(x, y, z, source.sound, 1.0F, 1.0F);
toTp.fallDistance = 0;
if(player != null) {
@@ -108,13 +108,13 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
private String getPowerOutputLabel() {
return StatCollector.translateToLocal("enderio.gui.max");
}
protected int getPowerOutputValue() {
return 500;
return te.getUsage();
}
protected void updatePowerBarTooltip(List<String> text) {
text.add(getPowerOutputLabel() + PowerDisplayUtil.formatPower(getPowerOutputValue()) + " " + PowerDisplayUtil.abrevation()
text.add(getPowerOutputLabel() + " " + PowerDisplayUtil.formatPower(getPowerOutputValue()) + " " + PowerDisplayUtil.abrevation()
+ PowerDisplayUtil.perTickStr());
text.add(PowerDisplayUtil.formatStoredPower(te.getEnergyStored(), te.getMaxEnergyStored()));
}
@@ -138,10 +138,15 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
public void updateScreen() {
super.updateScreen();
}
@Override
protected void keyTyped(char par1, int par2) {
super.keyTyped(par1, par2);
for (TextFieldEIO tf : textFields) {
if("-".equals(tf.getText())) {
tf.setText("");
}
}
updateCoords();
}
@@ -4,6 +4,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Queue;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
@@ -59,7 +60,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
private int powerUsed;
private int maxPower;
private int lastSyncPowerUsed;
private static final ResourceLocation activeRes = AbstractMachineEntity.getSoundFor("telepad.active");
private MachineSound activeSound = null;
@@ -80,7 +81,8 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
activeSound = new MachineSound(activeRes, xCoord, yCoord, zCoord, 0.01f, 1);
playSound();
}
activeSound.setVolume(Math.min(activeSound.getVolume() + 0.01f, 0.5f));
activeSound.setVolume(Math.min(activeSound.getVolume() + 0.1f, 0.5f));
activeSound.setPitch(1 + getProgress());
} else if(!active() && activeSound != null) {
if(activeSound.getVolume() > 0) {
activeSound.setVolume(activeSound.getVolume() - 0.1f);
@@ -91,12 +93,11 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
}
} else {
if(active()) {
System.out.println(maxPower);
if(powerUsed >= maxPower) {
teleport(toTeleport.poll());
powerUsed = 0;
} else {
powerUsed += energy.extractEnergy(energy.getMaxExtract(), false);
powerUsed += energy.extractEnergy(getUsage(), false);
}
if(worldObj.getTotalWorldTime() % 5 == 0) {
updateQueuedEntities();
@@ -158,17 +159,12 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
master.updateConnectedState(false);
}
}
if(te != null) {
// manually call this to avoid infinite recursion
worldObj.getBlock(te.xCoord, te.yCoord, te.zCoord).onNeighborChange(worldObj, te.xCoord, te.yCoord, te.zCoord, xCoord, yCoord, zCoord);
}
}
}
if(isMaster() && !inNetwork) {
inNetwork = formNetwork();
updateBlock();
if(inNetwork) {
master = this;
if(target.equals(new BlockCoord())) {
target = new BlockCoord(this);
}
@@ -190,7 +186,9 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
te.master = this;
te.inNetwork = true;
te.updateBlock();
te.updateNeighborTEs();
}
this.master = this;
return true;
}
return false;
@@ -202,9 +200,11 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
for (BlockCoord c : getSurroundingCoords()) {
TileEntity te = c.getTileEntity(worldObj);
if(te instanceof TileTelePad) {
((TileTelePad) te).master = null;
((TileTelePad) te).inNetwork = false;
((TileTelePad) te).updateBlock();
TileTelePad telepad = (TileTelePad) te;
telepad.master = null;
telepad.inNetwork = false;
telepad.updateBlock();
telepad.updateNeighborTEs();
}
}
}
@@ -221,6 +221,17 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
return ret;
}
private void updateNeighborTEs() {
BlockCoord bc = new BlockCoord(this);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
BlockCoord neighbor = bc.getLocation(dir);
Block block = neighbor.getBlock(worldObj);
if(!(block instanceof BlockTelePad)) {
block.onNeighborChange(worldObj, neighbor.x, neighbor.y, neighbor.z, xCoord, yCoord, zCoord);
}
}
}
@Override
public boolean canUpdate() {
return true;
@@ -244,14 +255,14 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
@Override
public Packet getDescriptionPacket() {
S35PacketUpdateTileEntity pkt = (S35PacketUpdateTileEntity) super.getDescriptionPacket();
pkt.func_148857_g().setBoolean("inNetwork", inNetwork);
// pkt.func_148857_g().setBoolean("inNetwork", inNetwork);
return pkt;
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
this.inNetwork = pkt.func_148857_g().getBoolean("inNetwork");
// this.inNetwork = pkt.func_148857_g().getBoolean("inNetwork");
}
public int getPowerScaled(int scale) {
@@ -438,7 +449,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
if(entity.worldObj.isRemote) {
return TravelController.instance.doClientTeleport(entity, target, TravelSource.TELEPAD, 0, false);
} else {
if(PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false)) {
if(PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false, TravelSource.TELEPAD)) {
dequeueTeleport(entity);
return true;
}
@@ -505,4 +516,8 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
public int getMaxEnergyStored(ForgeDirection from) {
return inNetwork && master != null ? master == this ? energy.getMaxEnergyStored() : master.getMaxEnergyStored() : 0;
}
public int getUsage() {
return energy.getMaxReceive();
}
}