Skip to content

Commit

Permalink
Initial 1.17 Port
Browse files Browse the repository at this point in the history
  • Loading branch information
Noaaan committed Jun 21, 2021
1 parent 833fbc3 commit 8b68700
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/remappedSrc/
41 changes: 6 additions & 35 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '0.7-SNAPSHOT'
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand All @@ -31,8 +31,8 @@ dependencies {
modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cardinal_components_version}"
modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${project.cardinal_components_version}"

modCompileOnly "me.shedaniel:RoughlyEnoughItems-api:${project.rei_version}"
modRuntime "me.shedaniel:RoughlyEnoughItems:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modRuntime "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand All @@ -41,19 +41,11 @@ dependencies {
processResources {
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
Expand All @@ -69,24 +61,3 @@ task sourcesJar(type: Jar, dependsOn: classes) {
jar {
from "LICENSE"
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.3
minecraft_version=1.17
yarn_mappings=1.17+build.13
loader_version=0.11.6
# Mod Properties
mod_version=0.1
maven_group=com.glisco
archives_base_name=numismatic-overhaul
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.31.0+1.16
cardinal_components_version=2.7.13
rei_version=5.11.202
fabric_version=0.36.0+1.17
cardinal_components_version=3.0.0
rei_version=6.0.246-alpha
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-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer;
import nerdhub.cardinal.components.api.util.RespawnCopyStrategy;
import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy;
import net.minecraft.util.Identifier;

public class ModComponents implements EntityComponentInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void onInitialize() {

Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "shop"), SHOP_BLOCK);
Registry.register(Registry.ITEM, new Identifier(MOD_ID, "shop"), new BlockItem(SHOP_BLOCK, new Item.Settings().group(ItemGroup.MISC)));
SHOP_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MOD_ID, "shop"), BlockEntityType.Builder.create(ShopBlockEntity::new, SHOP_BLOCK).build(null));
SHOP_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MOD_ID, "shop"), FabricBlockEntityTypeBuilder.create(ShopBlockEntity::new, SHOP_BLOCK).build(null));

ServerPlayNetworking.registerGlobalReceiver(RequestPurseActionC2SPacket.ID, RequestPurseActionC2SPacket::onPacket);
ServerPlayNetworking.registerGlobalReceiver(ShopScreenHandlerRequestC2SPacket.ID, ShopScreenHandlerRequestC2SPacket::onPacket);
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/glisco/numismaticoverhaul/block/ShopBlock.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.glisco.numismaticoverhaul.block;

import com.glisco.numismaticoverhaul.NumismaticOverhaul;
import com.glisco.numismaticoverhaul.currency.CurrencyStack;
import com.glisco.numismaticoverhaul.network.UpdateShopScreenS2CPacket;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -39,12 +42,6 @@ public ShopBlock() {
super(FabricBlockSettings.of(Material.STONE).breakByTool(FabricToolTags.PICKAXES).nonOpaque().hardness(5.0f));
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockView world) {
return new ShopBlockEntity();
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
Expand Down Expand Up @@ -108,4 +105,16 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
super.onStateReplaced(state, world, pos, newState, moved);
}
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new ShopBlockEntity(pos, state);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return checkType(type, NumismaticOverhaul.SHOP_BLOCK_ENTITY, ShopBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Tickable;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.village.Merchant;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ShopBlockEntity extends BlockEntity implements ImplementedInventory, SidedInventory, NamedScreenHandlerFactory, BlockEntityClientSerializable, Tickable {
public class ShopBlockEntity extends BlockEntity implements ImplementedInventory, SidedInventory, NamedScreenHandlerFactory, BlockEntityClientSerializable {

private final DefaultedList<ItemStack> INVENTORY = DefaultedList.ofSize(27, ItemStack.EMPTY);
private final Merchant merchant;
Expand All @@ -38,8 +39,8 @@ public class ShopBlockEntity extends BlockEntity implements ImplementedInventory

private int tradeIndex;

public ShopBlockEntity() {
super(NumismaticOverhaul.SHOP_BLOCK_ENTITY);
public ShopBlockEntity(BlockPos pos, BlockState state) {
super(NumismaticOverhaul.SHOP_BLOCK_ENTITY, pos, state);
this.merchant = new ShopMerchant(this);
this.offers = new ArrayList<>();
this.storedCurrency = 0;
Expand Down Expand Up @@ -94,9 +95,9 @@ public void addCurrency(int value) {
}

@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
Inventories.toTag(tag, INVENTORY);
public NbtCompound writeNbt(NbtCompound tag) {
super.writeNbt(tag);
Inventories.writeNbt(tag, INVENTORY);
ShopOffer.toTag(tag, offers);
tag.putInt("StoredCurrency", storedCurrency);
if (owner != null) {
Expand All @@ -106,9 +107,9 @@ public CompoundTag toTag(CompoundTag tag) {
}

@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
Inventories.fromTag(tag, INVENTORY);
public void readNbt(NbtCompound tag) {
super.readNbt(tag);
Inventories.readNbt(tag, INVENTORY);
ShopOffer.fromTag(tag, offers);
if (tag.contains("Owner")) {
owner = tag.getUuid("Owner");
Expand Down Expand Up @@ -148,7 +149,10 @@ public void deleteOffer(ItemStack stack) {
this.markDirty();
}

@Override
public static void tick(World world, BlockPos pos, BlockState state, ShopBlockEntity blockEntity) {
blockEntity.tick();
}

public void tick() {
if (world.getTime() % 60 == 0) tradeIndex++;
}
Expand All @@ -166,8 +170,8 @@ public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity pl
}

@Override
public void fromClientTag(CompoundTag tag) {
fromTag(getCachedState(), tag);
public void fromClientTag(NbtCompound tag) {
readNbt(tag);
}

public UUID getOwner() {
Expand All @@ -180,8 +184,8 @@ public void setOwner(UUID owner) {
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
toTag(tag);
public NbtCompound toClientTag(NbtCompound tag) {
writeNbt(tag);
tag.remove("Items");
tag.remove("StoredCurrency");
return tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void trade(TradeOffer offer) {
shop.getItems().forEach(itemStack -> {
ItemStack comparisonStack = itemStack.copy();
comparisonStack.setCount(1);
if (!ItemStack.areEqual(comparisonStack, offer.getSellItem())) return;
if (!ItemStack.areEqual(comparisonStack, offer.copySellItem())) return;
itemStack.decrement(1);
});

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/glisco/numismaticoverhaul/block/ShopOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.glisco.numismaticoverhaul.currency.CurrencyStack;
import com.glisco.numismaticoverhaul.item.MoneyBagItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.village.TradeOffer;

import java.util.List;
Expand Down Expand Up @@ -46,16 +46,16 @@ public ItemStack getSellStack() {
return sell.copy();
}

public static CompoundTag toTag(CompoundTag tag, List<ShopOffer> offers) {
public static NbtCompound toTag(NbtCompound tag, List<ShopOffer> offers) {

ListTag offerList = new ListTag();
NbtList offerList = new NbtList();

for (ShopOffer offer : offers) {
CompoundTag offerTag = new CompoundTag();
NbtCompound offerTag = new NbtCompound();
offerTag.putInt("Price", offer.getPrice());

CompoundTag item = new CompoundTag();
offer.getSellStack().toTag(item);
NbtCompound item = new NbtCompound();
offer.getSellStack().writeNbt(item);

offerTag.put("Item", item);

Expand All @@ -67,19 +67,19 @@ public static CompoundTag toTag(CompoundTag tag, List<ShopOffer> offers) {
return tag;
}

public static void fromTag(CompoundTag tag, List<ShopOffer> offers) {
public static void fromTag(NbtCompound tag, List<ShopOffer> offers) {

offers.clear();

ListTag offerList = tag.getList("Offers", 10);
NbtList offerList = tag.getList("Offers", 10);

for (Tag offerTag : offerList) {
for (NbtElement offerTag : offerList) {

CompoundTag offer = (CompoundTag) offerTag;
NbtCompound offer = (NbtCompound) offerTag;

int price = offer.getInt("Price");

ItemStack sell = ItemStack.fromTag(offer.getCompound("Item"));
ItemStack sell = ItemStack.fromNbt(offer.getCompound("Item"));

offers.add(new ShopOffer(sell, price));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public AutoHidingSlot(Inventory inventory, int index, int x, int y, int targetTa

@Override
@Environment(EnvType.CLIENT)
public boolean doDrawHoveringEffect() {
public boolean isEnabled() {
if (!(MinecraftClient.getInstance().currentScreen instanceof ShopScreen)) return true;
if (hide) {
return ((ShopScreen) MinecraftClient.getInstance().currentScreen).getSelectedTab() != targetTab;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class NumismaticOverhaulClient implements ClientModInitializer {
public void onInitializeClient() {
ScreenRegistry.register(NumismaticOverhaul.SHOP_SCREEN_HANDLER_TYPE, ShopScreen::new);

FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.BRONZE_COIN, new Identifier("coins"), (stack, world, entity) -> stack.getCount() / 100.0f);
FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.SILVER_COIN, new Identifier("coins"), (stack, world, entity) -> stack.getCount() / 100.0f);
FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.GOLD_COIN, new Identifier("coins"), (stack, world, entity) -> stack.getCount() / 100.0f);
FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.BRONZE_COIN, new Identifier("coins"), (stack, world, entity, seed) -> stack.getCount() / 100.0f);
FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.SILVER_COIN, new Identifier("coins"), (stack, world, entity, seed) -> stack.getCount() / 100.0f);
FabricModelPredicateProviderRegistry.register(NumismaticOverhaul.GOLD_COIN, new Identifier("coins"), (stack, world, entity, seed) -> stack.getCount() / 100.0f);

ClientPlayNetworking.registerGlobalReceiver(UpdateShopScreenS2CPacket.ID, UpdateShopScreenS2CPacket::onPacket);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3f;

public class ShopBlockEntityRender extends BlockEntityRenderer<ShopBlockEntity> {
public class ShopBlockEntityRender implements BlockEntityRenderer<ShopBlockEntity> {

public ShopBlockEntityRender(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher);
public ShopBlockEntityRender(BlockEntityRendererFactory.Context context) {
super();
}

@Override
Expand All @@ -37,9 +38,9 @@ public void render(ShopBlockEntity entity, float tickDelta, MatrixStack matrices
float scale = isBlockItem ? 0.95f : 0.85f;
matrices.scale(scale, scale, scale);

matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion((float) (System.currentTimeMillis() / 20d % 360d)));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion((float) (System.currentTimeMillis() / 20d % 360d)));

client.getItemRenderer().renderItem(toRender, ModelTransformation.Mode.GROUND, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers);
client.getItemRenderer().renderItem(toRender, ModelTransformation.Mode.GROUND, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, 0);

matrices.pop();

Expand Down
Loading

0 comments on commit 8b68700

Please sign in to comment.