Skip to content

Commit

Permalink
Merge pull request #81 from EminGT/master
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai authored Jun 1, 2024
2 parents c6d8b24 + 952c7d2 commit 4e90508
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public class ArmorConfig {
public static final Codec<ArmorConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.fieldOf("showInCombat").forGetter(config -> config.showInCombat),
Codec.BOOL.fieldOf("showNameTag").forGetter(config -> config.showNameTag),
Codec.BOOL.fieldOf("forceElytraWhenFlying").forGetter(config -> config.forceElytraWhenFlying),
Codec.unboundedMap(HideableEquipment.getCodec(), ArmorPieceConfig.CODEC).fieldOf("pieces").forGetter(config -> config.pieces),
Codec.unboundedMap(HideableEquipment.getSlotCodec(), ArmorPieceConfig.CODEC).fieldOf("trims").forGetter(config -> config.trims),
Codec.unboundedMap(HideableEquipment.getCodec(), ArmorPieceConfig.CODEC).fieldOf("glints").forGetter(config -> config.glints)
).apply(instance, ArmorConfig::new));
public static final PacketCodec<ByteBuf, ArmorConfig> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.BOOL, c -> c.showInCombat,
PacketCodecs.BOOL, c -> c.showNameTag,
PacketCodecs.BOOL, c -> c.forceElytraWhenFlying,
PacketCodecs.map(HashMap::new, HideableEquipment.getPacketCodec(), ArmorPieceConfig.PACKET_CODEC, VANILLA_VALUES.pieces.size()), ArmorConfig::getPieces,
PacketCodecs.map(HashMap::new, HideableEquipment.getPacketSlotCodec(), ArmorPieceConfig.PACKET_CODEC, VANILLA_VALUES.trims.size()), ArmorConfig::getTrims,
PacketCodecs.map(HashMap::new, HideableEquipment.getPacketCodec(), ArmorPieceConfig.PACKET_CODEC, VANILLA_VALUES.glints.size()), ArmorConfig::getGlints,
Expand All @@ -37,6 +39,7 @@ public class ArmorConfig {
public final HashMap<HideableEquipment, ArmorPieceConfig> glints = new HashMap<>();
public boolean showInCombat = true;
public boolean showNameTag = true;
public boolean forceElytraWhenFlying = true;

public ArmorConfig() {
pieces.put(HideableEquipment.HEAD, new ArmorPieceConfig());
Expand All @@ -61,10 +64,11 @@ public ArmorConfig() {
glints.put(HideableEquipment.HAT, new ArmorPieceConfig());
}

public ArmorConfig(boolean showInCombat, boolean showNameTag, Map<HideableEquipment, ArmorPieceConfig> pieces, Map<EquipmentSlot, ArmorPieceConfig> trims, Map<HideableEquipment, ArmorPieceConfig> glints) {
public ArmorConfig(boolean showInCombat, boolean showNameTag, boolean forceElytraWhenFlying, Map<HideableEquipment, ArmorPieceConfig> pieces, Map<EquipmentSlot, ArmorPieceConfig> trims, Map<HideableEquipment, ArmorPieceConfig> glints) {
this();
this.showInCombat = showInCombat;
this.showNameTag = showNameTag;
this.forceElytraWhenFlying = forceElytraWhenFlying;
this.pieces.putAll(pieces);
this.trims.putAll(trims);
this.glints.putAll(glints);
Expand Down Expand Up @@ -125,6 +129,7 @@ public ArmorConfig copy() {
return new ArmorConfig(
showInCombat,
showNameTag,
forceElytraWhenFlying,
pieces.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().copy())),
trims.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().copy())),
glints.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().copy()))
Expand All @@ -140,6 +145,7 @@ public boolean equals(Object o) {

if (showInCombat != that.showInCombat) return false;
if (showNameTag != that.showNameTag) return false;
if (forceElytraWhenFlying != that.forceElytraWhenFlying) return false;
if (!pieces.equals(that.pieces)) return false;
if (!trims.equals(that.trims)) return false;
return glints.equals(that.glints);
Expand All @@ -152,6 +158,7 @@ public int hashCode() {
result = 31 * result + glints.hashCode();
result = 31 * result + (showInCombat ? 1 : 0);
result = 31 * result + (showNameTag ? 1 : 0);
result = 31 * result + (forceElytraWhenFlying ? 1 : 0);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
public interface SyncedModConfig {
Codec<SyncedModConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.optionalFieldOf("allowNotShowInCombat", true).forGetter(SyncedModConfig::allowNotShowInCombat),
Codec.BOOL.optionalFieldOf("allowNotShowNameTag", true).forGetter(SyncedModConfig::allowNotShowNameTag)
Codec.BOOL.optionalFieldOf("allowNotShowNameTag", true).forGetter(SyncedModConfig::allowNotShowNameTag),
Codec.BOOL.optionalFieldOf("allowNotForceElytraWhenFlying", true).forGetter(SyncedModConfig::allowNotForceElytraWhenFlying)
).apply(instance, SyncedModConfigClient::new));
PacketCodec<RegistryByteBuf, SyncedModConfig> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.BOOL, SyncedModConfig::allowNotShowInCombat,
PacketCodecs.BOOL, SyncedModConfig::allowNotShowNameTag,
PacketCodecs.BOOL, SyncedModConfig::allowNotForceElytraWhenFlying,
SyncedModConfigClient::new
);

boolean allowNotShowInCombat();

boolean allowNotShowNameTag();

boolean allowNotForceElytraWhenFlying();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.enjarai.showmeyourskin.config;

public record SyncedModConfigClient(boolean allowNotShowInCombat, boolean allowNotShowNameTag) implements SyncedModConfig {
public record SyncedModConfigClient(boolean allowNotShowInCombat, boolean allowNotShowNameTag, boolean allowNotForceElytraWhenFlying) implements SyncedModConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SyncedModConfigServer implements SyncedModConfig {

public boolean allowNotShowInCombat = false;
public boolean allowNotShowNameTag = false;
public boolean allowNotForceElytraWhenFlying = false;

public static void load() {
INSTANCE = loadConfigFile(CONFIG_FILE);
Expand Down Expand Up @@ -81,4 +82,8 @@ public boolean allowNotShowInCombat() {
public boolean allowNotShowNameTag() {
return allowNotShowNameTag;
}

public boolean allowNotForceElytraWhenFlying() {
return allowNotForceElytraWhenFlying;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ArmorConfigWindow extends AbstractParentElement implements Drawable
protected static final ButtonTextures TOGGLE_GLINT_BUTTON_TEXTURES = ToggleButtonWidget.createTextures("show_glint");
protected static final ButtonTextures SHOW_IN_COMBAT_BUTTON_TEXTURES = ToggleButtonWidget.createTextures("show_in_combat");
protected static final ButtonTextures SHOW_NAME_TAG_BUTTON_TEXTURES = ToggleButtonWidget.createTextures("show_nametag");
protected static final ButtonTextures FORCE_ELYTRA_WHEN_FLYING_BUTTON_TEXTURES = ToggleButtonWidget.createTextures("force_elytra_when_flying");

private static final ItemStack HEAD_ARMOR = new AlwaysGlintingStack(Items.NETHERITE_HELMET);
private static final ItemStack CHEST_ARMOR = new AlwaysGlintingStack(Items.NETHERITE_CHESTPLATE);
Expand Down Expand Up @@ -139,12 +140,20 @@ public ArmorConfigWindow(Screen parent, int x, int y, Text name, DummyClientPlay

if (!hideOptions || serverConfig.get().allowNotShowNameTag()) {
buttons.add(new ToggleButtonWidget(
getWindowLeft() + 14, getWindowTop() + 141, 20, 20,
getWindowLeft() + 40, getWindowTop() + 115, 20, 20,
SHOW_NAME_TAG_BUTTON_TEXTURES,
armorConfig.showNameTag, (btn, b) -> armorConfig.showNameTag = b, NAME_TAG_TOOLTIP
));
}

if (!hideOptions || serverConfig.get().allowNotForceElytraWhenFlying()) {
buttons.add(new ToggleButtonWidget(
getWindowLeft() + 66, getWindowTop() + 115, 20, 20,
FORCE_ELYTRA_WHEN_FLYING_BUTTON_TEXTURES,
armorConfig.forceElytraWhenFlying, (btn, b) -> armorConfig.forceElytraWhenFlying = b, NAME_TAG_TOOLTIP
));
}

children.addAll(buttons);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public ElytraFeatureRendererMixin(FeatureRendererContext<T, M> context) {
MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f,
float g, float h, float j, float k, float l, CallbackInfo ci) {
if (livingEntity instanceof PlayerEntity player) {
if (ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA) <= 0) {
ci.cancel();
if (!player.isFallFlying() || !ModConfig.INSTANCE.getApplicable(player.getUuid()).forceElytraWhenFlying) {
if (ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA) <= 0) {
ci.cancel();
}
}
}
}
Expand Down Expand Up @@ -71,9 +73,11 @@ public ElytraFeatureRendererMixin(FeatureRendererContext<T, M> context) {
VertexConsumerProvider vertexConsumerProvider, RenderLayer renderLayer, boolean solid, boolean hasGlint,
Operation<VertexConsumer> original, @Local(argsOnly = true) LivingEntity entity) {
if (entity instanceof PlayerEntity player) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return ItemRenderer.getDirectItemGlintConsumer(vertexConsumerProvider, renderLayer, solid, hasGlint);
if (!player.isFallFlying() || !ModConfig.INSTANCE.getApplicable(player.getUuid()).forceElytraWhenFlying) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return ItemRenderer.getDirectItemGlintConsumer(vertexConsumerProvider, renderLayer, solid, hasGlint);
}
}
}

Expand All @@ -90,9 +94,11 @@ public ElytraFeatureRendererMixin(FeatureRendererContext<T, M> context) {
private RenderLayer showmeyourskin$enableElytraTransparency2(
Identifier texture, Operation<RenderLayer> original, @Local(argsOnly = true) LivingEntity entity) {
if (entity instanceof PlayerEntity player) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return RenderLayer.getEntityTranslucent(texture);
if (!player.isFallFlying() || !ModConfig.INSTANCE.getApplicable(player.getUuid()).forceElytraWhenFlying) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return RenderLayer.getEntityTranslucent(texture);
}
}
}

Expand All @@ -109,9 +115,11 @@ public ElytraFeatureRendererMixin(FeatureRendererContext<T, M> context) {
)
private float showmeyourskin$applyElytraTransparency(float original, @Local(argsOnly = true) LivingEntity entity) {
if (entity instanceof PlayerEntity player) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return transparency;
if (!player.isFallFlying() || !ModConfig.INSTANCE.getApplicable(player.getUuid()).forceElytraWhenFlying) {
var transparency = ModConfig.INSTANCE.getApplicablePieceTransparency(player.getUuid(), HideableEquipment.ELYTRA);
if (transparency < 1) {
return transparency;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void setFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLo
public void ensureValid() {
if (!SyncedModConfigServer.INSTANCE.allowNotShowInCombat()) getConfig().showInCombat = true;
if (!SyncedModConfigServer.INSTANCE.allowNotShowNameTag()) getConfig().showNameTag = true;
if (!SyncedModConfigServer.INSTANCE.allowNotForceElytraWhenFlying()) getConfig().forceElytraWhenFlying = true;
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4e90508

Please sign in to comment.