Skip to content

Commit

Permalink
Fragmentation grenade Item, Grenade Tag, Thermal Detonator Fixes & Re…
Browse files Browse the repository at this point in the history
…ndering
  • Loading branch information
DeltaHelios committed Jan 1, 2025
1 parent e5aa692 commit 1898b04
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public ItemTagGenerator(FabricDataOutput output, CompletableFuture<RegistryWrapp
@Override
protected void configure(RegistryWrapper.WrapperLookup wrapperLookup)
{

getOrCreateTagBuilder(Gadgets.GRENADES_TAG)
.add(Gadgets.THERMAL_DETONATOR_ITEM)
.add(Gadgets.FRAGMENTATION_GRENADE_ITEM);
}
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModelPartNames;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;

public class ThermalDetonatorEntityRenderer extends EntityRenderer<ThermalDetonatorEntity, ThermalDetonatorEntityRenderer.State>
{
Expand All @@ -29,13 +29,9 @@ public static TexturedModelData getTexturedModelData()
{
ModelData modelData = new ModelData();
ModelPartData modelPartData = modelData.getRoot();
modelPartData.addChild("back", ModelPartBuilder.create()
.uv(0, 0)
.cuboid(0.0F, 0F, 0F, 8.0F, 8.0F, 8.0F), ModelTransform.of(8.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F)
.withScale(1F));
return TexturedModelData.of(modelData.transform((modelTransform) -> {
return modelTransform.scaled(0.9F);
}), 8, 8);
modelPartData.addChild("body", ModelPartBuilder.create().uv(0, 0).cuboid(-1.5F, -3F, -1.5F, 3F, 3F, 3F), ModelTransform.of(0F, 0F, 0F, 0, 0, (float)Math.toRadians(180)));
modelPartData.addChild("trigger", ModelPartBuilder.create().uv(0, 6).cuboid(-0.5F, -3.5F, -0.75F, 1F, 1F, 2F), ModelTransform.of(0F, 0F, 0F, 0, 0, (float)Math.toRadians(180)));
return TexturedModelData.of(modelData, 16, 16);
}
}
public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Gadgets.id("thermal_detonator"), "temp");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"pswg_gadgets:thermal_detonator",
"pswg_gadgets:fragmentation_grenade"
]
}
25 changes: 18 additions & 7 deletions projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.mojang.serialization.Codec;
import dev.pswg.api.GalaxiesAddon;
import dev.pswg.entity.FragmentationGrenadeEntity;
import dev.pswg.entity.ThermalDetonatorEntity;
import dev.pswg.item.FragmentationGrenadeItem;
import dev.pswg.item.GrenadeItem;
import dev.pswg.item.ThermalDetonatorItem;
import dev.pswg.registry.Registrar;
Expand Down Expand Up @@ -49,32 +51,41 @@ public static Identifier id(String path)
* A logger available only to PSWG module and addon gadgets
*/
public static final Logger LOGGER = Galaxies.createSubLogger("gadgets");
public static final TagKey<DamageType> IGNITES_EXPLOSIVES = TagKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MODID, "ignites_explosives"));

public static final EntityType<FragmentationGrenadeEntity> FRAGMENTATION_GRENADE_ENTITY = Registrar.entityType(
id("fragmentation_grenade"),
EntityType.Builder.create(FragmentationGrenadeEntity::new, SpawnGroup.MISC)
.dimensions(0.2f, 0.4f)
.spawnBoxScale(0.2f)
.dropsNothing()

);
public static final EntityType<ThermalDetonatorEntity> THERMAL_DETONATOR_ENTITY = Registrar.entityType(
id("thermal_detonator"),
EntityType.Builder.create(ThermalDetonatorEntity::new, SpawnGroup.MISC)
.dimensions(0.2f, 0.2f)
.spawnBoxScale(0.2f)
.dropsNothing()
.maxTrackingRange(100)
.trackingTickInterval(20)

);

public static final ComponentType<Long> PRIMING_TIME = Registry.register(
Registries.DATA_COMPONENT_TYPE,
Identifier.of(MODID, "priming_time"),
ComponentType.<Long>builder().codec(Codec.LONG).build()
);

public static final GrenadeItem THERMAL_DETONATOR_ITEM = Registrar.item(id("thermal_detonator"), ThermalDetonatorItem::new, new Item.Settings());
public static final GrenadeItem FRAGMENTATION_GRENADE_ITEM = Registrar.item(id("fragmentation_grenade"), FragmentationGrenadeItem::new, new Item.Settings());

public static final TagKey<Block> FRAGMENTATION_GRENADE_DESTROY = TagKey.of(RegistryKeys.BLOCK, id("fragmentation_destroy"));

public static final SimpleParticleType EXPLOSION_SMOKE_PARTICLE = FabricParticleTypes.simple();

public static final TagKey<Block> DETONATES_GRENADE = TagKey.of(RegistryKeys.BLOCK, Identifier.of(MODID, "detonates_grenade"));
public static final TagKey<Item> GRENADES_TAG = TagKey.of(RegistryKeys.ITEM, id("grenades"));

public static final TagKey<Item> GRENADES_TAG = TagKey.of(RegistryKeys.ITEM, id("grenades"));

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

public static final SimpleParticleType EXPLOSION_SMOKE_PARTICLE = FabricParticleTypes.simple();


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import dev.pswg.Gadgets;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -102,7 +99,7 @@ public ActionResult interact(PlayerEntity player, Hand hand)
{
if (!isPrimed() && age > MIN_PICKUP_AGE && player.getMainHandStack().isEmpty())
{
player.giveItemStack(new ItemStack(Gadgets.THERMAL_DETONATOR_ITEM));
player.giveItemStack(new ItemStack(Gadgets.FRAGMENTATION_GRENADE_ITEM));
this.remove(RemovalReason.DISCARDED);
}
return super.interact(player, hand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.util.Hand;
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 ThermalDetonatorEntity extends GrenadeEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package dev.pswg.item;

import dev.pswg.Gadgets;
import dev.pswg.entity.FragmentationGrenadeEntity;
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 FragmentationGrenadeItem extends GrenadeItem
{
public FragmentationGrenadeItem(Item.Settings settings)
{
super(settings, Blocks.IRON_BLOCK, Gadgets.FRAGMENTATION_GRENADE_ITEM, 150);
}

@Override
public void throwEntity(World world, ItemStack stack, PlayerEntity player)
{
FragmentationGrenadeEntity fg = new FragmentationGrenadeEntity(Gadgets.FRAGMENTATION_GRENADE_ENTITY, world);
if (stack.contains(Gadgets.PRIMING_TIME))
{
fg.setLife((int)(stack.get(Gadgets.PRIMING_TIME) + baseTicksToExplosion - world.getTime()));
fg.setPrimed(true);
}
else
{
fg.setLife(150);
fg.setPrimed(false);
}
fg.setVisible(true);
fg.onSpawnPacket(new EntitySpawnS2CPacket(fg.getId(), fg.getUuid(), player.getX(), player.getY() + 1.5, player.getZ(), -player.getPitch(), -player.getYaw(), fg.getType(), 0, Vec3d.ZERO, player.getHeadYaw()));
fg.setOwner(player);
fg.setVelocity(player, player.getPitch(), player.getYaw(), (float)player.getRotationVector().z * 10, 1.0F, 0F);

world.spawnEntity(fg);
}

@Override
public void spawnEntity(World world, int power, ItemStack stack, Entity player)
{
FragmentationGrenadeEntity fg = new FragmentationGrenadeEntity(Gadgets.FRAGMENTATION_GRENADE_ENTITY, world);
//world.getTime() - baseTicksToExplosion
fg.setLife(stack.contains(Gadgets.PRIMING_TIME) ? (int)(stack.get(Gadgets.PRIMING_TIME) + baseTicksToExplosion - world.getTime()) : 1);
fg.setPrimed(stack.contains(Gadgets.PRIMING_TIME));
fg.setExplosionPower(power);
fg.onSpawnPacket(new EntitySpawnS2CPacket(fg.getId(), fg.getUuid(), player.getX(), player.getY() + 1, player.getZ(), -player.getPitch(), -player.getYaw(), fg.getType(), 0, Vec3d.ZERO, player.getHeadYaw()));
world.spawnEntity(fg);
}

// Used for dispensers
@Override
public ProjectileEntity createEntity(World world, Position pos, ItemStack stack, Direction direction)
{
FragmentationGrenadeEntity fg = new FragmentationGrenadeEntity(Gadgets.FRAGMENTATION_GRENADE_ENTITY, world);
initializeProjectile(fg, pos.getX(), pos.getY(), pos.getZ(), 1f, 0);
return fg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void inventoryTick(ItemStack stack, World world, Entity entity, int slot,
player.damage(serverWorld, new DamageSource(player.getWorld().getRegistryManager().getOrThrow(RegistryKeys.DAMAGE_TYPE).getEntry(DamageTypes.EXPLOSION.getValue()).get()), 40f);
GrenadeItem tei = (GrenadeItem)(stack.getItem() instanceof GrenadeItem ? stack.getItem() : item);
createExplosion(world, player);
player.getItemCooldownManager().set(stack, 0);
if (!player.isCreative())
{
stack.decrement(1);
Expand Down Expand Up @@ -231,7 +230,6 @@ public ActionResult useLeft(World world, LivingEntity user, Hand hand)
if (!stack.contains(Gadgets.PRIMING_TIME))
{
if(user instanceof PlayerEntity player){
player.getItemCooldownManager().set(stack, baseTicksToExplosion);
player.sendMessage(Text.of("Primed"), true);
}
stack.set(Gadgets.PRIMING_TIME, world.getTime());
Expand Down

0 comments on commit 1898b04

Please sign in to comment.