Skip to content

Commit

Permalink
1.20.2 Port (#16)
Browse files Browse the repository at this point in the history
* Initial port to 1.20.2.

* Fix SnailInventoryScreen entity positioning.

* Update according to review.

* Optimise PNGs.

* Recompress assets.

---------

Co-authored-by: LambdAurora <email@lambdaurora.dev>
  • Loading branch information
MerchantPug and LambdAurora committed Nov 11, 2023
1 parent 2b91155 commit d21c169
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 23 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.jvmargs=-Xmx1G

# Quilt properties
minecraft_version=1.20.1
quilt_mappings=23
loader_version=0.14.21
fabric_api_version=0.84.0+1.20.1
minecraft_version=1.20.2
quilt_mappings=3
loader_version=0.14.24
fabric_api_version=0.90.7+1.20.2

# Mod properties
mod_version=1.1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidgetStateTextures;
import net.minecraft.client.gui.widget.button.TexturedButtonWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundManager;
Expand Down Expand Up @@ -84,13 +85,13 @@ protected void init() {

int x = (this.width - this.backgroundWidth) / 2;
int y = (this.height - this.backgroundHeight) / 2;
this.addDrawableChild(this.enderChestButton = new EnderChestButton(x + 7 + 18, y + 35 + 18));
this.addDrawableSelectableElement(this.enderChestButton = new EnderChestButton(x + 7 + 18, y + 35 + 18));
this.getScreenHandler().getInventory().addListener(this.enderChestButton);

int buttonX = x + this.backgroundWidth - 3;
int buttonY = y + 17;
for (int page = 0; page < 3; page++) {
this.addDrawableChild(this.pageButtons[page] = new PageButton(buttonX, buttonY, page));
this.addDrawableSelectableElement(this.pageButtons[page] = new PageButton(buttonX, buttonY, page));
this.getScreenHandler().getInventory().addListener(this.pageButtons[page]);
this.getScreenHandler().addPageChangeListener(this.pageButtons[page]);
}
Expand All @@ -111,17 +112,17 @@ public void closeScreen() {
/* Input */

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
int x = (this.width - this.backgroundWidth) / 2;
int y = (this.height - this.backgroundHeight) / 2;
if (mouseX > x + 98 && mouseY > y + 17 && mouseX <= x + 98 + 5 * 18 && mouseY <= y + 17 + 54) {
int oldPage = this.getScreenHandler().getCurrentStoragePage();
int newPage = MathHelper.clamp(oldPage + (amount > 0 ? -1 : 1), 0, 2);
int newPage = MathHelper.clamp(oldPage + (scrollY > 0 ? -1 : 1), 0, 2);
if (oldPage == newPage)
return true;

if (!this.getScreenHandler().hasChest(newPage)) {
int otherNewPage = MathHelper.clamp(newPage + (amount > 0 ? -1 : 1), 0, 2);
int otherNewPage = MathHelper.clamp(newPage + (scrollY > 0 ? -1 : 1), 0, 2);
if (newPage == otherNewPage || !this.getScreenHandler().hasChest(otherNewPage))
return true;

Expand All @@ -131,7 +132,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
this.getScreenHandler().requestStoragePage(newPage);
return true;
}
return super.mouseScrolled(mouseX, mouseY, amount);
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
}

/* Rendering */
Expand Down Expand Up @@ -161,15 +162,18 @@ protected void drawBackground(GuiGraphics graphics, float delta, int mouseX, int
}

InventoryScreen.drawEntity(
graphics, x + 70, y + 60, 17,
(x + 51) - this.mouseX, (y + 75 - 50) - this.mouseY,
graphics, x + 40, y + 8,
x + 100,
y + 70, 17,
0.25f,
this.mouseX, this.mouseY,
this.entity
);
}

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.renderBackground(graphics);
this.renderBackground(graphics, mouseX, mouseY, delta);
this.mouseX = mouseX;
this.mouseY = mouseY;
super.render(graphics, mouseX, mouseY, delta);
Expand All @@ -178,8 +182,10 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {

private class EnderChestButton extends TexturedButtonWidget implements InventoryChangedListener {
public EnderChestButton(int x, int y) {
super(x, y, 18, 18, 0, 0, 18, LovelySnails.id("textures/gui/snail_ender_chest_button.png"),
18, 36,
super(x, y, 18, 18,
new ClickableWidgetStateTextures(
LovelySnails.id("snail_ender_chest_button"),
LovelySnails.id("snail_ender_chest_button_highlighted")),
btn -> {
var client = MinecraftClient.getInstance();
var screenHandler = SnailInventoryScreen.this.getScreenHandler();
Expand All @@ -203,8 +209,11 @@ private class PageButton extends TexturedButtonWidget implements InventoryChange
private final int page;

public PageButton(int x, int y, int page) {
super(x, y + page * 18 + 1, 15, 16, 211 + page * 15, 0, 16, TEXTURE,
256, 256,
super(x, y + page * 18 + 1, 15, 16,
new ClickableWidgetStateTextures(
LovelySnails.id("container/snail_page_" + (page + 1) + "_button"),
LovelySnails.id("container/snail_page_" + (page + 1) + "_button_highlighted")
),
btn -> {
SnailInventoryScreen.this.getScreenHandler().requestStoragePage(page);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void setScared(boolean scared) {
this.setSnailFlag(SCARED_FLAG, scared);

if (!this.getWorld().isClient()) {
this.getAttributeInstance(EntityAttributes.GENERIC_ARMOR).removeModifier(SCARED_ARMOR_BONUS);
this.getAttributeInstance(EntityAttributes.GENERIC_ARMOR).removeModifier(SCARED_ARMOR_BONUS.getId());
if (scared) {
this.getAttributeInstance(EntityAttributes.GENERIC_ARMOR).addPersistentModifier(SCARED_ARMOR_BONUS);
}
Expand Down Expand Up @@ -292,11 +292,11 @@ public void setCarpetColor(@Nullable DyeColor color) {
}

@Override
public double getMountedHeightOffset() {
public float getHeightOffset(Entity entity) {
if (!this.isBaby())
return this.getDimensions(EntityPose.STANDING).height * 0.95f;
else
return super.getMountedHeightOffset();
return super.getHeightOffset(entity);
}

@Override
Expand Down Expand Up @@ -827,7 +827,7 @@ public void setBreedingAge(int age) {

@Override
protected void onGrowUp() {
if (!this.getWorld().isClient() && !this.isBaby() && this.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
if (!this.getWorld().isClient() && !this.isBaby() && this.getWorld().getGameRules().getBooleanValue(GameRules.DO_MOB_LOOT)) {
this.dropStack(new ItemStack(Items.SLIME_BALL, 1 + this.random.nextInt(2)));
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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.
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.
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.
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.
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"depends": {
"minecraft": "~1.20",
"fabricloader": ">=0.14.20",
"fabric": ">=0.83.0",
"fabric-api": ">=0.89.0",
"java": ">=17"
},
"recommends": {
Expand Down

0 comments on commit d21c169

Please sign in to comment.