Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 24413be

Browse files
committed
basic laser gun working
1 parent e74649d commit 24413be

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.htmlcsjs.htmlTech.api.damagesources;
2+
3+
import net.minecraft.util.DamageSource;
4+
5+
public class HTDamageSources {
6+
private static final DamageSource LASER = new DamageSource("laser").setFireDamage();
7+
8+
public static DamageSource getLaserDamage() {
9+
return LASER;
10+
}
11+
}

src/main/java/net/htmlcsjs/htmlTech/common/HTConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ public class HTConfig {
1313
public static class LaserOptions {
1414
@Config.Comment({"Minimum tier of laser collectors.", "Default: 5 [IV]"})
1515
public int minLaserTier = 5;
16+
17+
@Config.Comment({"Amount of damage to do to an entity when it is hit by the laser gun", "Default: 10 (5 hearts)"})
18+
public float laserGunDamage = 10.0F;
1619
}
1720
}

src/main/java/net/htmlcsjs/htmlTech/common/item/HTMetaItem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import gregtech.api.items.metaitem.MetaItem;
77
import gregtech.api.items.metaitem.StandardMetaItem;
88
import gregtech.api.items.metaitem.stats.IItemBehaviour;
9+
import net.htmlcsjs.htmlTech.common.item.behaviors.LaserGunBehaviour;
910
import net.htmlcsjs.htmlTech.common.item.behaviors.LaserInspectorToolBehaviour;
1011
import net.minecraft.client.resources.I18n;
1112
import net.minecraft.client.util.ITooltipFlag;
@@ -23,8 +24,7 @@
2324
import java.util.Arrays;
2425
import java.util.List;
2526

26-
import static net.htmlcsjs.htmlTech.common.item.HTMetaItems.EMPTY_LASER;
27-
import static net.htmlcsjs.htmlTech.common.item.HTMetaItems.LASER_INSPECTOR;
27+
import static net.htmlcsjs.htmlTech.common.item.HTMetaItems.*;
2828

2929
public class HTMetaItem extends StandardMetaItem {
3030
public HTMetaItem(short offset) {
@@ -34,7 +34,7 @@ public HTMetaItem(short offset) {
3434
public void registerSubItems() {
3535
LASER_INSPECTOR = addItem(1, "tool.laser.inspector").addComponents(new LaserInspectorToolBehaviour()).setMaxStackSize(1);
3636
EMPTY_LASER = addItem(2, "empty_laser").setMaxStackSize(1);
37-
//LASER_GUN = addItem(3, "laser_gun").setMaxStackSize(1).addComponents(new LaserGunBehaviour());
37+
LASER_GUN = addItem(3, "laser_gun").setMaxStackSize(1).addComponents(new LaserGunBehaviour());
3838
}
3939

4040
@Override

src/main/java/net/htmlcsjs/htmlTech/common/item/behaviors/LaserGunBehaviour.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import gregtech.api.items.metaitem.stats.IItemBehaviour;
77
import gregtech.client.particle.GTLaserBeamParticle;
88
import gregtech.client.particle.GTParticleManager;
9+
import net.htmlcsjs.htmlTech.api.damagesources.HTDamageSources;
10+
import net.htmlcsjs.htmlTech.common.HTConfig;
911
import net.minecraft.entity.Entity;
1012
import net.minecraft.entity.EntityLivingBase;
1113
import net.minecraft.entity.player.EntityPlayer;
@@ -19,6 +21,7 @@
1921
public class LaserGunBehaviour implements IItemBehaviour {
2022

2123
private GTLaserBeamParticle particle;
24+
private float alpha; // TODO move to getter after ceu pr #800
2225

2326
@Override
2427
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
@@ -27,11 +30,17 @@ public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player
2730
if (particle != null) {
2831
GTParticleManager.INSTANCE.clearAllEffects(true);
2932
}
33+
alpha = 1.0F;
3034
particle = new GTLaserBeamParticle(world, Vector3.fromEntity(player).add(0, player.getEyeHeight(), 0), Vector3.fromEntity(player).subtract(new Vector3(rayTracedLooking.hitVec)))
3135
.setBody(new ResourceLocation(GTValues.MODID, "textures/fx/laser/laser.png")); // create a beam particle and set its texture.
3236
GTParticleManager.INSTANCE.addEffect(particle); // add it to the particle manager.
3337
ItemStack itemStack = player.getHeldItem(hand);
34-
return ActionResult.newResult(EnumActionResult.PASS, itemStack);
38+
39+
if (rayTracedLooking.typeOfHit == RayTraceResult.Type.ENTITY && rayTracedLooking.entityHit != null) {
40+
rayTracedLooking.entityHit.attackEntityFrom(HTDamageSources.getLaserDamage(), HTConfig.lasers.laserGunDamage);
41+
}
42+
43+
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
3544
}
3645

3746
/**
@@ -116,4 +125,13 @@ private RayTraceResult rayTrace(EntityLivingBase entity, double reachDistance, f
116125
}
117126
}
118127

128+
@Override
129+
public void onUpdate(ItemStack itemStack, Entity entity) {
130+
if (alpha > 0) {
131+
alpha -= 0.05F;
132+
if (particle != null) {
133+
particle.setAlpha(alpha);
134+
}
135+
}
136+
}
119137
}

0 commit comments

Comments
 (0)