Add mixins for block and entity placeholder cleanup
Introduces BlockMixin and EntityMixin to handle removal of placeholder ArmorStand entities when pressure plates are broken and when fishing rod item entities are discarded. Also updates Util to mark spawned placeholders with a custom data flag, and registers new mixins in stasisrods.mixins.json. Bumps mod version to 1.4.
This commit is contained in:
@@ -7,7 +7,7 @@ yarn_mappings=1.21.10+build.2
|
|||||||
loader_version=0.17.3
|
loader_version=0.17.3
|
||||||
loom_version=1.12-SNAPSHOT
|
loom_version=1.12-SNAPSHOT
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.3
|
mod_version=1.4
|
||||||
maven_group=com.kasetoatz
|
maven_group=com.kasetoatz
|
||||||
archives_base_name=StasisRods
|
archives_base_name=StasisRods
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|||||||
35
src/main/java/com/kasetoatz/stasisrods/mixin/BlockMixin.java
Normal file
35
src/main/java/com/kasetoatz/stasisrods/mixin/BlockMixin.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.kasetoatz.stasisrods.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.component.DataComponentTypes;
|
||||||
|
import net.minecraft.component.type.NbtComponent;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Mixin(Block.class)
|
||||||
|
public class BlockMixin
|
||||||
|
{
|
||||||
|
@Inject(method="onBreak", at=@At("HEAD"))
|
||||||
|
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir)
|
||||||
|
{
|
||||||
|
if (!state.isIn(BlockTags.PRESSURE_PLATES))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<ArmorStandEntity> entities = world.getEntitiesByClass(ArmorStandEntity.class, Box.of(pos.toBottomCenterPos(), 0.5, 0.5, 0.5), entity -> Objects.requireNonNullElse(entity.get(DataComponentTypes.CUSTOM_DATA), NbtComponent.DEFAULT).copyNbt().getBoolean("isPlaceholder", false));
|
||||||
|
entities.forEach(Entity::discard);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.kasetoatz.stasisrods.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.ItemEntity;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import static com.kasetoatz.stasisrods.util.Util.tryDiscardPlaceholder;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public abstract class EntityMixin
|
||||||
|
{
|
||||||
|
@Shadow public abstract World getEntityWorld();
|
||||||
|
|
||||||
|
@Inject(method="discard", at=@At("HEAD"))
|
||||||
|
public void discard(CallbackInfo ci)
|
||||||
|
{
|
||||||
|
Entity entity = (Entity)(Object)this;
|
||||||
|
if (entity instanceof ItemEntity item && item.getStack().getItem() == Items.FISHING_ROD)
|
||||||
|
{
|
||||||
|
tryDiscardPlaceholder(item.getStack(), getEntityWorld().getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,7 @@ public class Util
|
|||||||
public static ArmorStandEntity spawnPlaceholder(World world, Vec3d pos)
|
public static ArmorStandEntity spawnPlaceholder(World world, Vec3d pos)
|
||||||
{
|
{
|
||||||
ArmorStandEntity placeholder = new ArmorStandEntity(world, pos.getX(), pos.getY(), pos.getZ());
|
ArmorStandEntity placeholder = new ArmorStandEntity(world, pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
placeholder.setComponent(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.apply(nbt -> nbt.putBoolean("isPlaceholder", true)));
|
||||||
placeholder.setHideBasePlate(true);
|
placeholder.setHideBasePlate(true);
|
||||||
placeholder.setInvisible(true);
|
placeholder.setInvisible(true);
|
||||||
placeholder.setInvulnerable(true);
|
placeholder.setInvulnerable(true);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
"package": "com.kasetoatz.stasisrods.mixin",
|
"package": "com.kasetoatz.stasisrods.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"BlockMixin",
|
||||||
|
"EntityMixin",
|
||||||
"FishingRodItemMixin"
|
"FishingRodItemMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
|||||||
Reference in New Issue
Block a user