Skip to content

Commit

Permalink
Thermal Detonator dispenser behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Dec 28, 2024
1 parent 3636d22 commit 3e72c75
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
3 changes: 3 additions & 0 deletions projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.pswg.registry.Registrar;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.block.Block;
import net.minecraft.block.DispenserBlock;
import net.minecraft.component.ComponentType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
Expand Down Expand Up @@ -72,11 +73,13 @@ public static Identifier id(String path)




@Override
public void onGalaxiesReady()
{
// TODO: how to differentiate different modules' versions?
Registry.register(Registries.PARTICLE_TYPE, Identifier.of(MODID, "explosion_smoke"), EXPLOSION_SMOKE_PARTICLE);
DispenserBlock.registerProjectileBehavior(Gadgets.THERMAL_DETONATOR_ITEM);
LOGGER.info("Module initialized");
}
}
39 changes: 32 additions & 7 deletions projects/pswg_gadgets/src/main/java/dev/pswg/item/GrenadeItem.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
package dev.pswg.item;

import dev.pswg.Gadgets;
import dev.pswg.entity.GrenadeEntity;
import dev.pswg.world.TickConstants;
import net.minecraft.block.Block;
import net.minecraft.block.DispenserBlock;
import net.minecraft.component.type.ConsumableComponents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.*;
import net.minecraft.item.consume.UseAction;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class GrenadeItem extends BlockItem implements ILeftClickUsable
public class GrenadeItem extends Item implements ILeftClickUsable, ProjectileItem
{
public final int baseTicksToExplosion;
public final Block block;
public final Item item;
//public final ExplosionSoundGroup sounds;

public GrenadeItem(Settings settings, Block block, Item item, int baseTicksToExplosion)
public GrenadeItem(Item.Settings settings, Block block, Item item, int baseTicksToExplosion)
{
super(block, settings);
super(settings);
this.block = block;
this.item = item;
//this.sounds = sounds;
Expand Down Expand Up @@ -243,6 +248,26 @@ public ActionResult useLeft(World world, LivingEntity user, Hand hand)
return ActionResult.SUCCESS;
}

@Override
public ProjectileEntity createEntity(World world, Position pos, ItemStack stack, Direction direction)
{
return null;
}

@Override
public ProjectileItem.Settings getProjectileSettings()
{
return ProjectileItem.super.getProjectileSettings();
}

@Override
public void initializeProjectile(ProjectileEntity entity, double x, double y, double z, float power, float uncertainty)
{

//grenade.setLife();
ProjectileItem.super.initializeProjectile(entity, x, y, z, power, uncertainty);
}

/*
@Override
public boolean allowRepeatedLeftHold(World world, PlayerEntity player, Hand mainHand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class ThermalDetonatorItem extends GrenadeItem
{
public ThermalDetonatorItem(Settings settings)
public ThermalDetonatorItem(Item.Settings settings)
{
super(settings, Blocks.IRON_BLOCK, Gadgets.THERMAL_DETONATOR_ITEM, 150);
}
Expand Down Expand Up @@ -42,9 +46,20 @@ public void spawnEntity(World world, int power, ItemStack stack , Entity player)
ThermalDetonatorEntity td = new ThermalDetonatorEntity(Gadgets.THERMAL_DETONATOR_ENTITY, world);
//world.getTime() - baseTicksToExplosion
td.setLife(stack.contains(Gadgets.PRIMING_TIME) ? (int)(stack.get(Gadgets.PRIMING_TIME) + baseTicksToExplosion - world.getTime() ) : 1);
td.setPrimed(stack.contains(Gadgets.PRIMING_TIME) ? true : false );
td.setPrimed(stack.contains(Gadgets.PRIMING_TIME));
td.setExplosionPower(power);
td.onSpawnPacket(new EntitySpawnS2CPacket(td.getId(), td.getUuid(), player.getX(), player.getY() + 1, player.getZ(), -player.getPitch(), -player.getYaw(), td.getType(), 0, Vec3d.ZERO, player.getHeadYaw()));
world.spawnEntity(td);
}

@Override
public ProjectileEntity createEntity(World world, Position pos, ItemStack stack, Direction direction)
{
ThermalDetonatorEntity td = new ThermalDetonatorEntity(Gadgets.THERMAL_DETONATOR_ENTITY, world);
td.setLife(stack.contains(Gadgets.PRIMING_TIME) ? (int)(stack.get(Gadgets.PRIMING_TIME) + baseTicksToExplosion - world.getTime() ) : 1);
td.setPrimed(stack.contains(Gadgets.PRIMING_TIME));
td.setPos(pos.getX(), pos.getY(), pos.getZ());

return td;
}
}

0 comments on commit 3e72c75

Please sign in to comment.