Skip to content

Commit

Permalink
Initial 1.18 port
Browse files Browse the repository at this point in the history
Signed-off-by: Noaaan <[email protected]>
  • Loading branch information
Noaaan committed Nov 30, 2021
1 parent 654409f commit 1f05337
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 87 deletions.
60 changes: 31 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
plugins {
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
maven {
name = "Ladysnake Mods"
url = 'https://ladysnake.jfrog.io/artifactory/mods'
}

maven { url "https://maven.shedaniel.me/" }

maven { url 'https://jitpack.io' }
maven { url = "https://ladysnake.jfrog.io/artifactory/mods"}
maven { url = "https://maven.shedaniel.me/" }
maven { url = "https://maven.wispforest.io/"}
mavenCentral()
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cardinal_components_version}"
Expand All @@ -36,34 +28,44 @@ dependencies {
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modRuntime "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"

modRuntime "com.ptsmods:devlogin:1.2"

modImplementation "com.github.glisco03:owo-lib:${project.owo_version}"
modRuntime "com.ptsmods:devlogin:1.2.1"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
// OwO
modImplementation "io.wispforest:owo-lib:${project.owo_version}"
}

processResources {
inputs.property "version", project.version

filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
def targetJavaVersion = 17

tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
from "LICENSE"
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.61
loader_version=0.12.2
minecraft_version=1.18-rc4
yarn_mappings=1.18-rc4+build.1
loader_version=0.12.5
# Mod Properties
mod_version=0.1.2
mod_version=0.1.3
maven_group=com.glisco
archives_base_name=numismatic-overhaul
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.41.0+1.17
cardinal_components_version=3.0.0
rei_version=6.0.307-alpha
owo_version=0.3.0-fixed-rei
fabric_version=0.43.1+1.18
cardinal_components_version=4.0.0
rei_version=7.0.339
owo_version=0.3.6+1.18
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.glisco.numismaticoverhaul.network.ShopScreenHandlerRequestC2SPacket;
import com.glisco.numismaticoverhaul.villagers.data.VillagerTradesResourceListener;
import com.glisco.numismaticoverhaul.villagers.json.VillagerTradesHandler;
import com.glisco.owo.ops.LootOps;
import io.wispforest.owo.ops.LootOps;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.glisco.numismaticoverhaul.ImplementedInventory;
import com.glisco.numismaticoverhaul.NumismaticOverhaul;
import io.wispforest.owo.ops.WorldOps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -28,8 +28,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ShopBlockEntity extends BlockEntity implements ImplementedInventory, SidedInventory, NamedScreenHandlerFactory, BlockEntityClientSerializable {
//TODO - Look over the new methods from this, and see if any need changing
public class ShopBlockEntity extends BlockEntity implements ImplementedInventory, SidedInventory, NamedScreenHandlerFactory {

private final DefaultedList<ItemStack> INVENTORY = DefaultedList.ofSize(27, ItemStack.EMPTY);
private final Merchant merchant;
Expand Down Expand Up @@ -95,15 +95,14 @@ public void addCurrency(int value) {
}

@Override
public NbtCompound writeNbt(NbtCompound tag) {
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
Inventories.writeNbt(tag, INVENTORY);
ShopOffer.toTag(tag, offers);
tag.putInt("StoredCurrency", storedCurrency);
if (owner != null) {
tag.putUuid("Owner", owner);
}
return tag;
}

@Override
Expand Down Expand Up @@ -170,8 +169,12 @@ public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity pl
}

@Override
public void fromClientTag(NbtCompound tag) {
readNbt(tag);
public NbtCompound toInitialChunkDataNbt() {
NbtCompound tag = new NbtCompound();
this.writeNbt(tag);
tag.remove("Items");
tag.remove("StoredCurrency");
return tag;
}

public UUID getOwner() {
Expand All @@ -183,17 +186,9 @@ public void setOwner(UUID owner) {
markDirty();
}

@Override
public NbtCompound toClientTag(NbtCompound tag) {
writeNbt(tag);
tag.remove("Items");
tag.remove("StoredCurrency");
return tag;
}

@Override
public void markDirty() {
super.markDirty();
if (!world.isClient()) this.sync();
WorldOps.updateIfOnServer(world, this.getPos());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.village.Merchant;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOfferList;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
Expand Down Expand Up @@ -69,11 +69,6 @@ public void onSellingItem(ItemStack stack) {

}

@Override
public World getMerchantWorld() {
return shop.getWorld();
}

@Override
public int getExperience() {
return 0;
Expand All @@ -93,4 +88,22 @@ public boolean isLeveledMerchant() {
public SoundEvent getYesSound() {
return SoundEvents.ENTITY_VILLAGER_YES;
}
//TODO - Look at the new methods and see if they cause any issues
// new
@Override
public boolean canRefreshTrades() {
return Merchant.super.canRefreshTrades();
}

// new
@Override
public void sendOffers(PlayerEntity player, Text test, int levelProgress) {
Merchant.super.sendOffers(player, test, levelProgress);
}

// new
@Override
public boolean isClient() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.glisco.numismaticoverhaul.currency.CurrencyConverter;
import com.glisco.numismaticoverhaul.item.CurrencyTooltipData;
import com.glisco.owo.ops.ItemOps;
import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.ops.ItemOps;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.tooltip.TooltipComponent;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void drawText(TextRenderer textRenderer, int x, int y, Matrix4f matrix4f,
}

@Override
public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matrices, ItemRenderer itemRenderer, int z, TextureManager textureManager) {
public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matrices, ItemRenderer itemRenderer, int z) {
List<ItemStack> originalCoins = data.original()[0] != -1 ? CurrencyConverter.getAsItemStackList(data.original()) : new ArrayList<>();
List<ItemStack> coins = CurrencyConverter.getAsItemStackList(data.value());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.glisco.numismaticoverhaul.mixin;

import com.glisco.numismaticoverhaul.NumismaticOverhaul;
import com.glisco.numismaticoverhaul.client.gui.CurrencyTooltipRenderer;
import com.glisco.numismaticoverhaul.currency.CurrencyResolver;
import com.glisco.numismaticoverhaul.item.CurrencyItem;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.MerchantScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.text.TranslatableText;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.text.TranslatableText;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -229,8 +230,9 @@ public TradeOffers.Factory deserialize(JsonObject json) {

int level = json.get("level").getAsInt();
ItemStack item = VillagerJsonHelper.ItemStack_getOrDefault(json, "item", new ItemStack(Items.BOOK));
int base_price = JsonHelper.getInt(json, "base_price", 200);

return new EnchantItemFactory(item, max_uses, villager_experience, level, allow_treasure, price_multiplier);
return new EnchantItemFactory(item, max_uses, villager_experience, level, allow_treasure, price_multiplier, base_price);
}
}

Expand All @@ -241,24 +243,29 @@ private static class EnchantItemFactory implements TradeOffers.Factory {
private final boolean allowTreasure;
private final ItemStack toEnchant;
private final float multiplier;
private final int basePrice;

public EnchantItemFactory(ItemStack item, int maxUses, int experience, int level, boolean allowTreasure, float multiplier) {
public EnchantItemFactory(ItemStack item, int maxUses, int experience, int level, boolean allowTreasure, float multiplier, int basePrice) {
this.experience = experience;
this.maxUses = maxUses;
this.level = level;
this.allowTreasure = allowTreasure;
this.toEnchant = item;
this.multiplier = multiplier;
this.basePrice = basePrice;
}

public TradeOffer create(Entity entity, Random random) {
ItemStack itemStack = toEnchant.copy();
itemStack = EnchantmentHelper.enchant(random, itemStack, level, allowTreasure);

int price = 150;

int price = basePrice;
// TODO - Make algorithm return smaller values + decrease toolsmith and weaponsmith prices
for (Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.get(itemStack).entrySet()) {
price *= (entry.getKey().isTreasure() ? 2f : 1f) * (MathHelper.nextFloat(random, entry.getValue(), entry.getKey().getMaxLevel())) * (5f / (float) entry.getKey().getRarity().getWeight());
price *= (entry.getKey().isTreasure() ? 2f : 1f) *
(MathHelper.nextFloat(
random,
entry.getValue(),
entry.getKey().getMaxLevel())) * (5f / (float) entry.getKey().getRarity().getWeight());
}

return new TradeOffer(CurrencyHelper.getClosest(price), toEnchant, itemStack, maxUses, this.experience, multiplier);
Expand Down
Loading

0 comments on commit 1f05337

Please sign in to comment.