Skip to content

Commit 47fb8ba

Browse files
committed
Persist default skin for robit regardless of holiday if the default skin was manually set (#8138)
1 parent 8d75a05 commit 47fb8ba

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/main/java/mekanism/common/entity/EntityRobit.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ private static <T> EntityDataAccessor<T> define(EntityDataSerializer<T> dataSeri
147147
private static final EntityDataAccessor<SecurityMode> SECURITY = define(MekanismDataSerializers.SECURITY.value());
148148
private static final EntityDataAccessor<Boolean> FOLLOW = define(EntityDataSerializers.BOOLEAN);
149149
private static final EntityDataAccessor<Boolean> DROP_PICKUP = define(EntityDataSerializers.BOOLEAN);
150+
//Note: We sync the default skin part, so that pick item on the robit will properly persist this
151+
private static final EntityDataAccessor<Boolean> DEFAULT_SKIN_MANUALLY_SELECTED = define(EntityDataSerializers.BOOLEAN);
150152
private static final EntityDataAccessor<ResourceKey<RobitSkin>> SKIN = define(MekanismDataSerializers.ROBIT_SKIN.value());
151153

152154
private static final List<RecipeError> TRACKED_ERROR_TYPES = List.of(
@@ -277,6 +279,7 @@ protected void defineSynchedData(@NotNull SynchedEntityData.Builder builder) {
277279
builder.define(SECURITY, SecurityMode.PUBLIC);
278280
builder.define(FOLLOW, false);
279281
builder.define(DROP_PICKUP, false);
282+
builder.define(DEFAULT_SKIN_MANUALLY_SELECTED, false);
280283
builder.define(SKIN, MekanismRobitSkins.BASE);
281284
}
282285

@@ -347,7 +350,7 @@ public void baseTick() {
347350
energySlot.fillContainerOrConvert();
348351
recipeCacheLookupMonitor.updateAndProcess();
349352

350-
if (HolidayManager.hasRobitSkinsToday() && getSkin() == MekanismRobitSkins.BASE) {
353+
if (!isDefaultSkinManuallySelected() && HolidayManager.hasRobitSkinsToday() && getSkin() == MekanismRobitSkins.BASE) {
351354
//Randomize the robit's skin
352355
setSkin(HolidayManager.getRandomBaseSkin(level().random), null);
353356
}
@@ -459,6 +462,7 @@ private ItemStack getItemVariant() {
459462
security.setOwnerUUID(getOwnerUUID());
460463
security.setSecurityMode(getSecurityMode());
461464
}
465+
stack.set(MekanismDataComponents.DEFAULT_MANUALLY_SELECTED, isDefaultSkinManuallySelected());
462466
stack.set(MekanismDataComponents.ROBIT_SKIN, getSkin());
463467
return stack;
464468
}
@@ -668,7 +672,7 @@ public IEnergyContainer getEnergyContainer() {
668672
}
669673

670674
@Override
671-
public ItemStack getPickedResult(HitResult target) {
675+
public ItemStack getPickedResult(@NotNull HitResult target) {
672676
return getItemVariant();
673677
}
674678

@@ -729,6 +733,14 @@ public <T> Optional<T> evaluate(@NotNull BiFunction<Level, BlockPos, T> worldBlo
729733
};
730734
}
731735

736+
public boolean isDefaultSkinManuallySelected() {
737+
return entityData.get(DEFAULT_SKIN_MANUALLY_SELECTED);
738+
}
739+
740+
public void setDefaultSkinManuallySelected(boolean value) {
741+
entityData.set(DEFAULT_SKIN_MANUALLY_SELECTED, value);
742+
}
743+
732744
@NotNull
733745
@Override
734746
public ResourceKey<RobitSkin> getSkin() {
@@ -759,6 +771,9 @@ public boolean setSkin(@NotNull ResourceKey<RobitSkin> skinKey, @Nullable Player
759771
}
760772
}
761773
entityData.set(SKIN, skinKey);
774+
if (skinKey == MekanismRobitSkins.BASE) {
775+
setDefaultSkinManuallySelected(true);
776+
}
762777
return true;
763778
}
764779

src/main/java/mekanism/common/item/ItemRobit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public ItemRobit(Properties properties) {
5050
super(properties.rarity(Rarity.RARE).stacksTo(1)
5151
.component(MekanismDataComponents.ROBIT_SKIN, MekanismRobitSkins.BASE)
5252
.component(MekanismDataComponents.SECURITY, SecurityMode.PUBLIC)
53+
.component(MekanismDataComponents.DEFAULT_MANUALLY_SELECTED, false)
5354
);
5455
}
5556

@@ -111,6 +112,7 @@ public InteractionResult useOn(UseOnContext context) {
111112
robit.setSecurityMode(securityObject.getSecurityMode());
112113
}
113114
robit.setSkin(stack.getOrDefault(MekanismDataComponents.ROBIT_SKIN, MekanismRobitSkins.BASE), player);
115+
robit.setDefaultSkinManuallySelected(stack.getOrDefault(MekanismDataComponents.DEFAULT_MANUALLY_SELECTED, false));
114116
world.addFreshEntity(robit);
115117
world.gameEvent(player, GameEvent.ENTITY_PLACE, robit.blockPosition());
116118
stack.shrink(1);
@@ -130,7 +132,7 @@ public void attachCapabilities(RegisterCapabilitiesEvent event) {
130132
@Override
131133
public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, @NotNull Entity entity, int slot, boolean isSelected) {
132134
super.inventoryTick(stack, level, entity, slot, isSelected);
133-
if (!level.isClientSide && HolidayManager.hasRobitSkinsToday()) {
135+
if (!level.isClientSide && HolidayManager.hasRobitSkinsToday() && !stack.getOrDefault(MekanismDataComponents.DEFAULT_MANUALLY_SELECTED, false)) {
134136
ResourceKey<RobitSkin> skin = stack.get(MekanismDataComponents.ROBIT_SKIN);
135137
if (skin == null || skin == MekanismRobitSkins.BASE) {
136138
//Randomize the robit's skin

src/main/java/mekanism/common/registries/MekanismDataComponents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ private MekanismDataComponents() {
153153
.networkSynchronized(RedstoneOutput.STREAM_CODEC)
154154
);
155155

156+
public static final MekanismDeferredHolder<DataComponentType<?>, DataComponentType<Boolean>> DEFAULT_MANUALLY_SELECTED = DATA_COMPONENTS.registerBoolean("default_manually_selected");
156157
public static final MekanismDeferredHolder<DataComponentType<?>, DataComponentType<Boolean>> SCUBA_TANK_MODE = DATA_COMPONENTS.registerBoolean("scuba_tank_mode");
157158
public static final MekanismDeferredHolder<DataComponentType<?>, DataComponentType<Boolean>> ELECTRIC_BOW_MODE = DATA_COMPONENTS.registerBoolean("electric_bow_mode");
158159
public static final MekanismDeferredHolder<DataComponentType<?>, DataComponentType<Boolean>> BUCKET_MODE = DATA_COMPONENTS.registerBoolean("bucket_mode");

0 commit comments

Comments
 (0)