Skip to content

Commit

Permalink
Ratstronyu
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Aug 7, 2021
1 parent 927aa43 commit 589a507
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Rat's Mischief 1.2.1 - 1.17.1
- Using the harvest staff will now also make rats holding bone meal fertilize crops
- If a player's inventory is full, rats will keep the item they possess until the owner has made some space
- Added a new rat named type: "Astron" or "Astronyu"

### Rat's Mischief 1.2: Party Rats - 1.17.1
- Twice a year, the 19th of July and 28th of December and each lasting for a week, rats will celebrate respectively RAT's birthday and Rat's Mischief's birthday!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
package ladysnake.ratsmischief.client.gui.screen;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import ladysnake.ratsmischief.common.Mischief;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.NarratorManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class StaffCommandSelectionScreen extends Screen {
static final Identifier TEXTURE = new Identifier("textures/gui/container/gamemode_switcher.png");
private static final int field_32310 = 128;
private static final int field_32311 = 128;
private static final int field_32312 = 26;
private static final int field_32313 = 5;
private static final int field_32314 = 31;
private static final int field_32315 = 5;
private static final int UI_WIDTH = StaffCommandSelectionScreen.GameMode.values().length * 31 - 5;
private static final Text SELECT_NEXT_TEXT;
private final Optional<StaffCommandSelectionScreen.GameMode> currentGameMode = StaffCommandSelectionScreen.GameMode.of(this.getPreviousGameMode());
private Optional<StaffCommandSelectionScreen.GameMode> gameMode = Optional.empty();
private int lastMouseX;
private int lastMouseY;
private boolean mouseUsedForSelection;
private final List<StaffCommandSelectionScreen.ButtonWidget> gameModeButtons = Lists.newArrayList();

public StaffCommandSelectionScreen() {
super(NarratorManager.EMPTY);
}

private net.minecraft.world.GameMode getPreviousGameMode() {
ClientPlayerInteractionManager clientPlayerInteractionManager = MinecraftClient.getInstance().interactionManager;
net.minecraft.world.GameMode gameMode = clientPlayerInteractionManager.getPreviousGameMode();
if (gameMode != null) {
return gameMode;
} else {
return clientPlayerInteractionManager.getCurrentGameMode() == net.minecraft.world.GameMode.CREATIVE ? net.minecraft.world.GameMode.SURVIVAL : net.minecraft.world.GameMode.CREATIVE;
}
}

protected void init() {
super.init();
this.gameMode = this.currentGameMode.isPresent() ? this.currentGameMode : StaffCommandSelectionScreen.GameMode.of(this.client.interactionManager.getCurrentGameMode());

for(int i = 0; i < StaffCommandSelectionScreen.GameMode.VALUES.length; ++i) {
StaffCommandSelectionScreen.GameMode gameMode = StaffCommandSelectionScreen.GameMode.VALUES[i];
this.gameModeButtons.add(new StaffCommandSelectionScreen.ButtonWidget(gameMode, this.width / 2 - UI_WIDTH / 2 + i * 31, this.height / 2 - 31));
}

}

public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
if (!this.checkForClose()) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
matrices.push();
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, TEXTURE);
int i = this.width / 2 - 62;
int j = this.height / 2 - 31 - 27;
drawTexture(matrices, i, j, 0.0F, 0.0F, 125, 75, 128, 128);
matrices.pop();
super.render(matrices, mouseX, mouseY, delta);
this.gameMode.ifPresent((gameMode) -> {
drawCenteredText(matrices, this.textRenderer, gameMode.getText(), this.width / 2, this.height / 2 - 31 - 20, -1);
});
drawCenteredText(matrices, this.textRenderer, SELECT_NEXT_TEXT, this.width / 2, this.height / 2 + 5, 16777215);
if (!this.mouseUsedForSelection) {
this.lastMouseX = mouseX;
this.lastMouseY = mouseY;
this.mouseUsedForSelection = true;
}

boolean bl = this.lastMouseX == mouseX && this.lastMouseY == mouseY;
Iterator var8 = this.gameModeButtons.iterator();

while(var8.hasNext()) {
StaffCommandSelectionScreen.ButtonWidget buttonWidget = (StaffCommandSelectionScreen.ButtonWidget)var8.next();
buttonWidget.render(matrices, mouseX, mouseY, delta);
this.gameMode.ifPresent((gameMode) -> {
buttonWidget.setSelected(gameMode == buttonWidget.gameMode);
});
if (!bl && buttonWidget.isHovered()) {
this.gameMode = Optional.of(buttonWidget.gameMode);
}
}

}
}

private void apply() {
apply(this.client, this.gameMode);
}

private static void apply(MinecraftClient client, Optional<StaffCommandSelectionScreen.GameMode> gameMode) {
if (client.interactionManager != null && client.player != null && gameMode.isPresent()) {
Optional<StaffCommandSelectionScreen.GameMode> optional = StaffCommandSelectionScreen.GameMode.of(client.interactionManager.getCurrentGameMode());
StaffCommandSelectionScreen.GameMode gameMode2 = (StaffCommandSelectionScreen.GameMode)gameMode.get();
if (optional.isPresent() && client.player.hasPermissionLevel(2) && gameMode2 != optional.get()) {
client.player.sendChatMessage(gameMode2.getCommand());
}

}
}

private boolean checkForClose() {
if (InputUtil.isKeyPressed(this.client.getWindow().getHandle(), GLFW.GLFW_KEY_ENTER)) {
this.apply();
this.client.setScreen((Screen)null);
return true;
} else {
return false;
}
}

public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_F4 && this.gameMode.isPresent()) {
this.mouseUsedForSelection = false;
this.gameMode = this.gameMode.get().next();
return true;
} else {
return super.keyPressed(keyCode, scanCode, modifiers);
}
}

public boolean isPauseScreen() {
return false;
}

static {
SELECT_NEXT_TEXT = new TranslatableText("debug.gamemodes.select_next", new Object[]{(new TranslatableText("debug.gamemodes.press_f4")).formatted(Formatting.AQUA)});
}

@Environment(EnvType.CLIENT)
private static enum GameMode {
CREATIVE(new TranslatableText("gameMode.creative"), "/gamemode creative", new ItemStack(Mischief.HARVEST_STAFF)),
SURVIVAL(new TranslatableText("gameMode.survival"), "/gamemode survival", new ItemStack(Mischief.COLLECTION_STAFF)),
ADVENTURE(new TranslatableText("gameMode.adventure"), "/gamemode adventure", new ItemStack(Mischief.LOVE_STAFF)),
SPECTATOR(new TranslatableText("gameMode.spectator"), "/gamemode spectator", new ItemStack(Items.BARRIER));

protected static final StaffCommandSelectionScreen.GameMode[] VALUES = values();
private static final int field_32317 = 16;
protected static final int field_32316 = 5;
final Text text;
final String command;
final ItemStack icon;

private GameMode(Text text, String command, ItemStack icon) {
this.text = text;
this.command = command;
this.icon = icon;
}

void renderIcon(ItemRenderer itemRenderer, int x, int y) {
itemRenderer.renderInGuiWithOverrides(this.icon, x, y);
}

Text getText() {
return this.text;
}

String getCommand() {
return this.command;
}

Optional<StaffCommandSelectionScreen.GameMode> next() {
switch(this) {
case CREATIVE:
return Optional.of(SURVIVAL);
case SURVIVAL:
return Optional.of(ADVENTURE);
case ADVENTURE:
return Optional.of(SPECTATOR);
default:
return Optional.of(CREATIVE);
}
}

static Optional<StaffCommandSelectionScreen.GameMode> of(net.minecraft.world.GameMode gameMode) {
switch(gameMode) {
case SPECTATOR:
return Optional.of(SPECTATOR);
case SURVIVAL:
return Optional.of(SURVIVAL);
case CREATIVE:
return Optional.of(CREATIVE);
case ADVENTURE:
return Optional.of(ADVENTURE);
default:
return Optional.empty();
}
}
}

@Environment(EnvType.CLIENT)
public class ButtonWidget extends ClickableWidget {
final StaffCommandSelectionScreen.GameMode gameMode;
private boolean selected;

public ButtonWidget(StaffCommandSelectionScreen.GameMode gameMode, int x, int y) {
super(x, y, 26, 26, gameMode.getText());
this.gameMode = gameMode;
}

public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
MinecraftClient minecraftClient = MinecraftClient.getInstance();
this.drawBackground(matrices, minecraftClient.getTextureManager());
this.gameMode.renderIcon(StaffCommandSelectionScreen.this.itemRenderer, this.x + 5, this.y + 5);
if (this.selected) {
this.drawSelectionBox(matrices, minecraftClient.getTextureManager());
}

}

public void appendNarrations(NarrationMessageBuilder builder) {
this.appendDefaultNarrations(builder);
}

public boolean isHovered() {
return super.isHovered() || this.selected;
}

public void setSelected(boolean selected) {
this.selected = selected;
}

private void drawBackground(MatrixStack matrices, TextureManager textureManager) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, StaffCommandSelectionScreen.TEXTURE);
matrices.push();
matrices.translate((double)this.x, (double)this.y, 0.0D);
drawTexture(matrices, 0, 0, 0.0F, 75.0F, 26, 26, 128, 128);
matrices.pop();
}

private void drawSelectionBox(MatrixStack matrices, TextureManager textureManager) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, StaffCommandSelectionScreen.TEXTURE);
matrices.push();
matrices.translate((double)this.x, (double)this.y, 0.0D);
drawTexture(matrices, 0, 0, 26.0F, 75.0F, 26, 26, 128, 128);
matrices.pop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public void mobTick() {
this.setRatType(Type.BIGGIE_CHEESE);
} else if (this.getCustomName().getString().equalsIgnoreCase("arathain") || this.getCustomName().getString().equalsIgnoreCase("arathainfarqoe")) {
this.setRatType(Type.ARATHAIN);
} else if (this.getCustomName().getString().equalsIgnoreCase("astron") || this.getCustomName().getString().equalsIgnoreCase("astronyu")) {
this.setRatType(Type.ASTRONYU);
}
}

Expand Down Expand Up @@ -796,7 +798,8 @@ public enum Type {
HOLLOW,
RATELINE,
BIGGIE_CHEESE,
ARATHAIN
ARATHAIN,
ASTRONYU
}

public enum PartyHat {
Expand Down
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 589a507

Please sign in to comment.