Skip to content

Commit

Permalink
Port to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
fonnymunkey committed Jun 9, 2023
1 parent 17a8c56 commit d43108e
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.17
minecraft_version=1.20
yarn_mappings=1.20+build.1
loader_version=0.14.21

# Mod Properties
mod_version = 0.2.0
maven_group = fonnymunkey
archives_base_name = simplehats

# Dependencies
fabric_version=0.76.0+1.19.4
trinkets_version=3.6.0
cloth_config_version=10.0.96
cc_version=5.1.0
modmenu_version=6.1.0-rc.2
fabric_version=0.83.0+1.20
trinkets_version=3.7.0
cloth_config_version=11.0.99
cc_version=5.2.0
modmenu_version=5.0.2
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.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
39 changes: 36 additions & 3 deletions src/main/java/fonnymunkey/simplehats/SimpleHats.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -29,9 +34,7 @@ public class SimpleHats implements ModInitializer {
public static Logger logger = LogManager.getLogger();
public static ModConfig config;

public static ItemGroup HAT_TAB = FabricItemGroup.builder(new Identifier(modId, "hat_group"))
.icon(() -> new ItemStack(ModRegistry.HATICON))
.build();
public static RegistryKey<ItemGroup> HAT_TAB = RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(modId, "hat_group"));

@Override
public void onInitialize() {
Expand All @@ -46,6 +49,34 @@ public void onInitialize() {

ModRegistry.registerHats();

Registry.register(Registries.ITEM_GROUP, HAT_TAB, FabricItemGroup.builder()
.icon(() -> new ItemStack(ModRegistry.HATICON))
.displayName(Text.translatable("itemGroup.simplehats.hat_group"))
.entries((context, entries) -> {
entries.add(ModRegistry.HATBAG_COMMON);
entries.add(ModRegistry.HATBAG_UNCOMMON);
entries.add(ModRegistry.HATBAG_RARE);
entries.add(ModRegistry.HATBAG_EPIC);
entries.add(ModRegistry.HATBAG_EASTER);
entries.add(ModRegistry.HATBAG_SUMMER);
entries.add(ModRegistry.HATBAG_HALLOWEEN);
entries.add(ModRegistry.HATBAG_FESTIVE);
entries.add(ModRegistry.HATSCRAPS_COMMON);
entries.add(ModRegistry.HATSCRAPS_UNCOMMON);
entries.add(ModRegistry.HATSCRAPS_RARE);
entries.add(ModRegistry.HATSCRAPS_EASTER);
entries.add(ModRegistry.HATSCRAPS_SUMMER);
entries.add(ModRegistry.HATSCRAPS_HALLOWEEN);
entries.add(ModRegistry.HATSCRAPS_FESTIVE);
entries.add(ModRegistry.HATICON);
entries.add(ModRegistry.HATDISPLAYITEM);

for(HatItem hat : ModRegistry.hatList) {
entries.add(hat);
}
})
.build());
/*
ItemGroupEvents.modifyEntriesEvent(HAT_TAB).register(content -> {
content.add(ModRegistry.HATBAG_COMMON);
content.add(ModRegistry.HATBAG_UNCOMMON);
Expand All @@ -70,6 +101,8 @@ public void onInitialize() {
}
});
*/

FabricDefaultAttributeRegistry.register(ModRegistry.HATDISPLAYENTITY, HatDisplay.createLivingAttributes());

LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Identifier getTexture(HatDisplay entity) {

protected void setupTransforms(HatDisplay entityLiving, MatrixStack matrixStack, float ageInTicks, float rotationYaw, float partialTicks) {
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F - rotationYaw));
float f = (float)(entityLiving.world.getTime() - entityLiving.lastHit) + partialTicks;
float f = (float)(entityLiving.getWorld().getTime() - entityLiving.lastHit) + partialTicks;
if(f < 5.0F) matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(MathHelper.sin(f / 1.5F * (float)Math.PI) * 3.0F));
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/fonnymunkey/simplehats/common/entity/HatDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ActionResult interactAt(PlayerEntity player, Vec3d vec3, Hand hand) {
if(player.isSpectator()) {
return ActionResult.SUCCESS;
}
else if(player.world.isClient()) {
else if(player.getWorld().isClient()) {
return ActionResult.CONSUME;
}
else {
Expand Down Expand Up @@ -172,7 +172,7 @@ else if(!stack.isEmpty() && stack.getCount() > 1) {

@Override
public boolean damage(DamageSource source, float amount) {
if(!this.world.isClient() && !this.isRemoved()) {
if(!this.getWorld().isClient() && !this.isRemoved()) {
if(source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
this.kill();
return false;
Expand Down Expand Up @@ -213,9 +213,9 @@ else if(source.isSourceCreativePlayer()) {
return flag1;
}
else {
long i = this.world.getTime();
long i = this.getWorld().getTime();
if(i - this.lastHit > 5L && !flag) {
this.world.sendEntityStatus(this, (byte)32);
this.getWorld().sendEntityStatus(this, (byte)32);
this.emitGameEvent(GameEvent.ENTITY_DAMAGE, source.getAttacker());
this.lastHit = i;
}
Expand All @@ -240,9 +240,9 @@ else if(source.isSourceCreativePlayer()) {
@Override
public void handleStatus(byte id) {
if(id == 32) {
if(this.world.isClient()) {
this.world.playSound(this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_ARMOR_STAND_HIT, this.getSoundCategory(), 0.3F, 1.0F, false);
this.lastHit = this.world.getTime();
if(this.getWorld().isClient()) {
this.getWorld().playSound(this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_ARMOR_STAND_HIT, this.getSoundCategory(), 0.3F, 1.0F, false);
this.lastHit = this.getWorld().getTime();
}
}
else {
Expand All @@ -251,8 +251,8 @@ public void handleStatus(byte id) {
}

private void spawnBreakParticles() {
if(this.world instanceof ServerWorld) {
((ServerWorld)this.world).spawnParticles(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.OAK_PLANKS.getDefaultState()), this.getX(), this.getBodyY(0.66D), this.getZ(), 10, (double)(this.getWidth() / 4.0F), (double)(this.getHeight() / 4.0F), (double)(this.getWidth() / 4.0F), 0.05D);
if(this.getWorld() instanceof ServerWorld) {
((ServerWorld)this.getWorld()).spawnParticles(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.OAK_PLANKS.getDefaultState()), this.getX(), this.getBodyY(0.66D), this.getZ(), 10, (double)(this.getWidth() / 4.0F), (double)(this.getHeight() / 4.0F), (double)(this.getWidth() / 4.0F), 0.05D);
}
}

Expand All @@ -269,7 +269,7 @@ private void updateHealth(DamageSource source, float dmg) {
}

private void breakAndDropItem(DamageSource source) {
Block.dropStack(this.world, this.getBlockPos(), new ItemStack(ModRegistry.HATDISPLAYITEM));
Block.dropStack(this.getWorld(), this.getBlockPos(), new ItemStack(ModRegistry.HATDISPLAYITEM));
this.onBreak(source);
}

Expand All @@ -279,13 +279,13 @@ private void onBreak(DamageSource source) {

ItemStack itemStack = this.hatItemSlots.get(0);
if(!itemStack.isEmpty()) {
Block.dropStack(this.world, this.getBlockPos().up(), itemStack);
Block.dropStack(this.getWorld(), this.getBlockPos().up(), itemStack);
this.hatItemSlots.set(0, ItemStack.EMPTY);
}
}

private void playBreakSound() {
this.world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_ARMOR_STAND_BREAK, this.getSoundCategory(), 1.0F, 1.0F);
this.getWorld().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_ARMOR_STAND_BREAK, this.getSoundCategory(), 1.0F, 1.0F);
}

@Override
Expand Down Expand Up @@ -319,7 +319,7 @@ public void kill() {

@Override
public boolean handleAttack(Entity entity) {
return entity instanceof PlayerEntity && !this.world.canPlayerModifyAt((PlayerEntity)entity, this.getBlockPos());
return entity instanceof PlayerEntity && !this.getWorld().canPlayerModifyAt((PlayerEntity)entity, this.getBlockPos());
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fonnymunkey/simplehats/common/item/HatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public HatEntry getHatEntry() {

@Override
public void onEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
if(entity.world.isClient()) return;
if(entity.getWorld().isClient()) return;
/*
if(stack.getItem() == ModRegistry.HATSPECIAL && entity instanceof PlayerEntity player) {
NbtCompound tag = stack.getOrCreateNbt();
Expand Down Expand Up @@ -96,8 +96,8 @@ else if(entity instanceof AbstractClientPlayerEntity clientEntity && renderLayer
matrixStack.scale(0.66F, 0.66F, 0.66F);
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180.0F));
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
if(hatModel == null) hatModel = renderer.getModel(stack, entity.world, entity, 0);
if(stack.getNbt() != null && stack.getNbt().getInt("CustomModelData") != 0) renderer.renderItem(stack, ModelTransformationMode.HEAD, false, matrixStack, renderTypeBuffer, light, OverlayTexture.DEFAULT_UV, Objects.requireNonNullElse(hatModel.getOverrides().apply(hatModel, stack, (ClientWorld)entity.world, entity, 0), hatModel));
if(hatModel == null) hatModel = renderer.getModel(stack, entity.getWorld(), entity, 0);
if(stack.getNbt() != null && stack.getNbt().getInt("CustomModelData") != 0) renderer.renderItem(stack, ModelTransformationMode.HEAD, false, matrixStack, renderTypeBuffer, light, OverlayTexture.DEFAULT_UV, Objects.requireNonNullElse(hatModel.getOverrides().apply(hatModel, stack, (ClientWorld)entity.getWorld(), entity, 0), hatModel));
else renderer.renderItem(stack, ModelTransformationMode.HEAD, false, matrixStack, renderTypeBuffer, light, OverlayTexture.DEFAULT_UV, hatModel);
matrixStack.pop();
}
Expand All @@ -112,7 +112,7 @@ else if(entity instanceof AbstractClientPlayerEntity clientEntity && renderLayer
case TRAILING_FEET -> entity.getY()+0.25;
case TRAILING_FULL -> entity.getRandomBodyY();
};
entity.world.addParticle(particleSettings.getParticleType(), entity.getX() + entity.getRandom().nextFloat() - 0.5, y, entity.getZ() + entity.getRandom().nextFloat() - 0.5, d0, d1,d2);
entity.getWorld().addParticle(particleSettings.getParticleType(), entity.getX() + entity.getRandom().nextFloat() - 0.5, y, entity.getZ() + entity.getRandom().nextFloat() - 0.5, d0, d1,d2);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fonnymunkey.simplehats.common.init.ModRegistry;
import fonnymunkey.simplehats.common.item.HatItem;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShearsItem;
import net.minecraft.recipe.RecipeSerializer;
Expand All @@ -25,13 +26,13 @@ public Identifier getId() {
}

@Override
public boolean matches(CraftingInventory craftingInventory, World level) {
public boolean matches(RecipeInputInventory craftingInventory, World level) {
int[] list = processInventory(craftingInventory);
return list[0] != -1 && list[1] != -1;
}

@Override
public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManager reg) {
public ItemStack craft(RecipeInputInventory craftingInventory, DynamicRegistryManager reg) {
int[] list = processInventory(craftingInventory);
if(list[0] != -1 && list[1] != -1) {
return switch(((HatItem)craftingInventory.getStack(list[0]).getItem()).getHatEntry().getHatSeason()) {
Expand All @@ -50,7 +51,7 @@ public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManag
}

@Override
public DefaultedList<ItemStack> getRemainder(CraftingInventory craftingInventory) {
public DefaultedList<ItemStack> getRemainder(RecipeInputInventory craftingInventory) {
DefaultedList<ItemStack> remainList = DefaultedList.ofSize(craftingInventory.size(), ItemStack.EMPTY);

for(int i = 0; i < craftingInventory.size(); ++i) {
Expand All @@ -70,7 +71,7 @@ public DefaultedList<ItemStack> getRemainder(CraftingInventory craftingInventory
return remainList;
}

private static int[] processInventory(CraftingInventory craftingInventory) {
private static int[] processInventory(RecipeInputInventory craftingInventory) {
int totalItems = 0;
int[] list = new int[]{-1, -1};
for(int i =0; i < craftingInventory.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fonnymunkey.simplehats.common.init.ModRegistry;
import fonnymunkey.simplehats.common.item.HatItem;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.RecipeSerializer;
Expand All @@ -24,12 +25,12 @@ public Identifier getId() {
}

@Override
public boolean matches(CraftingInventory craftingInventory, World level) {
public boolean matches(RecipeInputInventory craftingInventory, World level) {
return processInventory(craftingInventory) != null;
}

@Override
public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManager reg) {
public ItemStack craft(RecipeInputInventory craftingInventory, DynamicRegistryManager reg) {
ItemStack hat = processInventory(craftingInventory);
if(hat != null) {
ItemStack hat1 = hat.copy();
Expand All @@ -42,7 +43,7 @@ public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManag
return ItemStack.EMPTY;
}

private static ItemStack processInventory(CraftingInventory craftingInventory) {
private static ItemStack processInventory(RecipeInputInventory craftingInventory) {
int totalItems = 0;
ItemStack hatItem = null;
for(int i =0; i < craftingInventory.size(); i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"mixins": [ "mixins.simplehats.json" ],

"depends": {
"minecraft": ">=1.19.4",
"fabric": ">=0.76.0",
"fabricloader": ">=0.14.17",
"trinkets": ">=3.5.0",
"minecraft": ">=1.20",
"fabric": ">=0.83.0",
"fabricloader": ">=0.14.21",
"trinkets": ">=3.7.0",
"cardinal-components-base": ">=3.0.0",
"cardinal-components-entity": ">=3.0.0",
"cloth-config2": ">=4.9"
Expand Down

0 comments on commit d43108e

Please sign in to comment.