Skip to content

Commit

Permalink
Gas entity, damage type and effect
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jan 22, 2025
1 parent 70f68f8 commit ba678ae
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.render.entity.EmptyEntityRenderer;

/**
* The main entrypoint for PSWG client-side gadget features
Expand All @@ -23,6 +24,7 @@ public void onGalaxiesClientReady()
EntityModelLayerRegistry.registerModelLayer(FragmentationGrenadeEntityRenderer.MODEL_LAYER, FragmentationGrenadeEntityRenderer.Model::getTexturedModelData);
EntityRendererRegistry.register(Gadgets.NERVE_GAS_GRENADE_ENTITY, NerveGasGrenadeEntityRenderer::new);
EntityModelLayerRegistry.registerModelLayer(NerveGasGrenadeEntityRenderer.MODEL_LAYER, NerveGasGrenadeEntityRenderer.Model::getTexturedModelData);
EntityRendererRegistry.register(Gadgets.NERVE_GAS, EmptyEntityRenderer::new);

ParticleFactoryRegistry.getInstance().register(Gadgets.EXPLOSION_SMOKE_PARTICLE, ExplosionSmokeParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(Gadgets.FRAGMENTATION_GRENADE_SPARK_PARTICLE, FragmentationGrenadeSparkParticle.Factory::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void generateItemModels(ItemModelGenerator itemModelGenerator)
{
register(itemModelGenerator, Gadgets.THERMAL_DETONATOR_ITEM, Galaxies.id("item/wizard"), Models.GENERATED);
register(itemModelGenerator, Gadgets.FRAGMENTATION_GRENADE_ITEM, Galaxies.id("item/wizard"), Models.GENERATED);
register(itemModelGenerator, Gadgets.NERVE_GAS_GRENADE_ITEM, Galaxies.id("item/wizard"), Models.GENERATED);
}
}

Expand Down Expand Up @@ -84,6 +85,8 @@ public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, T
translationBuilder.add("subtitle.pswg_gadgets.fragmentationgrenade.explode", "C25 Grenade Explosion");
translationBuilder.add("subtitle.pswg_gadgets.thermaldetonator.explode", "Thermal Detonator Explosion");

translationBuilder.add("effect.pswg_gadgets.intoxicated", "Intoxicated");

}
}

Expand All @@ -103,7 +106,8 @@ protected void configure(RegistryWrapper.WrapperLookup wrapperLookup)
{
getOrCreateTagBuilder(Gadgets.GRENADES_TAG)
.add(Gadgets.THERMAL_DETONATOR_ITEM)
.add(Gadgets.FRAGMENTATION_GRENADE_ITEM);
.add(Gadgets.FRAGMENTATION_GRENADE_ITEM)
.add(Gadgets.NERVE_GAS_GRENADE_ITEM);
}
}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "pswg_gadgets:item/nerve_gas_grenade"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"effect.pswg_gadgets.intoxicated": "Intoxicated",
"item.pswg_gadgets.fragmentation_grenade": "Fragmentation Grenade",
"item.pswg_gadgets.thermal_detonator": "Thermal Detonator",
"subtitle.pswg_gadgets.fragmentationgrenade.explode": "C25 Grenade Explosion",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "pswg:item/wizard"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"minecraft:red_mushroom",
"minecraft:dead_bush",
"minecraft:short_grass",
"minecraft:tall_grass"
"minecraft:tall_grass",
"minecraft:snow"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"values": [
"pswg_gadgets:thermal_detonator",
"pswg_gadgets:fragmentation_grenade"
"pswg_gadgets:fragmentation_grenade",
"pswg_gadgets:nerve_gas_grenade"
]
}
26 changes: 25 additions & 1 deletion projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import dev.pswg.block.FragmentationGrenadeBlock;
import dev.pswg.block.ThermalDetonatorBlock;
import dev.pswg.entity.FragmentationGrenadeEntity;
import dev.pswg.entity.NerveGasEntity;
import dev.pswg.entity.NerveGasGrenadeEntity;
import dev.pswg.entity.ThermalDetonatorEntity;
import dev.pswg.entity.effects.IntoxicatedEffect;
import dev.pswg.item.FragmentationGrenadeItem;
import dev.pswg.item.NerveGasGrenadeItem;
import dev.pswg.item.ThermalDetonatorItem;
Expand All @@ -17,15 +19,20 @@
import net.minecraft.component.ComponentType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.slf4j.Logger;

/**
Expand Down Expand Up @@ -79,6 +86,14 @@ public static Identifier id(String path)
.spawnBoxScale(0.2f)
.dropsNothing()

);
public static final EntityType<NerveGasEntity> NERVE_GAS = Registrar.entityType(
id("nerve_gas"),
EntityType.Builder.create(NerveGasEntity::new, SpawnGroup.MISC)
.dimensions(6f, 3f)
.spawnBoxScale(0.2f)
.dropsNothing()

);

public static final ComponentType<Long> PRIMING_TIME = Registry.register(
Expand All @@ -101,6 +116,10 @@ public static Identifier id(String path)

public static final TagKey<DamageType> IGNITES_EXPLOSIVES = TagKey.of(RegistryKeys.DAMAGE_TYPE, id("ignites_explosives"));

public static final RegistryKey<DamageType> NERVE_GAS_DAMAGE_TYPE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, id("nerve_gas"));

public static final RegistryEntry<StatusEffect> INTOXICATED = Registry.registerReference(Registries.STATUS_EFFECT, id("intoxicated"), new IntoxicatedEffect());

public static final SimpleParticleType EXPLOSION_SMOKE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("explosion_smoke"), FabricParticleTypes.simple());
public static final SimpleParticleType FRAGMENTATION_GRENADE_SPARK_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_spark"), FabricParticleTypes.simple());
public static final SimpleParticleType FRAGMENTATION_GRENADE_WAVE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_wave"), FabricParticleTypes.simple());
Expand All @@ -123,6 +142,11 @@ private static SoundEvent registerSound(Identifier id)
return Registry.register(Registries.SOUND_EVENT, id, SoundEvent.of(id));
}

public static DamageSource create(World world, RegistryKey<DamageType> key)
{
return new DamageSource(world.getRegistryManager().getOrThrow(RegistryKeys.DAMAGE_TYPE).getOrThrow(key));
}

@Override
public void onGalaxiesReady()
{
Expand All @@ -132,4 +156,4 @@ public void onGalaxiesReady()

LOGGER.info("Module initialized");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
package dev.pswg.entity;

import dev.pswg.Gadgets;
import dev.pswg.world.TickConstants;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.*;

public class NerveGasEntity extends Entity
{
public Map<LivingEntity, Integer> toxicityIndex;

public NerveGasEntity(EntityType<?> type, World world)
{
super(type, world);
toxicityIndex = HashMap.newHashMap(1024);
}

@Override
protected void initDataTracker(DataTracker.Builder builder)
{

}

@Override
Expand All @@ -31,18 +43,57 @@ public boolean damage(ServerWorld world, DamageSource source, float amount)
@Override
protected void readCustomDataFromNbt(NbtCompound nbt)
{

}

@Override
protected void writeCustomDataToNbt(NbtCompound nbt)
{
}

@Override
public boolean hasNoGravity()
{
return true;
}

@Override
public void tick()
{
if (age > 850)
this.discard();
var entities = getWorld().getNonSpectatingEntities(LivingEntity.class, this.getBoundingBox());
for (LivingEntity entity : entities)
{
if (toxicityIndex.containsKey(entity))
toxicityIndex.replace(entity, toxicityIndex.get(entity) + 1);
else
toxicityIndex.put(entity, 5);
}
List<LivingEntity> decrement = new ArrayList<>(1024);
toxicityIndex.forEach((livingEntity, integer) -> {
if (!entities.contains(livingEntity))
decrement.add(livingEntity);
});
for (LivingEntity entity : decrement)
{
toxicityIndex.replace(entity, (int)(toxicityIndex.get(entity) - 3f));
if (toxicityIndex.get(entity) <= 3)
toxicityIndex.remove(entity);
}
if (getWorld() instanceof ServerWorld serverWorld)
toxicityIndex.forEach((livingEntity, integer) -> {
int amplifier = integer / 50 - 1;
if (livingEntity.hasStatusEffect(Gadgets.INTOXICATED))
{
if (livingEntity.getStatusEffect(Gadgets.INTOXICATED).getAmplifier() != amplifier)
{
livingEntity.setStatusEffect(new StatusEffectInstance(Gadgets.INTOXICATED, TickConstants.ONE_DAY * 10, amplifier, false, false, true), this);
}
}
else
livingEntity.addStatusEffect(new StatusEffectInstance(Gadgets.INTOXICATED, TickConstants.ONE_DAY * 10, amplifier, false, false, true), this);
});

super.tick();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import dev.pswg.Gadgets;
import dev.pswg.item.GrenadeItem;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class NerveGasGrenadeEntity extends GrenadeEntity
Expand All @@ -22,15 +25,17 @@ public NerveGasGrenadeEntity(EntityType<? extends ThrownEntity> entityType, Worl
@Override
public GrenadeItem getItem()
{
return null;
return Gadgets.NERVE_GAS_GRENADE_ITEM;
}

@Override
public void explode()
{
NerveGasEntity gasEntity = Gadgets.NERVE_GAS.create(getWorld(), SpawnReason.TRIGGERED);
gasEntity.setPosition(getX(), getY(), getZ());
EXPELLING_GAS = true;
getWorld().spawnEntity(gasEntity);
}

@Override
protected void onCollision(HitResult hitResult)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.pswg.entity.effects;

import dev.pswg.Gadgets;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;

public class IntoxicatedEffect extends StatusEffect
{
public IntoxicatedEffect()
{
super(StatusEffectCategory.HARMFUL, 100000);
}

@Override
public boolean canApplyUpdateEffect(int duration, int amplifier)
{
return true;
}

@Override
public void onApplied(LivingEntity entity, int amplifier)
{
addAttributeModifier(EntityAttributes.MOVEMENT_SPEED, Identifier.of("intoxicated"), -amplifier / 100f, EntityAttributeModifier.Operation.ADD_VALUE);
super.onApplied(entity, amplifier);
}

@Override
public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier)
{
return entity.damage(world, Gadgets.create(world, Gadgets.NERVE_GAS_DAMAGE_TYPE), (amplifier) / 8f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"pswg_gadgets:nerve_gas"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"pswg_gadgets:nerve_gas"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"pswg_gadgets:nerve_gas"
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"pswg_gadgets:nerve_gas"
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"exhaustion" : 0,
"death_message_type" : "default",
"message_id": "nerve_gas",
"scaling": "never"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"replace": false,
"values": [
"minecraft:campfire",
"minecraft:dragon_breath",
"minecraft:explosion",
"minecraft:fireball",
"minecraft:fireworks",
"minecraft:hot_floor",
"minecraft:in_fire",
"minecraft:lava",
"minecraft:lightning_bolt",
"minecraft:on_fire",
"minecraft:sonic_boom"
]
}

0 comments on commit ba678ae

Please sign in to comment.