Skip to content

Commit

Permalink
Just implement ArmedArmorStandsModule with a mixin. Fixes #4470
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 14, 2023
1 parent c2bcd6d commit 2681985
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
package org.violetmoon.quark.content.tweaks.module;

import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.play.entity.ZEntityConstruct;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZConfigChanged;
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.util.Hint;

import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

/**
* @author WireSegal
* Created at 8:40 AM on 8/27/19.
*
* modified by quat
* @see org.violetmoon.quark.mixin.ArmorStandMixin
*/
@ZetaLoadModule(category = "tweaks")
public class ArmedArmorStandsModule extends ZetaModule {

@Hint Item armor_stand = Items.ARMOR_STAND;

@PlayEvent
public void entityConstruct(ZEntityConstruct event) {
if(event.getEntity() instanceof ArmorStand stand) {
if(!stand.isShowArms())
setShowArms(stand, true);
}
}
public static boolean staticEnabled = true;

private void setShowArms(ArmorStand e, boolean showArms) {
e.getEntityData().set(ArmorStand.DATA_CLIENT_FLAGS, setBit(e.getEntityData().get(ArmorStand.DATA_CLIENT_FLAGS), 4, showArms));
@LoadEvent
public void configChange(ZConfigChanged e) {
staticEnabled = enabled;
}

private byte setBit(byte status, int bitFlag, boolean value) {
if (value)
status = (byte)(status | bitFlag);
else
status = (byte)(status & ~bitFlag);

return status;
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/violetmoon/quark/mixin/ArmorStandMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.violetmoon.quark.mixin;

import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.violetmoon.quark.content.tweaks.module.ArmedArmorStandsModule;

@Mixin(ArmorStand.class)
public class ArmorStandMixin {
@ModifyConstant(method = "defineSynchedData", constant = @Constant(intValue = 0))
private int asdasld(int orig) {
if(!ArmedArmorStandsModule.staticEnabled)
return orig;

//try to be careful - this is a kinda scary looking mixin, lol
SynchedEntityData data = ((Entity) (Object) this).getEntityData();
if(data.hasItem(ArmorStand.DATA_CLIENT_FLAGS))
return orig; //it's already been defined

else
return orig | ArmorStand.CLIENT_FLAG_SHOW_ARMS; // | 4
}
}
1 change: 1 addition & 0 deletions src/main/resources/quark.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"AbstractVillagerMixin",
"AnimalMixin",
"AnvilMenuMixin",
"ArmorStandMixin",
"ArrowPiercingEnchantmentMixin",
"BannerDuplicateRecipeMixin",
"BaseCoralPlantTypeBlockMixin",
Expand Down

0 comments on commit 2681985

Please sign in to comment.