Skip to content

Commit

Permalink
Merge pull request #29 from orifu/1.21
Browse files Browse the repository at this point in the history
1.21
  • Loading branch information
ix0rai authored Jun 14, 2024
2 parents 79b3726 + ee98f7d commit 1f125f4
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 51 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# minecraft, mappings and loader dependencies
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
quilt_mappings=6
minecraft_version=1.21-rc1
quilt_mappings=2
loader_version=0.15.11

# mod properties
mod_version=1.3.1+mc1.20.6
mod_version=1.3.2+mc1.21
maven_group=rainglow
archives_base_name=rainglow

# other dependencies
java_version=21
mod_menu_version=10.0.0-beta.1
fabric_api_version=0.98.0+1.20.6
mod_menu_version=11.0.0-beta.1
fabric_api_version=0.100.1+1.21
2 changes: 1 addition & 1 deletion src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onInitialize() {
}

public static Identifier id(String id) {
return new Identifier(MOD_ID, id);
return Identifier.of(MOD_ID, id);
}

public static String generateRandomColourId(World world, RandomGenerator random) {
Expand Down
61 changes: 36 additions & 25 deletions src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ public class CustomModeScreen extends GameOptionsScreen implements ScreenWithUns

public CustomModeScreen(Screen parent) {
super(parent, MinecraftClient.getInstance().options, TITLE);
this.saveButton = ButtonWidget.builder(Rainglow.translatableText("config.save"), button -> {
boolean hasColourSelected = false;
for (DeferredSaveOption<Boolean> option : this.options) {
if (option.deferredValue) {
hasColourSelected = true;
break;
}
}

if (!hasColourSelected) {
sendNoColoursToast();
} else {
this.save();
}
}).build();

this.saveButton = ButtonWidget.builder(
Rainglow.translatableText("config.save"),
button -> {
boolean hasColourSelected = false;
for (DeferredSaveOption<Boolean> option : this.options) {
if (option.deferredValue) {
hasColourSelected = true;
break;
}
}

if (!hasColourSelected) {
sendNoColoursToast();
} else {
this.save();
}
}).build();
this.saveButton.active = false;
}

Expand All @@ -51,15 +54,15 @@ private void createColourToggles() {

for (RainglowColour colour : RainglowColour.values()) {
this.options.add(DeferredSaveOption.createDeferredBoolean(
"colour." + colour.getId(),
null,
Rainglow.CONFIG.customColours.getRealValue().contains(colour.getId()),
enabled -> {
if (enabled) {
Rainglow.CONFIG.customColours.getRealValue().add(colour.getId());
}
},
enabled -> this.saveButton.active = true
"colour." + colour.getId(),
null,
Rainglow.CONFIG.customColours.getRealValue().contains(colour.getId()),
enabled -> {
if (enabled) {
Rainglow.CONFIG.customColours.getRealValue().add(colour.getId());
}
},
enabled -> this.saveButton.active = true
));
}
}
Expand All @@ -81,7 +84,7 @@ public void init() {
headerFooterWidget.addToHeader(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28));

if (!this.isConfirming) {
ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this.height, this));
ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this));
createColourToggles();
buttonListWidget.addEntries(this.options.toArray(new Option<?>[0]));

Expand All @@ -96,6 +99,14 @@ public void init() {
headerFooterWidget.arrangeElements();
}

@Override
protected void method_60325() {}

@Override
protected void repositionElements() {
this.clearAndInit();
}

private static void sendNoColoursToast() {
Toast toast = new SystemToast(SystemToast.Id.PACK_LOAD_FAILURE, Rainglow.translatableText("config.no_custom_colours"), Rainglow.translatableText("config.no_custom_colours_description"));
MinecraftClient.getInstance().getToastManager().add(toast);
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ public void init() {
}

contentLayout.add(gridWidget);
contentLayout.add(ButtonWidget.builder(Rainglow.translatableText("config.custom"), button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this))).width(308).position(4, 0).build(), LayoutSettings.create().setPadding(4, 0));
contentLayout.add(ButtonWidget.builder(
Rainglow.translatableText("config.custom"),
button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this))
).width(308).position(4, 0).build(),
LayoutSettings.create().setPadding(4, 0));

headerFooterWidget.addToContents(contentLayout);

Expand Down Expand Up @@ -128,14 +132,14 @@ private DeferredSaveOption<Boolean> createEntityToggle(RainglowEntity entity) {

private DeferredSaveOption<Integer> createColourRaritySlider(RainglowEntity entity) {
return sliders.computeIfAbsent(entity, e -> DeferredSaveOption.createDeferredRangedInt(
"config." + e.getId() + "_rarity",
"tooltip.rarity",
Rainglow.CONFIG.rarities.getRealValue().get(e.getId()),
0,
100,
rarity -> Rainglow.CONFIG.rarities.getRealValue().put(e.getId(), rarity),
"config." + e.getId() + "_rarity",
"tooltip.rarity",
Rainglow.CONFIG.rarities.getRealValue().get(e.getId()),
0,
100,
rarity -> Rainglow.CONFIG.rarities.getRealValue().put(e.getId(), rarity),
rarity -> this.saveButton.active = true
));
));
}

public CyclingButtonWidget<RainglowMode> createModeButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ScreenWithUnsavedWarning {

void clearAndInit();

default void setUpUnsavedWarning(HeaderFooterLayoutWidget headerFooterWidget, TextRenderer renderer, Screen parent) {
default void setUpUnsavedWarning(HeaderFooterLayoutWidget headerFooterWidget, TextRenderer renderer, Screen parent) {
LinearLayoutWidget contentWidget = headerFooterWidget.addToContents(new LinearLayoutWidget(250, 100, LinearLayoutWidget.Orientation.VERTICAL).setSpacing(8));
contentWidget.add(new TextWidget(Rainglow.translatableText("config.unsaved_warning"), renderer), LayoutSettings::alignHorizontallyCenter);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/ix0rai/rainglow/data/RainglowColour.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public Identifier getTexture(RainglowEntity entityType) {
switch (entity) {
case GLOW_SQUID -> {
String textureName = RainglowEntity.GLOW_SQUID.getDefaultColour() == this ? "glow_squid" : this.getId();
this.textures.put(entity, new Identifier("textures/entity/squid/" + textureName + ".png"));
this.textures.put(entity, Identifier.ofDefault("textures/entity/squid/" + textureName + ".png"));
}
case ALLAY -> {
String textureName = RainglowEntity.ALLAY.getDefaultColour() == this ? "allay" : this.getId();
this.textures.put(entity, new Identifier("textures/entity/allay/" + textureName + ".png"));
this.textures.put(entity, Identifier.ofDefault("textures/entity/allay/" + textureName + ".png"));
}
case SLIME -> {
String textureName = RainglowEntity.SLIME.getDefaultColour() == this ? "slime" : this.getId();
this.textures.put(entity, new Identifier("textures/entity/slime/" + textureName + ".png"));
this.textures.put(entity, Identifier.ofDefault("textures/entity/slime/" + textureName + ".png"));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ protected void initDataTracker(Builder builder, CallbackInfo ci) {

@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) {
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom());
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random);
nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour.getId());
}

@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
this.setVariant(RainglowEntity.GLOW_SQUID.readNbt(this.getWorld(), nbt, this.getRandom()));
this.setVariant(RainglowEntity.GLOW_SQUID.readNbt(this.getWorld(), nbt, this.random));
}

/**
Expand All @@ -49,7 +49,7 @@ public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
*/
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addParticle(Lnet/minecraft/particle/ParticleEffect;DDDDDD)V"), cancellable = true)
public void tickMovement(CallbackInfo ci) {
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom());
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random);

if (colour != RainglowColour.BLUE) {
// we add 100 to g to let the mixin know that we want to override the method
Expand All @@ -60,7 +60,7 @@ public void tickMovement(CallbackInfo ci) {

@Override
public RainglowColour getVariant() {
return Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom());
return Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random);
}

@Override
Expand All @@ -85,7 +85,7 @@ protected SquidEntityMixin(EntityType<? extends WaterCreatureEntity> entityType,
private int spawnParticles(ServerWorld instance, ParticleEffect particle, double x, double y, double z, int count, double deltaX, double deltaY, double deltaZ, double speed) {
if (((Object) this) instanceof GlowSquidEntity) {
// send in custom colour data
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom());
RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random);
int index = colour.ordinal();
// round x to 1 decimal place and append index data to the next two
return ((ServerWorld) this.getWorld()).spawnParticles(particle, (Math.round(x * 10)) / 10D + index / 1000D, y + 0.5, z, 0, deltaX, deltaY, deltaZ, speed);
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
},

"depends": {
"fabricloader": ">=0.14.19",
"fabricloader": ">=0.15.11",
"fabric-resource-loader-v0": "*",
"fabric-networking-api-v1": "*",
"minecraft": ">=1.20.6"
"minecraft": ">=1.21-"
},

"suggests": {
"modmenu": ">=7.0.0"
"modmenu": ">=11.0.0-"
},

"custom": {
Expand Down

0 comments on commit 1f125f4

Please sign in to comment.