Skip to content

Commit d2480d7

Browse files
committed
Updated the code to 1.20.6
1 parent 8452ada commit d2480d7

13 files changed

Lines changed: 87 additions & 80 deletions

File tree

src/main/java/io/github/mikip98/humilityafm/content/blocks/cabinet/CabinetBlock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
5353
builder.add(WATERLOGGED);
5454
}
5555

56-
protected static final AbstractBlock.Settings defaultSettings = getDefaultSettings();
57-
public static AbstractBlock.Settings getDefaultSettings() {
58-
return AbstractBlock.Settings.create()
56+
protected static final Settings defaultSettings = getDefaultSettings();
57+
public static Settings getDefaultSettings() {
58+
return Settings.create()
5959
.strength(2.0f)
6060
.requiresTool()
6161
.nonOpaque()

src/main/java/io/github/mikip98/humilityafm/content/blocks/cabinet/IlluminatedCabinetBlock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.github.mikip98.humilityafm.content.blocks.cabinet;
22

3-
import net.minecraft.block.AbstractBlock;
43
import net.minecraft.block.BlockState;
54
import net.minecraft.block.entity.BlockEntity;
65
import net.minecraft.util.math.BlockPos;
76
import io.github.mikip98.humilityafm.content.blockentities.cabinetBlock.IlluminatedCabinetBlockEntity;
87

98
public class IlluminatedCabinetBlock extends CabinetBlock {
10-
public static final AbstractBlock.Settings defaultSettings = getDefaultSettings().luminance((ignored) -> 2);
9+
protected static final Settings defaultSettings = getDefaultSettings();
10+
public static Settings getDefaultSettings() {
11+
return CabinetBlock.getDefaultSettings().luminance((ignored) -> 2);
12+
}
1113

1214
public IlluminatedCabinetBlock() { this(defaultSettings); }
1315
public IlluminatedCabinetBlock(Settings settings) { super(settings); }

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/Candlestick.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
import io.github.mikip98.humilityafm.content.properties.ModProperties;
55
import io.github.mikip98.humilityafm.content.blocks.candlestick.logic.SimpleCandlestickLogic;
66
import io.github.mikip98.humilityafm.content.properties.enums.CandleColor;
7-
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
87
import net.minecraft.block.*;
9-
import net.minecraft.entity.LivingEntity;
108
import net.minecraft.entity.player.PlayerEntity;
119
import net.minecraft.fluid.FluidState;
1210
import net.minecraft.fluid.Fluids;
1311
import net.minecraft.item.*;
1412
import net.minecraft.registry.tag.FluidTags;
15-
import net.minecraft.server.network.ServerPlayerEntity;
1613
import net.minecraft.sound.BlockSoundGroup;
1714
import net.minecraft.state.StateManager;
1815
import net.minecraft.state.property.EnumProperty;
1916
import net.minecraft.state.property.Properties;
2017
import net.minecraft.util.ActionResult;
21-
import net.minecraft.util.Hand;
2218
import net.minecraft.util.hit.BlockHitResult;
2319
import net.minecraft.util.math.BlockPos;
2420
import net.minecraft.util.math.Direction;
@@ -29,12 +25,15 @@
2925
import net.minecraft.world.World;
3026

3127
public class Candlestick extends HorizontalFacingBlock implements SimpleCandlestickLogic, Waterloggable {
32-
public static final Settings defaultSettings = Settings.create()
33-
.strength(0.5f)
34-
.requiresTool()
35-
.nonOpaque()
36-
.sounds(BlockSoundGroup.METAL)
37-
.luminance(state -> state.get(Properties.LIT) ? 4 : 0);
28+
protected static final Settings defaultSettings = getDefaultSettings();
29+
public static Settings getDefaultSettings() {
30+
return Settings.create()
31+
.strength(0.5f)
32+
.requiresTool()
33+
.nonOpaque()
34+
.sounds(BlockSoundGroup.METAL)
35+
.luminance(state -> state.get(Properties.LIT) ? 4 : 0);
36+
}
3837

3938
// The below commented-out shapes are a simplified variants of the voxel shapes
4039
// They look more vanilla-like, but are in my opinion more ugly
@@ -153,11 +152,10 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
153152
.with(Properties.WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).isIn(FluidTags.WATER));
154153
}
155154

156-
@SuppressWarnings("deprecation")
157155
@Override
158-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
159-
if (onUseLogic(state, world, pos, player, hand, hit)) return ActionResult.SUCCESS;
160-
return super.onUse(state, world, pos, player, hand, hit);
156+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
157+
if (onUseLogic(state, world, pos, player)) return ActionResult.SUCCESS;
158+
return super.onUse(state, world, pos, player, hit);
161159
}
162160

163161
@Override

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/FloorCandlestick.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.state.property.EnumProperty;
1717
import net.minecraft.state.property.Properties;
1818
import net.minecraft.util.ActionResult;
19-
import net.minecraft.util.Hand;
2019
import net.minecraft.util.hit.BlockHitResult;
2120
import net.minecraft.util.math.BlockPos;
2221
import net.minecraft.util.math.random.Random;
@@ -55,11 +54,10 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
5554
.with(Properties.WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).isIn(FluidTags.WATER));
5655
}
5756

58-
@SuppressWarnings("deprecation")
5957
@Override
60-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
61-
if (onUseLogic(state, world, pos, player, hand, hit)) return ActionResult.SUCCESS;
62-
return super.onUse(state, world, pos, player, hand, hit);
58+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
59+
if (onUseLogic(state, world, pos, player)) return ActionResult.SUCCESS;
60+
return super.onUse(state, world, pos, player, hit);
6361
}
6462

6563
@Override
@@ -74,20 +72,17 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
7472
super.randomDisplayTick(state, world, pos, random);
7573
}
7674

77-
@SuppressWarnings("deprecation")
7875
@Override
7976
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
8077
return (state.get(CANDLE_COLOR) != CandleColor.NONE) ? voxelShapeCandle : voxelShape;
8178
}
8279

83-
@SuppressWarnings("deprecation")
8480
@Override
8581
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
8682
onStateReplacedLogic(state, world, pos, newState);
8783
super.onStateReplaced(state, world, pos, newState, moved);
8884
}
8985

90-
@SuppressWarnings("deprecation")
9186
@Override
9287
public FluidState getFluidState(BlockState state) {
9388
return state.get(Properties.WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.getDefaultState();

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/FloorRustableCandlestick.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import net.minecraft.server.world.ServerWorld;
1212
import net.minecraft.state.StateManager;
1313
import net.minecraft.util.ActionResult;
14-
import net.minecraft.util.Hand;
1514
import net.minecraft.util.hit.BlockHitResult;
1615
import net.minecraft.util.math.BlockPos;
1716
import net.minecraft.util.math.random.Random;
@@ -45,7 +44,6 @@ public FloorRustableCandlestick(Settings settings, @Nullable BlockState rustPrev
4544
);
4645
}
4746

48-
@SuppressWarnings("deprecation")
4947
@Override
5048
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
5149
if (random.nextDouble() >= 0.96) this.rust(state, world, pos);
@@ -57,13 +55,13 @@ public boolean hasRandomTicks(BlockState state) {
5755
}
5856

5957
@Override
60-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
58+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
6159
final double x = pos.getX() + 0.5;
6260
final double y = pos.getY() + 0.35;
6361
final double z = pos.getZ() + 0.5;
6462
final double randomSpread = 0.625;
65-
if (onUseRustableLogic(state, world, pos, player, hand, x, y, z, randomSpread)) return ActionResult.SUCCESS;
66-
return super.onUse(state, world, pos, player, hand, hit);
63+
if (onUseRustableLogic(state, world, pos, player, x, y, z, randomSpread)) return ActionResult.SUCCESS;
64+
return super.onUse(state, world, pos, player, hit);
6765
}
6866

6967
@Override

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/RustableCandlestick.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import net.minecraft.sound.BlockSoundGroup;
1111
import net.minecraft.state.StateManager;
1212
import net.minecraft.util.ActionResult;
13-
import net.minecraft.util.Hand;
1413
import net.minecraft.util.hit.BlockHitResult;
1514
import net.minecraft.util.math.BlockPos;
1615
import net.minecraft.util.math.random.Random;
@@ -20,8 +19,7 @@
2019
@Getter
2120
@Setter
2221
public class RustableCandlestick extends Candlestick implements RustableCandlestickLogic {
23-
// TODO: Mixin that adds copy(Settings settings)
24-
public static final Settings defaultSettings = (Settings) Settings.copy(Candlestick.defaultSettings)
22+
public static final Settings defaultSettings = Candlestick.getDefaultSettings()
2523
.sounds(BlockSoundGroup.COPPER)
2624
.ticksRandomly();
2725

@@ -60,7 +58,7 @@ public boolean hasRandomTicks(BlockState state) {
6058
}
6159

6260
@Override
63-
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
61+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
6462
double x = pos.getX() + 0.5;
6563
final double y = pos.getY() + 0.5;
6664
double z = pos.getZ() + 0.5;
@@ -75,8 +73,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
7573

7674
final double randomSpread = 2.0 / 3.0;
7775

78-
if (onUseRustableLogic(state, world, pos, player, hand, x, y, z, randomSpread)) return ActionResult.SUCCESS;
79-
return super.onUse(state, world, pos, player, hand, hit);
76+
if (onUseRustableLogic(state, world, pos, player, x, y, z, randomSpread)) return ActionResult.SUCCESS;
77+
return super.onUse(state, world, pos, player, hit);
8078
}
8179

8280
@Override

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/logic/BaseCandlestickLogic.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import net.minecraft.block.Block;
66
import net.minecraft.block.BlockState;
77
import net.minecraft.block.CandleBlock;
8+
import net.minecraft.entity.LivingEntity;
89
import net.minecraft.entity.player.PlayerEntity;
910
import net.minecraft.item.BlockItem;
1011
import net.minecraft.item.FlintAndSteelItem;
1112
import net.minecraft.item.Item;
1213
import net.minecraft.item.ItemStack;
1314
import net.minecraft.particle.ParticleTypes;
15+
import net.minecraft.server.network.ServerPlayerEntity;
1416
import net.minecraft.sound.SoundCategory;
1517
import net.minecraft.sound.SoundEvents;
1618
import net.minecraft.state.property.Properties;
@@ -64,7 +66,7 @@ default boolean tryToLightTheCandle(BlockState state, World world, BlockPos pos,
6466
&& !state.get(Properties.WATERLOGGED)
6567
) {
6668
world.setBlockState(pos, state.with(Properties.LIT, true), Block.NOTIFY_ALL);
67-
if (!player.isCreative()) heldItemStack.damage(1, player, (p) -> p.sendToolBreakStatus(hand));
69+
damageItem(heldItemStack, player, world, hand);
6870
world.playSoundAtBlockCenter(pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0f, 1.0f, true);
6971
return true;
7072
}
@@ -106,4 +108,14 @@ default Velocity getRandomVelocity(Random random, float velocityMultiplayer) {
106108
return new Velocity(velocityX, velocityY, velocityZ);
107109
}
108110
record Velocity(double x, double y, double z) {}
111+
112+
default void damageItem(ItemStack heldItemStack, PlayerEntity player, World world, Hand hand) {
113+
if (!player.isCreative() && !world.isClient)
114+
heldItemStack.damage(
115+
1,
116+
world.getRandom(),
117+
(ServerPlayerEntity) player,
118+
() -> player.sendEquipmentBreakStatus(LivingEntity.getSlotForHand(hand))
119+
);
120+
}
109121
}

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/logic/RustableCandlestickLogic.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import net.minecraft.item.HoneycombItem;
99
import net.minecraft.item.Item;
1010
import net.minecraft.item.ItemStack;
11-
import net.minecraft.particle.DefaultParticleType;
11+
import net.minecraft.particle.ParticleEffect;
1212
import net.minecraft.particle.ParticleTypes;
1313
import net.minecraft.sound.SoundCategory;
1414
import net.minecraft.sound.SoundEvents;
@@ -25,9 +25,10 @@ public non-sealed interface RustableCandlestickLogic extends BaseCandlestickLogi
2525
void setRustNextLevel(BlockState rustNextLevel);
2626

2727
default boolean onUseRustableLogic(
28-
BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
28+
BlockState state, World world, BlockPos pos, PlayerEntity player,
2929
double offsetX, double offsetY, double offsetZ, double randomSpread
3030
) {
31+
Hand hand = player.getActiveHand();
3132
ItemStack heldItemStack = player.getStackInHand(hand);
3233
Item heldItem = heldItemStack.getItem();
3334
if (tryToWax(state, world, pos, player, heldItemStack, heldItem, offsetX, offsetY, offsetZ, randomSpread)) return true;
@@ -55,14 +56,14 @@ default boolean tryToDeWaxOrDeRust(
5556
// De-wax
5657
if (state.get(ModProperties.WAXED)) {
5758
world.setBlockState(pos, state.with(ModProperties.WAXED, false), Block.NOTIFY_ALL);
58-
if (!player.isCreative()) heldItemStack.damage(1, player, (p) -> p.sendToolBreakStatus(hand));
59+
damageItem(heldItemStack, player, world, hand);
5960
emmitWaxOffParticles(world, offsetX, offsetY, offsetZ, randomSpread);
6061
world.playSound(offsetX, offsetY, offsetZ, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0f, 1.0f, true);
6162
return true;
6263
}
6364
// De-rust
6465
else if (getRustPreviousLevel() != null) {
65-
if (!player.isCreative()) heldItemStack.damage(1, player, (p) -> p.sendToolBreakStatus(hand));
66+
damageItem(heldItemStack, player, world, hand);
6667
// ServerWorld check is required to be spam proof
6768
if (!world.isClient) derust(state, world, pos);
6869
return true;
@@ -87,7 +88,7 @@ default void derust(BlockState state, World world, BlockPos pos) {
8788
}
8889

8990
default void emmitWaxingParticles(
90-
World world, DefaultParticleType particleType,
91+
World world, ParticleEffect particleEffect,
9192
double offsetX, double offsetY, double offsetZ,
9293
double randomSpread
9394
) {
@@ -97,7 +98,7 @@ default void emmitWaxingParticles(
9798
double randomX = offsetX + ((random.nextDouble() - 0.5) * randomSpread);
9899
double randomY = offsetY + ((random.nextDouble() - 0.5) * randomSpread);
99100
double randomZ = offsetZ + ((random.nextDouble() - 0.5) * randomSpread);
100-
world.addParticle(particleType, randomX, randomY, randomZ, 0, 0, 0);
101+
world.addParticle(particleEffect, randomX, randomY, randomZ, 0, 0, 0);
101102
}
102103
}
103104

src/main/java/io/github/mikip98/humilityafm/content/blocks/candlestick/logic/SimpleCandlestickLogic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import net.minecraft.item.Item;
99
import net.minecraft.item.ItemStack;
1010
import net.minecraft.util.Hand;
11-
import net.minecraft.util.hit.BlockHitResult;
1211
import net.minecraft.util.math.BlockPos;
1312
import net.minecraft.world.World;
1413

1514
public non-sealed interface SimpleCandlestickLogic extends BaseCandlestickLogic {
16-
default boolean onUseLogic(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
15+
default boolean onUseLogic(BlockState state, World world, BlockPos pos, PlayerEntity player) {
16+
Hand hand = player.getActiveHand();
1717
ItemStack heldItemStack = player.getStackInHand(hand);
1818
Item heldItem = heldItemStack.getItem();
1919
if (tryToInsertCandle(state, world, pos, player, heldItemStack, heldItem)) return true;

0 commit comments

Comments
 (0)