Skip to content

Commit

Permalink
chore: support MC 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed Jul 18, 2023
1 parent 36a39df commit f0b4dc0
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 62 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ repositories {
}
}

loom {
accessWidenerPath = file("src/main/resources/rug.accesswidener")
}

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}"
modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
modImplementation "carpet:fabric-carpet:${project.carpet_core_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
Expand Down
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ org.gradle.jvmargs = -Xmx4G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version = 1.19.4
minecraft_minimum_version = 1.19.4
yarn_mappings = 1.19.4+build.2
loader_version = 0.14.19
minecraft_version = 1.20.1
minecraft_minimum_version = 1.20.1
yarn_mappings = 1.20.1+build.8
loader_version = 0.14.21
# 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.101+v230319
carpet_core_version = 1.20-1.4.112+v230608

# Mod Properties
mod_version = 1.4.1
mod_version = 1.4.2
maven_group = de.rubixdev.rug
archives_base_name = rug

# Dependencies
fabric_version = 0.77.0+1.19.4
fabric_version = 0.84.0+1.20.1

# Check on https://maven.nucleoid.xyz/eu/pb4/sgui/ or https://github.com/Patbox/sgui/releases
sgui_version = 1.2.1+1.19.3
sgui_version = 1.2.2+1.20

# Release Action properties
release_curse_versions = Minecraft 1.19:1.19.4
release_modrinth_versions = 1.19.4
release_display_version = 1.19.4
release_curse_versions = Minecraft 1.20:1.20.1
release_modrinth_versions = 1.20.1
release_display_version = 1.20+

release_extra_branch = false
release_extra_branch_name = 1.18
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/de/rubixdev/rug/RugServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
import java.util.stream.Stream;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CocoaBlock;
import net.minecraft.block.CropBlock;
import net.minecraft.block.NetherWartBlock;
import net.minecraft.block.*;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.item.BlockItem;
import net.minecraft.item.HoeItem;
Expand Down Expand Up @@ -457,8 +452,13 @@ private static boolean isMature(BlockState state) {
}

private static IntProperty getAgeProperty(Block block) {
if (block instanceof CropBlock) {
return ((CropBlock) block).getAgeProperty();
// UPDATE: check for new classes overriding CropBlock.getAgeProperty()
if (block instanceof BeetrootsBlock) {
return BeetrootsBlock.AGE;
} else if (block instanceof TorchflowerBlock) {
return TorchflowerBlock.AGE;
} else if (block instanceof CropBlock) {
return CropBlock.AGE;
} else if (block instanceof NetherWartBlock) {
return NetherWartBlock.AGE;
} else if (block instanceof CocoaBlock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void register(
}

source.sendFeedback(
Text.translatable(
() -> Text.translatable(
"commands.effect.give.success.single",
effect.getName(),
player.getDisplayName(),
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/rubixdev/rug/commands/ModsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private static int execute(CommandContext<ServerCommandSource> context, boolean
}
chatMessageJson += String.join(",\"\\n \",", modJsons) + "]";

context.getSource().sendFeedback(Text.Serializer.fromJson(chatMessageJson), false);
String finalChatMessageJson = chatMessageJson;
context.getSource().sendFeedback(() -> Text.Serializer.fromJson(finalChatMessageJson), false);
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package de.rubixdev.rug.mixins;

import de.rubixdev.rug.RugSettings;
import net.minecraft.block.PressurePlateBlock;
import net.minecraft.block.AbstractPressurePlateBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(PressurePlateBlock.class)
public class PressurePlateBlockMixin {
@Mixin(AbstractPressurePlateBlock.class)
public class AbstractPressurePlateBlockMixin {
@Redirect(
method = "getRedstoneOutput(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I",
method = "method_52209",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;canAvoidTraps()Z"))
private boolean disableItemFrames(Entity entity) {
private static boolean disableItemFrames(Entity entity) {
if (!RugSettings.itemFramesActivatePressurePlates && entity.getType() == EntityType.ITEM_FRAME) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EnderDragonEntityMixin(EntityType<?> type, World world) {
ordinal = 1))
private void onUpdatePostDeath(CallbackInfo ci) {
String rugSetting = RugSettings.dragonDrops;
if (!rugSetting.equals("none") && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
if (!rugSetting.equals("none") && this.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
boolean dropAll = rugSetting.equals("all");

if (rugSetting.contains("elytra") || dropAll) {
Expand Down
56 changes: 31 additions & 25 deletions src/main/java/de/rubixdev/rug/mixins/FallingBlockEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,62 +40,68 @@ public FallingBlockEntityMixin(EntityType<?> type, World world) {
cancellable = true)
private void onTick(CallbackInfo ci, Block block, BlockPos pos) {
BlockPos posBelow = this.getBlockPos().down();
BlockState blockStateBelow = world.getBlockState(posBelow);
BlockState blockStateBelow = getWorld().getBlockState(posBelow);
Block blockBelow = blockStateBelow.getBlock();

if (this.block.isIn(BlockTags.ANVIL)) {
if (blockBelow == Blocks.FROSTED_ICE && RugSettings.anvilledIce > 0) {
if (++frostedIceCount < RugSettings.anvilledIce) {
world.breakBlock(posBelow, false);
onGround = false;
getWorld().breakBlock(posBelow, false);
setOnGround(false);
ci.cancel();
} else {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.ICE.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.ICE.getDefaultState(), 3);
}
} else if (blockBelow == Blocks.ICE && RugSettings.anvilledPackedIce > 0) {
if (++iceCount < RugSettings.anvilledPackedIce) {
world.breakBlock(posBelow, false);
onGround = false;
getWorld().breakBlock(posBelow, false);
setOnGround(false);
ci.cancel();
} else {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.PACKED_ICE.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.PACKED_ICE.getDefaultState(), 3);
}
} else if (blockBelow == Blocks.PACKED_ICE && RugSettings.anvilledBlueIce > 0) {
if (++packedIceCount < RugSettings.anvilledBlueIce) {
world.breakBlock(posBelow, false);
onGround = false;
getWorld().breakBlock(posBelow, false);
setOnGround(false);
ci.cancel();
} else {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.BLUE_ICE.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.BLUE_ICE.getDefaultState(), 3);
}
} else if (blockBelow == Blocks.COBBLESTONE && RugSettings.cobbleCrushing) {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.GRAVEL.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.GRAVEL.getDefaultState(), 3);
} else if (blockBelow == Blocks.GRAVEL && RugSettings.gravelCrushing) {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.SAND.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.SAND.getDefaultState(), 3);
}
} else if (this.block.isOf(Blocks.DRAGON_EGG)) {
String rugSetting = RugSettings.dragonEggConvertsCobbleToEndstone;
if (blockBelow == Blocks.COBBLESTONE && (rugSetting.equals("both") || rugSetting.equals("on_landing"))) {
world.breakBlock(posBelow, false);
world.setBlockState(posBelow, Blocks.END_STONE.getDefaultState(), 3);
getWorld().breakBlock(posBelow, false);
getWorld().setBlockState(posBelow, Blocks.END_STONE.getDefaultState(), 3);
}
} else if ((this.block.isOf(Blocks.SAND) && blockStateBelow.isOf(Blocks.GRAVEL))
|| (this.block.isOf(Blocks.GRAVEL) && blockStateBelow.isOf(Blocks.SAND))) {
BlockState concreteBlock = world.getBlockState(posBelow.down());
BlockState concreteBlock = getWorld().getBlockState(posBelow.down());
if (isConcrete(concreteBlock) && RugSettings.concreteMixing) {
world.syncWorldEvent(
WorldEvents.BLOCK_BROKEN, posBelow, Block.getRawIdFromState(Blocks.SAND.getDefaultState()));
world.syncWorldEvent(
WorldEvents.BLOCK_BROKEN, posBelow, Block.getRawIdFromState(Blocks.GRAVEL.getDefaultState()));
getWorld()
.syncWorldEvent(
WorldEvents.BLOCK_BROKEN,
posBelow,
Block.getRawIdFromState(Blocks.SAND.getDefaultState()));
getWorld()
.syncWorldEvent(
WorldEvents.BLOCK_BROKEN,
posBelow,
Block.getRawIdFromState(Blocks.GRAVEL.getDefaultState()));

Block powderBlock = getCorrespondingPowder(concreteBlock);
assert powderBlock != null;
world.setBlockState(posBelow, powderBlock.getDefaultState(), 3);
getWorld().setBlockState(posBelow, powderBlock.getDefaultState(), 3);
this.discard();
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void onDrop(DamageSource source, CallbackInfo ci) {

if (dyingEntity.getType().equals(EntityType.SHULKER)
&& RugSettings.strictShulkerShells > 0
&& dyingEntity.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
&& dyingEntity.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
ItemStack stack = new ItemStack(Items.SHULKER_SHELL);
stack.setCount(RugSettings.strictShulkerShells);
dyingEntity.dropStack(stack);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected PotionEntityMixin(EntityType<? extends ThrownEntity> entityType, World
ordinal = 0))
private void ageCopper(BlockHitResult blockHitResult, CallbackInfo ci) {
BlockPos blockPos = blockHitResult.getBlockPos();
BlockState blockState = this.world.getBlockState(blockPos);
BlockState blockState = this.getWorld().getBlockState(blockPos);
Block block = blockState.getBlock();

if (block instanceof Oxidizable && RugSettings.splashOxidize) {
Optional<BlockState> oxidized = ((Oxidizable) block).getDegradationResult(blockState);
oxidized.ifPresent(state -> this.world.setBlockState(blockPos, state));
oxidized.ifPresent(state -> this.getWorld().setBlockState(blockPos, state));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -26,9 +24,6 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile
super(world, pos, yaw, gameProfile);
}

@Shadow
public abstract ServerWorld getWorld();

@Inject(
method = "onDeath",
at =
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"mixins": [
"rug.mixins.json"
],
"accessWidener": "rug.accesswidener",

"depends": {
"fabricloader": ">=0.14.6",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/rug.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v1 named

accessible method net/minecraft/entity/Entity setWorld (Lnet/minecraft/world/World;)V
2 changes: 1 addition & 1 deletion src/main/resources/rug.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"AbstractCauldronBlockMixin",
"AbstractFurnaceBlockEntityMixin",
"AbstractPlantStemBlockMixin",
"AbstractPressurePlateBlockMixin",
"AbstractRedstoneGateBlockMixin",
"BambooBlockMixin",
"BlockItemMixin",
Expand Down Expand Up @@ -46,7 +47,6 @@
"PlayerEntityMixin",
"PointedDripstoneBlockMixin",
"PotionEntityMixin",
"PressurePlateBlockMixin",
"RedstoneLampBlockMixin",
"RepeaterBlockMixin",
"SculkBlockMixin",
Expand Down

0 comments on commit f0b4dc0

Please sign in to comment.