Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 25, 2024
1 parent 028e884 commit a4c5fe0
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7.+'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
}
Expand Down Expand Up @@ -29,7 +29,7 @@ dependencies {

modImplementation include("eu.pb4:map-canvas-api:${project.mapcanvas_version}")
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
modImplementation include("me.lucko:fabric-permissions-api:0.3.2")
}

loom {
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.1
loader_version=0.16.7

# Mod Properties
mod_version = 0.7.1+1.21
mod_version = 0.8.0+1.21.3
maven_group = space.essem
archives_base_name = image2map

# Dependencies
fabric_version=0.100.1+1.21
mapcanvas_version=0.4.1+1.21
sgui_version=1.6.0+1.21
fabric_version=0.106.1+1.21.3
mapcanvas_version=0.5.0+1.21.3
sgui_version=1.7.2+1.21.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/space/essem/image2map/Image2Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onInitialize() {
)
)
.then(literal("create-folder")
.requires(Permissions.require("image2map.createfolder", 3))
.requires(Permissions.require("image2map.createfolder", 3).and(x -> CONFIG.allowLocalFiles))
.then(argument("width", IntegerArgumentType.integer(1))
.then(argument("height", IntegerArgumentType.integer(1))
.then(argument("mode", StringArgumentType.word()).suggests(new DitherModeSuggestionProvider())
Expand Down Expand Up @@ -216,7 +216,7 @@ private CompletableFuture<BufferedImage> getImage(String input) {
}

private List<BufferedImage> getImageFromFolder(String input) {
if (CONFIG.allowLocalFiles || true) {
if (CONFIG.allowLocalFiles) {
try {
var arr = new ArrayList<BufferedImage>();
var path = FabricLoader.getInstance().getGameDir().resolve(input);
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/space/essem/image2map/gui/MapGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.passive.HorseEntity;
import net.minecraft.entity.player.PlayerPosition;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -24,12 +25,14 @@
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.PlayerInput;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

import org.jetbrains.annotations.Nullable;
import space.essem.image2map.mixin.EntityPassengersSetS2CPacketAccessor;
Expand Down Expand Up @@ -96,7 +99,7 @@ public MapGui(ServerPlayerEntity player, int width, int height) {
protected void resizeCanvas(int width, int height) {
this.destroy();
this.initialize(width, height);
this.player.networkHandler.sendPacket(new EntityPositionS2CPacket(this.entity));
this.player.networkHandler.sendPacket(new EntityPositionS2CPacket(this.entity.getId(), new PlayerPosition(this.entity.getPos(), Vec3d.ZERO, this.entity.getYaw(), this.entity.getPitch()), Set.of(), false));
}

protected void initialize(int width, int height) {
Expand Down Expand Up @@ -150,7 +153,7 @@ public void onClose() {
this.player.networkHandler.sendPacket(new EntitiesDestroyS2CPacket(this.additionalEntities));
}
this.player.networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.GAME_MODE_CHANGED, this.player.interactionManager.getGameMode().getId()));
this.player.networkHandler.sendPacket(new PlayerPositionLookS2CPacket(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYaw(), this.player.getPitch(), EnumSet.noneOf(PositionFlag.class), 0));
this.player.networkHandler.sendPacket(new PlayerPositionLookS2CPacket(this.entity.getId(), new PlayerPosition(this.entity.getPos(), Vec3d.ZERO, this.entity.getYaw(), this.entity.getPitch()), Set.of()));

super.onClose();
}
Expand Down Expand Up @@ -196,7 +199,7 @@ public boolean onClickEntity(int entityId, EntityInteraction type, boolean isSne

public void setDistance(double i) {
this.entity.setPos(this.entity.getX(), this.entity.getY(), this.pos.getZ() - i);
this.player.networkHandler.sendPacket(new EntityPositionS2CPacket(this.entity));
this.player.networkHandler.sendPacket(new EntityPositionS2CPacket(this.entity.getId(), new PlayerPosition(this.entity.getPos(), Vec3d.ZERO, this.entity.getYaw(), this.entity.getPitch()), Set.of(), false));
}

@Override
Expand All @@ -207,8 +210,7 @@ public boolean onPlayerAction(PlayerActionC2SPacket.Action action, Direction dir
return false;
}

// deltaX/Z is currently useless while in camera mode, as it is always 0
public void onPlayerInput(float deltaX, float deltaZ, boolean jumping, boolean shiftKeyDown) {
public void onPlayerInput(PlayerInput input) {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package space.essem.image2map.mixin;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.util.ActionResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -10,24 +11,22 @@
import net.minecraft.inventory.StackReference;
import net.minecraft.item.BundleItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.ClickType;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

@Mixin(BundleItem.class)
public class BundleItemMixin {

@Inject(method = "use", at = @At("HEAD"), cancellable = true)
private void image2map$useBundle(World world, PlayerEntity user, Hand hand,
CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
CallbackInfoReturnable<ActionResult> cir) {
ItemStack itemStack = user.getStackInHand(hand);
var tag = itemStack.get(DataComponentTypes.CUSTOM_DATA);

if (tag != null && tag.contains("image2map:quick_place") && !user.isCreative()) {
cir.setReturnValue(TypedActionResult.fail(itemStack));
cir.setReturnValue(ActionResult.FAIL);
cir.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;

Expand All @@ -30,13 +31,12 @@ public class ItemFrameEntityMixin {
}

@Inject(method = "dropHeldStack", at = @At("HEAD"), cancellable = true)
private void image2map$destroyMaps(@Nullable Entity entity, boolean alwaysDrop,
CallbackInfo ci) {
private void image2map$destroyMaps(ServerWorld world, Entity entity, boolean dropSelf, CallbackInfo ci) {
var frame = (ItemFrameEntity) (Object) this;

if (!this.fixed && Image2Map.destroyItemFrame(entity, frame)) {
if (alwaysDrop) {
frame.dropStack(new ItemStack(Items.ITEM_FRAME));
if (dropSelf) {
frame.dropStack(world, new ItemStack(Items.ITEM_FRAME));
}
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.entity.player.PlayerEntity;

import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -17,9 +18,9 @@ public class PlayerEntityMixin {

@Shadow public ScreenHandler currentScreenHandler;

@Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z", shift = At.Shift.BEFORE))
private void image2map$closeOnDamage(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
if (f > 0 && this.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) {
@Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;damage(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/damage/DamageSource;F)Z", shift = At.Shift.BEFORE))
private void image2map$closeOnDamage(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (amount > 0 && this.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) {
computerGui.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co
private void image2map$onPlayerInput(PlayerInputC2SPacket packet, CallbackInfo ci) {
if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) {
this.server.execute(() -> {
computerGui.onPlayerInput(packet.getForward(), packet.getSideways(), packet.isJumping(), packet.isSneaking());
computerGui.onPlayerInput(packet.input());
});
ci.cancel();
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/space/essem/image2map/renderer/MapRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ public static List<ItemStack> toVanillaItems(CanvasImage image, ServerWorld worl

private static int mapColorToRGBColor(CanvasColor color) {
var mcColor = color.getRgbColor();
double[] mcColorVec = { (double) ColorHelper.Argb.getRed(mcColor), (double) ColorHelper.Argb.getGreen(mcColor), (double) ColorHelper.Argb.getBlue(mcColor) };
double[] mcColorVec = { (double) ColorHelper.getRed(mcColor), (double) ColorHelper.getGreen(mcColor), (double) ColorHelper.getBlue(mcColor) };
double coeff = shadeCoeffs[color.getColor().id & 3];
return ColorHelper.Argb.getArgb(0, (int) (mcColorVec[0] * coeff), (int) (mcColorVec[1] * coeff), (int) (mcColorVec[2] * coeff));
return ColorHelper.getArgb(0, (int) (mcColorVec[0] * coeff), (int) (mcColorVec[1] * coeff), (int) (mcColorVec[2] * coeff));
}

private static CanvasColor floydDither(int[][] pixels, int x, int y, int imageColor) {
var closestColor = CanvasUtils.findClosestColorARGB(imageColor);
var palletedColor = mapColorToRGBColor(closestColor);

var errorR = ColorHelper.Argb.getRed(imageColor) - ColorHelper.Argb.getRed(palletedColor);
var errorG = ColorHelper.Argb.getGreen(imageColor) - ColorHelper.Argb.getGreen(palletedColor);
var errorB = ColorHelper.Argb.getBlue(imageColor) - ColorHelper.Argb.getBlue(palletedColor);
var errorR = ColorHelper.getRed(imageColor) - ColorHelper.getRed(palletedColor);
var errorG = ColorHelper.getGreen(imageColor) - ColorHelper.getGreen(palletedColor);
var errorB = ColorHelper.getBlue(imageColor) - ColorHelper.getBlue(palletedColor);
if (pixels[0].length > x + 1) {
pixels[y][x + 1] = applyError(pixels[y][x + 1], errorR, errorG, errorB, 7.0 / 16.0);
}
Expand All @@ -178,10 +178,10 @@ private static CanvasColor floydDither(int[][] pixels, int x, int y, int imageCo
}

private static int applyError(int pixelColor, int errorR, int errorG, int errorB, double quantConst) {
int pR = clamp( ColorHelper.Argb.getRed(pixelColor) + (int) ((double) errorR * quantConst), 0, 255);
int pG = clamp(ColorHelper.Argb.getGreen(pixelColor) + (int) ((double) errorG * quantConst), 0, 255);
int pB = clamp(ColorHelper.Argb.getBlue(pixelColor) + (int) ((double) errorB * quantConst), 0, 255);
return ColorHelper.Argb.getArgb(ColorHelper.Argb.getAlpha(pixelColor), pR, pG, pB);
int pR = clamp( ColorHelper.getRed(pixelColor) + (int) ((double) errorR * quantConst), 0, 255);
int pG = clamp(ColorHelper.getGreen(pixelColor) + (int) ((double) errorG * quantConst), 0, 255);
int pB = clamp(ColorHelper.getBlue(pixelColor) + (int) ((double) errorB * quantConst), 0, 255);
return ColorHelper.getArgb(ColorHelper.getAlpha(pixelColor), pR, pG, pB);
}

private static int clamp(int i, int min, int max) {
Expand Down

0 comments on commit a4c5fe0

Please sign in to comment.