-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
org.gradle.jvmargs=-Xmx2G | ||
loom.platform=fabric | ||
|
||
minecraft_version=1.20.6 | ||
yarn_mappings=1.20.6+build.1 | ||
loader_version=0.15.11 | ||
|
||
mod_version = 0.2.0-release-mc1.20.6 | ||
maven_group = top.gregtao.xibaopp | ||
archives_base_name = XibaoPlusPlus-Fabric | ||
|
||
fabric_version=0.98.0+1.20.6 |
45 changes: 45 additions & 0 deletions
45
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/BackgroundWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.Drawable; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.gui.Selectable; | ||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; | ||
import net.minecraft.client.util.Window; | ||
import top.gregtao.xibaopp.util.RenderHelper; | ||
|
||
public class BackgroundWidget implements Drawable, Element, Selectable { | ||
|
||
@Override | ||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
Window window = client.getWindow(); | ||
int width = window.getScaledWidth(), height = window.getScaledHeight(); | ||
if (XibaoPlusPlusConfig.showPicture) { | ||
RenderHelper.renderStretchTexture(width, height, 225, | ||
XibaoPlusPlusConfig.type.background); | ||
} | ||
if (XibaoPlusPlusConfig.displaySnow || XibaoPlusPlusConfig.tempSnow) { | ||
SnowAnimation.INSTANCE.tick(width, height, XibaoPlusPlusConfig.type.snows); | ||
} | ||
} | ||
|
||
@Override | ||
public void setFocused(boolean focused) { | ||
} | ||
|
||
@Override | ||
public boolean isFocused() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public SelectionType getType() { | ||
return Selectable.SelectionType.NONE; | ||
} | ||
|
||
@Override | ||
public void appendNarrations(NarrationMessageBuilder builder) { | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/SnowAnimation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import net.minecraft.util.Identifier; | ||
import top.gregtao.xibaopp.util.RenderHelper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class SnowAnimation { | ||
public static SnowAnimation INSTANCE; | ||
private Identifier[] source; | ||
private int lastWidth, lastHeight; | ||
private float amount = 0.1f; | ||
private final Random random; | ||
private final List<Snow> snows; | ||
|
||
public SnowAnimation(Random random) { | ||
this.random = random; | ||
this.snows = new ArrayList<>(); | ||
} | ||
|
||
public void tick(int width, int height, Identifier[] source) { | ||
this.source = source; | ||
if (width != this.lastWidth || height != this.lastHeight) { | ||
this.snows.clear(); | ||
this.lastWidth = width; | ||
this.lastHeight = height; | ||
} | ||
this.spawnGroup(); | ||
for (Snow snow : this.snows) { | ||
RenderHelper.renderParticle(snow.x, height - snow.y, 4, 4, this.source[snow.source % this.source.length]); | ||
snow.move(); | ||
if (snow.y > height) { | ||
snow.removed = true; | ||
} | ||
} | ||
if (this.snows.size() > 500) { | ||
int i = 0; | ||
while (i < this.snows.size() && this.snows.get(i).removed) this.snows.remove(i); | ||
} | ||
} | ||
|
||
public void spawnGroup() { | ||
this.amount += 0.001f; | ||
float realAmount = Math.min(0.4f, this.amount); | ||
if (realAmount < 1) { | ||
if (this.random.nextInt((int) (1 / realAmount)) == 0) this.spawn(); | ||
} else { | ||
for (int i = 1; i <= realAmount; ++i) this.spawn(); | ||
} | ||
if (this.amount >= 0.6f) this.amount = 0.1f; | ||
} | ||
|
||
public int getSourceIndex() { | ||
return this.random.nextInt(this.source.length); | ||
} | ||
|
||
public void spawn() { | ||
int x = random.nextInt(this.lastWidth); | ||
int k = (random.nextInt(4)) * 2 + 1; | ||
this.snows.add(new Snow(x, random.nextInt(2) == 0 ? -k : k, this.getSourceIndex())); | ||
} | ||
|
||
} | ||
|
||
class Snow { | ||
public int baseX, x, y, k, source; | ||
public boolean removed = false; | ||
public Snow(int x, int k, int source) { | ||
this.baseX = this.x = x; | ||
this.k = k; | ||
this.source = source; | ||
this.y = 0; | ||
} | ||
public void move() { | ||
this.y++; | ||
this.x = this.baseX + this.y / this.k; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/XibaoPlusPlusConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.util.Random; | ||
|
||
public class XibaoPlusPlusConfig { | ||
private static final File file = new File("xibao_plus_plus.properties"); | ||
|
||
public static boolean shouldPlayMusic = false; | ||
public static boolean tempSnow = false; | ||
public static Random random = new Random(); | ||
|
||
public static boolean playMusic = true; | ||
public static boolean showPicture = true; | ||
public static boolean displaySnow = false; | ||
|
||
public static XibaoType type = XibaoType.XIBAO; | ||
|
||
public static void loadConfig() throws Exception { | ||
if (!file.exists()) { | ||
storeConfig(); | ||
return; | ||
} | ||
Properties properties = new Properties(); | ||
properties.load(new FileInputStream(file)); | ||
playMusic = properties.getOrDefault("playMusic", "true").equals("true"); | ||
showPicture = properties.getOrDefault("showPicture", "true").equals("true"); | ||
displaySnow = properties.getOrDefault("displaySnow", "false").equals("true"); | ||
type = XibaoType.getByString(properties.getProperty("type")); | ||
} | ||
|
||
public static void storeConfig() throws IOException { | ||
Properties properties = new Properties(); | ||
properties.setProperty("playMusic", String.valueOf(playMusic)); | ||
properties.setProperty("showPicture", String.valueOf(showPicture)); | ||
properties.setProperty("displaySnow", String.valueOf(displaySnow)); | ||
properties.setProperty("type", type.type); | ||
properties.store(new FileWriter(file), "Xibao Plus Plus"); | ||
} | ||
|
||
public static void switchAlbum() { | ||
XibaoType[] types = XibaoType.values(); | ||
type = types[(type.ordinal() + 1) % types.length]; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/XibaoPlusPlusMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class XibaoPlusPlusMain implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
try { | ||
XibaoPlusPlusConfig.loadConfig(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/XibaoPlusPlusMusic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.sound.MusicSound; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class XibaoPlusPlusMusic { | ||
public static RegistryEntry.Reference<SoundEvent> XIBAO_SOUND_EVENT = registerReference(new Identifier("xibaopp", "xibao")); | ||
public static MusicSound XIBAO_MUSIC = new MusicSound(XIBAO_SOUND_EVENT, 0, 0, true); | ||
public static RegistryEntry.Reference<SoundEvent> BEIBAO_SOUND_EVENT = registerReference(new Identifier("xibaopp", "beibao")); | ||
public static MusicSound BEIBAO_MUSIC = new MusicSound(BEIBAO_SOUND_EVENT, 0, 0, true); | ||
|
||
private static RegistryEntry.Reference<SoundEvent> registerReference(Identifier id) { | ||
return registerReference(id, id); | ||
} | ||
private static RegistryEntry.Reference<SoundEvent> registerReference(Identifier id, Identifier soundId) { | ||
return Registry.registerReference(Registries.SOUND_EVENT, id, SoundEvent.of(soundId)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/XibaoType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package top.gregtao.xibaopp; | ||
|
||
import net.minecraft.sound.MusicSound; | ||
import net.minecraft.util.Identifier; | ||
|
||
public enum XibaoType { | ||
XIBAO( | ||
XibaoPlusPlusMusic.XIBAO_MUSIC, | ||
new Identifier("xibaopp", "textures/xibao.png"), | ||
new Identifier[] { | ||
new Identifier("xibaopp", "textures/yellow_snow.png"), | ||
new Identifier("xibaopp", "textures/red_snow.png") | ||
}, | ||
"xibao" | ||
), | ||
BEIBAO( | ||
XibaoPlusPlusMusic.BEIBAO_MUSIC, | ||
new Identifier("xibaopp", "textures/beibao.png"), | ||
new Identifier[] { | ||
new Identifier("xibaopp", "textures/white_snow.png") | ||
}, | ||
"beibao" | ||
) | ||
; | ||
public final MusicSound music; | ||
public final Identifier background; | ||
public final Identifier[] snows; | ||
public final String type; | ||
|
||
XibaoType(MusicSound music, Identifier background, Identifier[] snows, String type) { | ||
this.music = music; | ||
this.background = background; | ||
this.snows = snows; | ||
this.type = type; | ||
} | ||
|
||
public static XibaoType getByString(String type) { | ||
for (XibaoType xibaoType : values()) { | ||
if (type.equals(xibaoType.type)) return xibaoType; | ||
} | ||
return XIBAO; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/mixin/DisconnectedScreenAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package top.gregtao.xibaopp.mixin; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(DisconnectedScreen.class) | ||
public interface DisconnectedScreenAccessor { | ||
|
||
@Accessor("reason") | ||
Text getReason(); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/mixin/DisconnectedScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package top.gregtao.xibaopp.mixin; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.text.Text; | ||
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.CallbackInfo; | ||
import top.gregtao.xibaopp.SnowAnimation; | ||
import top.gregtao.xibaopp.BackgroundWidget; | ||
import top.gregtao.xibaopp.XibaoPlusPlusConfig; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(DisconnectedScreen.class) | ||
public class DisconnectedScreenMixin extends Screen { | ||
|
||
protected DisconnectedScreenMixin(Text title) { | ||
super(title); | ||
} | ||
|
||
@Inject(method = "init", at = @At("TAIL")) | ||
private void initInject(CallbackInfo ci) { | ||
XibaoPlusPlusConfig.shouldPlayMusic = true; | ||
XibaoPlusPlusConfig.tempSnow = false; | ||
this.addDrawableChild(ButtonWidget.builder(Text.translatable("gui.stopMusic"), | ||
button -> XibaoPlusPlusConfig.shouldPlayMusic = !XibaoPlusPlusConfig.shouldPlayMusic) | ||
.dimensions(this.width / 2 - 100, this.height - 22, 66, 20).build()); | ||
this.addDrawableChild(ButtonWidget.builder( | ||
Text.translatable("gui.dropSnow"), | ||
button -> { | ||
SnowAnimation.INSTANCE = new SnowAnimation(XibaoPlusPlusConfig.random); | ||
XibaoPlusPlusConfig.tempSnow = !XibaoPlusPlusConfig.tempSnow; | ||
}).dimensions(this.width / 2 - 33, this.height - 22, 66, 20).build()); | ||
this.addDrawableChild(ButtonWidget.builder( | ||
Text.translatable("gui.switchAlbum"), | ||
button -> XibaoPlusPlusConfig.switchAlbum()) | ||
.dimensions(this.width / 2 + 34, this.height - 22, 66, 20).build()); | ||
if (XibaoPlusPlusConfig.displaySnow) SnowAnimation.INSTANCE = new SnowAnimation(XibaoPlusPlusConfig.random); | ||
this.addDrawableChild(new BackgroundWidget()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package top.gregtao.xibaopp.mixin; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.sound.MusicSound; | ||
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 top.gregtao.xibaopp.XibaoPlusPlusConfig; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(MinecraftClient.class) | ||
public class MinecraftClientMixin { | ||
|
||
@Inject(method = "getMusicType", at = @At("TAIL"), cancellable = true) | ||
public void getMusicTypeInject(CallbackInfoReturnable<MusicSound> cir) { | ||
if (XibaoPlusPlusConfig.playMusic && XibaoPlusPlusConfig.shouldPlayMusic) { | ||
if (MinecraftClient.getInstance().currentScreen instanceof DisconnectedScreen) { | ||
cir.setReturnValue(XibaoPlusPlusConfig.type.music); | ||
} | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
Fabric-1.20.6/src/main/java/top/gregtao/xibaopp/mixin/ScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package top.gregtao.xibaopp.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.client.gui.screen.Screen; | ||
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.CallbackInfo; | ||
|
||
@Mixin(Screen.class) | ||
public abstract class ScreenMixin { | ||
|
||
@Inject(method = "renderBackground(Lnet/minecraft/client/gui/DrawContext;IIF)V", at = @At("HEAD"), cancellable = true) | ||
public void renderBackgroundInject(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { | ||
Screen screen = MinecraftClient.getInstance().currentScreen; | ||
if (screen instanceof DisconnectedScreen) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
Oops, something went wrong.