Skip to content

Commit

Permalink
primed pipe bombs now explode when dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Oct 19, 2024
1 parent 4840728 commit 112d834
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ladysnake/blast/common/item/PipeBombItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand h
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
if (!world.isClient && stack.getOrDefault(BlastComponentTypes.PRIMED, false) && entity instanceof PlayerEntity player) {
for (int i = 0; i < stack.getCount(); i++) {
while (!stack.isEmpty()) {
spawn(world, stack.copyWithCount(1), player, 0);
stack.decrement(1);
}
stack.decrement(stack.getCount());
}
}

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/ladysnake/blast/mixin/ItemEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ladysnake.blast.mixin;

import ladysnake.blast.common.entity.PipeBombEntity;
import ladysnake.blast.common.init.BlastComponentTypes;
import ladysnake.blast.common.init.BlastEntities;
import ladysnake.blast.common.init.BlastItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemEntity.class)
public abstract class ItemEntityMixin extends Entity {
@Shadow
public abstract ItemStack getStack();

public ItemEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;tick()V"), cancellable = true)
private void blast$pipeBomb(CallbackInfo ci) {
if (getStack().isOf(BlastItems.PIPE_BOMB) && getStack().getOrDefault(BlastComponentTypes.PRIMED, false)) {
while (!getStack().isEmpty()) {
PipeBombEntity pipeBomb = BlastEntities.PIPE_BOMB.create(getWorld());
pipeBomb.setPosition(getPos());
pipeBomb.setVelocity(getVelocity());
pipeBomb.setItem(getStack().copyWithCount(1));
getWorld().spawnEntity(pipeBomb);
getStack().decrement(1);
}
discard();
ci.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/blast.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"EnderEyeItemMixin",
"ExplosionMixin",
"FallingBlockEntityAccessor",
"ItemEntityMixin",
"PersistentProjectileEntityMixin"
],
"client": [
Expand Down

0 comments on commit 112d834

Please sign in to comment.