Skip to content

Commit 4ede5d2

Browse files
committed
Dynamic laser colors
1 parent e07fbd3 commit 4ede5d2

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

src/main/java/de/ellpeck/nyx/client/renderer/NyxRendererLaser.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
@SideOnly(Side.CLIENT)
1515
public class NyxRendererLaser extends Render<NyxEntityLaser> {
16-
private static final ResourceLocation LASER = new ResourceLocation(Nyx.ID, "textures/entities/laser.png");
1716
private final NyxModelLaser model = new NyxModelLaser();
1817

1918
public NyxRendererLaser(RenderManager renderManager) {
@@ -22,28 +21,31 @@ public NyxRendererLaser(RenderManager renderManager) {
2221

2322
@Override
2423
public void doRender(NyxEntityLaser entity, double x, double y, double z, float entityYaw, float partialTicks) {
24+
int hexColor = entity.getLaserColor();
25+
26+
float r = (float) (hexColor >> 16 & 255) / 255.0F;
27+
float g = (float) (hexColor >> 8 & 255) / 255.0F;
28+
float b = (float) (hexColor & 255) / 255.0F;
29+
2530
GlStateManager.pushMatrix();
2631
GlStateManager.translate((float) x, (float) y + 0.1F, (float) z);
2732
GlStateManager.rotate(entityYaw, 0.0F, 1.0F, 0.0F);
2833
GlStateManager.rotate(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
29-
bindTexture(LASER);
30-
this.model.render();
31-
GlStateManager.enableBlend();
32-
GlStateManager.disableAlpha();
34+
GlStateManager.disableTexture2D();
35+
GlStateManager.disableLighting();
36+
GlStateManager.disableBlend();
3337
GlStateManager.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
34-
GlStateManager.depthMask(false);
3538
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F);
36-
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
39+
GlStateManager.color(r, g, b, 1.0F); // Laser color
3740
this.model.render();
38-
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, entity.getBrightnessForRender() % 65536, entity.getBrightnessForRender() / 65536);
39-
GlStateManager.depthMask(true);
40-
GlStateManager.disableBlend();
41-
GlStateManager.enableAlpha();
41+
GlStateManager.enableLighting();
42+
GlStateManager.enableTexture2D();
43+
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); // Reset color to white
4244
GlStateManager.popMatrix();
4345
}
4446

4547
@Override
4648
protected ResourceLocation getEntityTexture(NyxEntityLaser entity) {
47-
return LASER;
49+
return null;
4850
}
4951
}

src/main/java/de/ellpeck/nyx/entity/NyxEntityEyezor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void attackEntityWithRangedAttack(EntityLivingBase target, float distance
8181
double d1 = target.posX + target.motionX - this.posX;
8282
double d2 = d0 - this.posY;
8383
double d3 = target.posZ + target.motionZ - this.posZ;
84-
NyxEntityLaser laser = new NyxEntityLaser(this.world, this, 1.0F);
84+
NyxEntityLaser laser = new NyxEntityLaser(this.world, this, 1.0F, 6435325);
8585
laser.shoot(d1, d2, d3, 1.0F, 1.0F);
8686
this.world.playSound(null, this.posX, this.posY, this.posZ, NyxSoundEvents.RANDOM_LASER.getSoundEvent(), SoundCategory.HOSTILE, 1.0F, 0.8F + this.rand.nextFloat() * 0.4F);
8787
this.world.spawnEntity(laser);

src/main/java/de/ellpeck/nyx/entity/NyxEntityLaser.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
import net.minecraft.entity.EntityLivingBase;
55
import net.minecraft.entity.player.EntityPlayer;
66
import net.minecraft.entity.projectile.EntityThrowable;
7+
import net.minecraft.nbt.NBTTagCompound;
8+
import net.minecraft.network.datasync.DataParameter;
9+
import net.minecraft.network.datasync.DataSerializers;
10+
import net.minecraft.network.datasync.EntityDataManager;
711
import net.minecraft.util.DamageSource;
812
import net.minecraft.util.EnumParticleTypes;
913
import net.minecraft.util.math.RayTraceResult;
1014
import net.minecraft.world.World;
1115

16+
// TODO: Setup what effects the laser can do
1217
public class NyxEntityLaser extends EntityThrowable {
18+
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(NyxEntityLaser.class, DataSerializers.VARINT);
19+
1320
private float damage;
1421

1522
public NyxEntityLaser(World world) {
@@ -23,15 +30,42 @@ public NyxEntityLaser(World world, EntityLivingBase entity, float damageAmount)
2330
this.damage = damageAmount;
2431
}
2532

26-
public NyxEntityLaser(final World world, final double x, final double y, final double z) {
27-
super(world, x, y, z);
28-
}
29-
30-
public NyxEntityLaser(final World world, EntityPlayer player, float damageAmount) {
33+
// Sets another color, otherwise default to red
34+
public NyxEntityLaser(World world, EntityLivingBase player, float damageAmount, int color) {
3135
super(world, player);
3236
this.rotationPitch = -player.rotationPitch;
3337
this.rotationYaw = -player.rotationYaw;
3438
this.damage = damageAmount;
39+
this.setLaserColor(color);
40+
}
41+
42+
public NyxEntityLaser(final World world, final double x, final double y, final double z) {
43+
super(world, x, y, z);
44+
}
45+
46+
@Override
47+
protected void entityInit() {
48+
this.dataManager.register(COLOR, 0xFF0000);
49+
}
50+
51+
public void setLaserColor(int color) {
52+
this.dataManager.set(COLOR, color);
53+
}
54+
55+
public int getLaserColor() {
56+
return this.dataManager.get(COLOR);
57+
}
58+
59+
@Override
60+
public void readEntityFromNBT(NBTTagCompound compound) {
61+
if (compound.hasKey("LaserColor")) {
62+
setLaserColor(compound.getInteger("LaserColor"));
63+
}
64+
}
65+
66+
@Override
67+
public void writeEntityToNBT(NBTTagCompound compound) {
68+
compound.setInteger("LaserColor", getLaserColor());
3569
}
3670

3771
@Override
-2.72 KB
Binary file not shown.

0 commit comments

Comments
 (0)