Skip to content

Commit

Permalink
Port to 1.20.6 (#315)
Browse files Browse the repository at this point in the history
* build: java 21, loom 1.6

* build: migrate mappings to 1.20.6, carpet `1.4.141+v240429`

* fix(1.20.6): adjust damage item stack damage method

* fix(1.20.6): `#areItemsAndComponentsEqual()`

* ref: add missing newline at the end

* ref: clear empty lines

* fix(1.20.6): adjust skeleton entity `#initialize()` method

* fix(1.20.6): adjust `#onUse` to `#onUseWithItem()`

* fix(1.20.6): adjust `#damage` method, fix grammar

* fix(1.20.6): adjust `#damage` method

* fix(1.20.6): replace `PLANT_FERTILIZED` with `BONE_MEAL_USED`

* fix(1.20.6): adjust `#damage` method

* fix(1.20.6): adjust `#damage` method, fix grammar

* fix(1.20.6): adjust `#getNbt` with data components

* fix(1.20.6): adjust `#onUse` to `#onUseWithItem`

* fix(1.20.6): adjust stew effects type

* fix(1.20.6): adjust bytecode anonymous class ID for mob heads

* fix(1.20.6): adjust bytecode anonymous class ID for carved pumpkins

* fix(1.20.6): adjust code to use the new data component types system

* fix(1.20.6): update minecraft and java versions

* fix(1.20.6): adjust method parameters

* fix(1.20.6): adjust `BEHAVIOURS` map access level

* fix(1.20.6): fix mixin target, adjust `BEHAVIOURS` map access level

* revert: 092ee7e it seems like Mojang fixed the nullability crash.

* fix(1.20.6): adjust method parameters

* fix(1.20.6): change bytecode class ID for glowstone behavior

* ref: remove unnecessary mixin warning suppression

* fix(1.20.6): adjust injection target

* ref: don't call mooshroom accessor twice

Co-authored-by: MeeniMc <[email protected]>

* revert: a1ce350 carpet & chest dispensers weren't fixed

* fix(1.20.6): adjust carpet, chest & wither skull dispenser targets

* fix(1.20.6): correctly copy chest contents

* 1.20.6: build system and targets

* 1.20.6: fix cauldron water dispenser behavior for banners, shulkers,
dyed armors.

* 1.20.6: fix flowerChunkLoader with hand action

* 1.20.6: fix dispenserToggleThings

* ref: don't use asterisk auto import

* docs: add code comments

useless, unreadable, but that's the code style here

* ref: don't use asterisk auto import

* ref: update compatibility level to Java 17

* ref: use instanceof pattern matching, abandon matti's style

* fix: correct the empty check for shulker boxes

* Reduce import reorder noise in the diff and remove use of `var`

* Further

---------

Co-authored-by: MeeniMc <[email protected]>
  • Loading branch information
voidpointer0x00 and MeeniMc authored Jun 24, 2024
1 parent 1c54c8c commit 5c8f94e
Show file tree
Hide file tree
Showing 34 changed files with 169 additions and 211 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/devbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ steps.getbranchinfo.outputs.branchname }}
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
Expand Down Expand Up @@ -130,11 +130,11 @@ jobs:
uses: actions/checkout@v3
with:
ref: master
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: 'gradle'
- name: Update README page
run: |
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -9,8 +9,8 @@ repositories {
}
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.minecraft_version+'-'+project.mod_version
Expand Down Expand Up @@ -47,7 +47,7 @@ processResources {
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"

it.options.release = 17
it.options.release = 21
}

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

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.2
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.11
# check available versions on maven (https://masa.dy.fi/maven/carpet/fabric-carpet/) for the given minecraft version you are using
carpet_core_version=1.4.128+v231205
carpet_core_version=1.4.141+v240429

# Mod Properties
mod_version = 1.4.128
mod_version = 1.4.141
maven_group = carpet-extra
archives_base_name = carpet-extra

Expand All @@ -21,7 +21,7 @@ org.gradle.jvmargs=-Xmx1G
# The Curseforge versions "names" or ids for the main branch (comma separated: 1.16.4,1.16.5)
# This is needed because CF uses too vague names for prereleases and release candidates
# Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN]
release-curse-versions = Minecraft 1.20:1.20.3,Minecraft 1.20:1.20.4
release-curse-versions = Minecraft 1.20:1.20.5,Minecraft 1.20:1.20.6
# Whether or not to build another branch on release
release-extra-branch = false
# The name of the second branch to release
Expand Down
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-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
// grow netherwart one stage
world.setBlockState(frontBlockPos, frontBlockState.with(NetherWartBlock.AGE, age + 1), Block.NOTIFY_LISTENERS);
// green sparkles
world.syncWorldEvent(WorldEvents.PLANT_FERTILIZED, frontBlockPos, 0);
world.syncWorldEvent(WorldEvents.BONE_MEAL_USED, frontBlockPos, 0);

// decrement item and return
stack.decrement(1);
return stack;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
world.emitGameEvent(null, GameEvent.SHEAR, frontBlockPos);

// damage shears, remove if broken
if(stack.damage(1, world.random, null)) {
stack.setCount(0);
}
stack.damage(1, world.random, null, () -> stack.setCount(0));

return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.LeveledCauldronBlock;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.block.entity.BannerBlockEntity;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.BannerPatternsComponent;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.item.BannerItem;
import net.minecraft.item.DyeableItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
Expand All @@ -34,77 +36,79 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
BlockState frontBlockState = world.getBlockState(frontBlockPos);
Block frontBlock = frontBlockState.getBlock();

if(frontBlock == Blocks.WATER_CAULDRON) {
if(item == Items.POTION && PotionUtil.getPotion(stack) == Potions.WATER) {
// check if cauldron is not full
if(!((AbstractCauldronBlock) frontBlock).isFull(frontBlockState)) {
// increase cauldron level
int level = frontBlockState.get(LeveledCauldronBlock.LEVEL);
BlockState cauldronState = frontBlockState.with(LeveledCauldronBlock.LEVEL, level + 1);
setCauldron(world, frontBlockPos, cauldronState, SoundEvents.ITEM_BOTTLE_EMPTY, GameEvent.FLUID_PLACE);
if (frontBlock == Blocks.WATER_CAULDRON) {
if (item == Items.POTION) {
// check if it's a water bottle (https://minecraft.wiki/w/Potion#Base_potions)
PotionContentsComponent potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
if (potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER)) {
// check if cauldron is not full
if (!((AbstractCauldronBlock) frontBlock).isFull(frontBlockState)) {
// increase cauldron level
int level = frontBlockState.get(LeveledCauldronBlock.LEVEL);
BlockState cauldronState = frontBlockState.with(LeveledCauldronBlock.LEVEL, level + 1);
setCauldron(world, frontBlockPos, cauldronState, SoundEvents.ITEM_BOTTLE_EMPTY, GameEvent.FLUID_PLACE);

// return glass bottle
return this.addOrDispense(pointer, stack, new ItemStack(Items.GLASS_BOTTLE));
// return glass bottle
return this.addOrDispense(pointer, stack, new ItemStack(Items.GLASS_BOTTLE));
}
}
}
else if(item == Items.GLASS_BOTTLE) {
else if (item == Items.GLASS_BOTTLE) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// return water bottle
return this.addOrDispense(pointer, stack, PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER));
return this.addOrDispense(pointer, stack, PotionContentsComponent.createStack(Items.POTION, Potions.WATER));
}
else if(Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
else if (Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
// make sure item isn't plain shulker box
if(item != Items.SHULKER_BOX) {
if (item != Items.SHULKER_BOX) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// turn dyed shulker box into undyed shulker box
ItemStack undyedShulkerBox = new ItemStack(Items.SHULKER_BOX);
if(stack.hasNbt()) {
undyedShulkerBox.setNbt(stack.getNbt().copy());
}
ItemStack undyedShulkerBox = stack.copyComponentsToNewStack(Blocks.SHULKER_BOX, 1);

// return undyed shulker box
return this.addOrDispense(pointer, stack, undyedShulkerBox);
}
}
if(item instanceof DyeableItem) {
DyeableItem dyeableItem = (DyeableItem) item;

if (stack.isIn(ItemTags.DYEABLE)) {
// check if dyeable item has color
if(dyeableItem.hasColor(stack)) {
if (stack.contains(DataComponentTypes.DYED_COLOR)) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// remove color
dyeableItem.removeColor(stack);

stack.remove(DataComponentTypes.DYED_COLOR);
// return undyed item
return stack;
}
}
else if(item instanceof BannerItem) {
// checks if banner has layers
if(BannerBlockEntity.getPatternCount(stack) > 0) {
else if (item instanceof BannerItem) {
// check if banner has layers (https://minecraft.wiki/w/Banner#Patterns)
BannerPatternsComponent bannerPatternsComponent = stack.getOrDefault(DataComponentTypes.BANNER_PATTERNS, BannerPatternsComponent.DEFAULT);
if (!bannerPatternsComponent.layers().isEmpty()) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// copy banner stack, set to one item
ItemStack cleanedBanner = stack.copy();
cleanedBanner.setCount(1);
// removes layer from banner (yarn name is misleading)
BannerBlockEntity.loadFromItemStack(cleanedBanner);

// remove layer from banner
cleanedBanner.set(DataComponentTypes.BANNER_PATTERNS, bannerPatternsComponent.withoutTopLayer());
// return cleaned banner
return this.addOrDispense(pointer, stack, cleanedBanner);
}
}
}
else if(frontBlock == Blocks.CAULDRON && item == Items.POTION && PotionUtil.getPotion(stack) == Potions.WATER) {
// increase cauldron level
BlockState cauldronState = Blocks.WATER_CAULDRON.getDefaultState();
setCauldron(world, frontBlockPos, cauldronState, SoundEvents.ITEM_BOTTLE_EMPTY, GameEvent.FLUID_PLACE);
else if(frontBlock == Blocks.CAULDRON && item == Items.POTION) {
// check if it's a water bottle (https://minecraft.wiki/w/Potion#Base_potions)
PotionContentsComponent potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
if (potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER)) {
// increase cauldron level
BlockState cauldronState = Blocks.WATER_CAULDRON.getDefaultState();
setCauldron(world, frontBlockPos, cauldronState, SoundEvents.ITEM_BOTTLE_EMPTY, GameEvent.FLUID_PLACE);

// return glass bottle
return this.addOrDispense(pointer, stack, new ItemStack(Items.GLASS_BOTTLE));
// return glass bottle
return this.addOrDispense(pointer, stack, new ItemStack(Items.GLASS_BOTTLE));
}
}

// fail to dispense
Expand All @@ -113,22 +117,27 @@ else if(frontBlock == Blocks.CAULDRON && item == Items.POTION && PotionUtil.getP
}

// set cauldron, play sound, emit game event
private static void setCauldron(ServerWorld world, BlockPos pos, BlockState state, SoundEvent soundEvent, GameEvent gameEvent) {
private static void setCauldron(ServerWorld world, BlockPos pos, BlockState state, SoundEvent soundEvent, RegistryEntry.Reference<GameEvent> gameEvent) {
world.setBlockState(pos, state);
world.playSound(null, pos, soundEvent, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.emitGameEvent(null, gameEvent, pos);
}

public static boolean isWaterCauldronItem(ItemStack stack) {
/* accept empty and water bottles, banners and dyeable items */
Item item = stack.getItem();
return item == Items.GLASS_BOTTLE ||
// water bottle
(item == Items.POTION && PotionUtil.getPotion(stack) == Potions.WATER) ||
// shulker boxes
Block.getBlockFromItem(item) instanceof ShulkerBoxBlock ||
// banners
item instanceof BannerItem ||
// dyeable items (leather armor, leather horse armor)
(item instanceof DyeableItem && ((DyeableItem) item).hasColor(stack));
if (item == Items.GLASS_BOTTLE || item instanceof BannerItem)
return true;
if (item == Items.POTION) {
PotionContentsComponent potionContentsComponent = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
return potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER);
}
if (Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
return item != Items.SHULKER_BOX; // dyed Shulkers only
}
if (stack.isIn(ItemTags.DYEABLE)) {
return stack.getComponents().contains(DataComponentTypes.DYED_COLOR);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.SuspiciousStewIngredient.StewEffect;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.component.type.SuspiciousStewEffectsComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.MooshroomEntity;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -43,7 +43,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
// check if mooshroom has no stew effect
if (mooshroomAccessor.getStewEffects() == null) {
// get stew effect and length for flower
Optional<List<StewEffect>> effect = mooshroomAccessor.invokeGetStewEffectFrom(stack);
Optional<SuspiciousStewEffectsComponent> effect = mooshroomAccessor.invokeGetStewEffectFrom(stack);

// check if effect is present
if (effect.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import carpetextra.dispenser.DispenserBehaviorHelper;
import carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.SuspiciousStewIngredient.StewEffect;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.SuspiciousStewEffectsComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.MooshroomEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SuspiciousStewItem;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -57,11 +57,11 @@ private static ItemStack getStewType(List<MooshroomEntity> mooshrooms) {
for (MooshroomEntity mooshroom : mooshrooms) {
// from MooshroomEntity#interact
MooshroomEntity_StatusEffectAccessorMixin mooshroomAccessor = (MooshroomEntity_StatusEffectAccessorMixin) mooshroom;
List<StewEffect> stewEffects = mooshroomAccessor.getStewEffects();
SuspiciousStewEffectsComponent stewEffects = mooshroomAccessor.getStewEffects();
if (stewEffects != null) {
// create suspicious stew and add mooshroom's stew effect to it
ItemStack stewStack = new ItemStack(Items.SUSPICIOUS_STEW);
SuspiciousStewItem.writeEffectsToStew(stewStack, stewEffects);
stewStack.set(DataComponentTypes.SUSPICIOUS_STEW_EFFECTS, stewEffects);

// clear mooshroom's stew effect
mooshroomAccessor.setStewEffects(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
chicken.dropItem(Items.FEATHER);

// damage shears, remove if broken
if(stack.damage(1, world.random, null)) {
stack.setCount(0);
}
stack.damage(1, world.random, null, () -> stack.setCount(0));

// return shears
return stack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
// use on block, test if sucessful
if(stack.getItem().useOnBlock(context).isAccepted()) {
// damage axe, remove if broken
if(stack.damage(1, world.random, null)) {
stack.setCount(0);
}
stack.damage(1, world.random, null, () -> stack.setCount(0));

return stack;
}
Expand All @@ -62,7 +60,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
return stack;
}

// checks if a block is able to be stripped with an axe
// checks if a block can be stripped with an axe
public static boolean canStrip(Block block) {
return STRIPPED_BLOCKS.contains(block) || DEOXIDIZE_BLOCKS.contains(block) || DEWAX_BLOCKS.contains(block);
}
Expand Down
Loading

0 comments on commit 5c8f94e

Please sign in to comment.