Skip to content

Commit

Permalink
Merge branch '1.19.3' into 1.19.4
Browse files Browse the repository at this point in the history
* 1.19.3:
  Updated changelog
  format
  Better oxidizable mixins
  Supress warnings
  Removed unused mixin
  Format
  Replaced oxidation with separate custom logic to prevent crashes/compat issues
  • Loading branch information
Faboslav committed Oct 2, 2024
2 parents ce6b10b + 640dc68 commit 91332b4
Show file tree
Hide file tree
Showing 23 changed files with 266 additions and 198 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 3.0.4

- Improved internal registries logic (Might fix some crashes)
- Mod should now not crash with mods like Caverns & Chasms and Unvoted & Shelved

## 3.0.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.ButtonBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -35,16 +31,10 @@ public ActionResult onUse(
Hand hand,
BlockHitResult hit
) {
ItemStack itemStack = player.getStackInHand(hand);
Item itemInHand = itemStack.getItem();
var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit);

if (itemInHand instanceof AxeItem) {
ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit);
ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext);

if (itemInHandUsageResult.isAccepted()) {
return itemInHandUsageResult;
}
if (actionResult.isAccepted()) {
return actionResult;
}

return super.onUse(state, world, pos, player, hand, hit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Oxidizable;

import java.util.Optional;
import java.util.function.Supplier;

@SuppressWarnings({"rawtypes", "unchecked"})
public interface Oxidizable extends net.minecraft.block.Oxidizable
public interface FriendsAndFoesOxidizable extends Oxidizable
{
Supplier<BiMap<Block, Block>> OXIDATION_LEVEL_INCREASES = Suppliers.memoize(() -> (BiMap) ImmutableBiMap.builder()
.put(FriendsAndFoesBlocks.COPPER_BUTTON.get(), FriendsAndFoesBlocks.EXPOSED_COPPER_BUTTON.get())
Expand All @@ -38,9 +39,7 @@ static Block getUnaffectedOxidationBlock(Block block) {
}

static Optional<BlockState> getDecreasedOxidationState(BlockState state) {
return getDecreasedOxidationBlock(state.getBlock()).map((block) -> {
return block.getStateWithProperties(state);
});
return getDecreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state));
}

static Optional<Block> getIncreasedOxidationBlock(Block block) {
Expand All @@ -53,13 +52,11 @@ static BlockState getUnaffectedOxidationState(BlockState state) {

@Override
default Optional<BlockState> getDegradationResult(BlockState state) {
return getIncreasedOxidationBlock(state.getBlock()).map((block) -> {
return block.getStateWithProperties(state);
});
return getIncreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state));
}

@Override
default float getDegradationChanceMultiplier() {
return this.getDegradationLevel() == Oxidizable.OxidationLevel.UNAFFECTED ? 0.75F:1.0F;
return this.getDegradationLevel() == OxidationLevel.UNAFFECTED ? 0.75F:1.0F;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.faboslav.friendsandfoes.common.block;

import com.faboslav.friendsandfoes.common.util.WaxableBlocksMap;
import com.google.common.collect.BiMap;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;

import java.util.Optional;

public final class OnUseOxidizable
{
public static ActionResult onOxidizableUse(
BlockState blockState,
World world,
BlockPos blockPos,
PlayerEntity player,
Hand hand,
BlockHitResult hit
) {
ItemStack itemStack = player.getStackInHand(hand);
Item itemInHand = itemStack.getItem();
ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit);

if (itemInHand instanceof HoneycombItem) {
Optional<BlockState> possibleWaxedState = OnUseOxidizable.getWaxedState(blockState);

if (possibleWaxedState.isPresent()) {
if (player instanceof ServerPlayerEntity) {
Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity) player, blockPos, itemStack);
}

if (!player.isCreative()) {
itemStack.decrement(1);
}

world.setBlockState(blockPos, possibleWaxedState.get(), 11);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(player, possibleWaxedState.get()));
world.syncWorldEvent(player, 3003, blockPos, 0);

return ActionResult.success(world.isClient);
}
} else if (itemInHand instanceof AxeItem) {
Optional<BlockState> possibleUnWaxedState = OnUseOxidizable.getUnWaxedState(blockState);
Optional<BlockState> possibleOxidationState = FriendsAndFoesOxidizable.getDecreasedOxidationState(blockState);
Optional<BlockState> possibleState = Optional.empty();

if (possibleUnWaxedState.isPresent()) {
world.playSound(player, blockPos, SoundEvents.ITEM_AXE_WAX_OFF, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.syncWorldEvent(player, 3004, blockPos, 0);
possibleState = possibleUnWaxedState;
} else if (possibleOxidationState.isPresent()) {
world.playSound(player, blockPos, SoundEvents.ITEM_AXE_SCRAPE, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.syncWorldEvent(player, 3005, blockPos, 0);
possibleState = possibleOxidationState;
}

if (possibleState.isPresent()) {
if (player instanceof ServerPlayerEntity) {
Criteria.ITEM_USED_ON_BLOCK.trigger((ServerPlayerEntity) player, blockPos, itemStack);
}

world.setBlockState(blockPos, possibleState.get(), 11);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Emitter.of(player, possibleState.get()));

if (player != null) {
itemStack.damage(1, player, (p) -> {
p.sendToolBreakStatus(hand);
});
}

return ActionResult.success(world.isClient);
} else {
return ActionResult.PASS;
}
}

if (itemInHand instanceof HoneycombItem || itemInHand instanceof AxeItem) {
ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext);

if (itemInHandUsageResult.isAccepted()) {
return itemInHandUsageResult;
}
}

return ActionResult.PASS;
}

private static Optional<BlockState> getWaxedState(BlockState state) {
return Optional.ofNullable((Block) ((BiMap) WaxableBlocksMap.UNWAXED_TO_WAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> {
return block.getStateWithProperties(state);
});
}

private static Optional<BlockState> getUnWaxedState(BlockState state) {
return Optional.ofNullable((Block) ((BiMap) WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get()).get(state.getBlock())).map((block) -> {
return block.getStateWithProperties(state);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.faboslav.friendsandfoes.common.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.Oxidizable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand All @@ -13,7 +11,7 @@
import net.minecraft.world.World;

@SuppressWarnings("deprecation")
public final class OxidizableButtonBlock extends CopperButtonBlock implements Oxidizable
public final class OxidizableButtonBlock extends CopperButtonBlock implements FriendsAndFoesOxidizable
{
private final OxidationLevel oxidationLevel;

Expand All @@ -38,7 +36,7 @@ public void randomTick(

@Override
public boolean hasRandomTicks(BlockState state) {
return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent();
return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent();
}

@Override
Expand All @@ -55,16 +53,10 @@ public ActionResult onUse(
Hand hand,
BlockHitResult hit
) {
ItemStack itemStack = player.getStackInHand(hand);
Item itemInHand = itemStack.getItem();
ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit);
var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit);

if (itemInHand instanceof HoneycombItem || itemInHand instanceof AxeItem) {
ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext);

if (itemInHandUsageResult.isAccepted()) {
return itemInHandUsageResult;
}
if (actionResult.isAccepted()) {
return actionResult;
}

return super.onUse(state, world, pos, player, hand, hit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.LightningRodBlock;
import net.minecraft.block.Oxidizable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public final class OxidizableLightningRodBlock extends LightningRodBlock implements Oxidizable
{
Expand All @@ -31,11 +36,29 @@ public void randomTick(

@Override
public boolean hasRandomTicks(BlockState state) {
return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent();
return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent();
}

@Override
public OxidationLevel getDegradationLevel() {
return this.oxidationLevel;
}

@Override
public ActionResult onUse(
BlockState state,
World world,
BlockPos pos,
PlayerEntity player,
Hand hand,
BlockHitResult hit
) {
var actionResult = OnUseOxidizable.onOxidizableUse(state, world, pos, player, hand, hit);

if (actionResult.isAccepted()) {
return actionResult;
}

return super.onUse(state, world, pos, player, hand, hit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.render.entity.model.CowEntityModel;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

public final class CopperGolemEntity extends GolemEntity implements AnimatedEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faboslav.friendsandfoes.common.init;

import com.faboslav.friendsandfoes.common.FriendsAndFoes;
import com.faboslav.friendsandfoes.common.block.Oxidizable;
import com.faboslav.friendsandfoes.common.block.*;
import com.faboslav.friendsandfoes.common.events.client.RegisterRenderLayersEvent;
import com.faboslav.friendsandfoes.common.events.lifecycle.RegisterFlammabilityEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class FriendsAndFoesVillagerProfessions
public static final RegistryEntry<VillagerProfession> BEEKEEPER = VILLAGER_PROFESSIONS.register("beekeeper", () -> new VillagerProfession("beekeeper", pointOfInterest -> pointOfInterest.isIn(PointOfInterestTypeTags.BEE_HOME), pointOfInterest -> pointOfInterest.isIn(PointOfInterestTypeTags.BEE_HOME), ImmutableSet.of(Items.HONEYCOMB), ImmutableSet.of(), SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM));

public static void registerVillagerTrades(RegisterVillagerTradesEvent event) {
if(event.type() == BEEKEEPER.get()) {
if (event.type() == BEEKEEPER.get()) {
event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(FriendsAndFoesItems.BUTTERCUP.get(), 10, 16, 2));
event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(Items.DANDELION, 10, 16, 2));
event.register(1, new TradeOffersUtil.BuyForOneEmeraldFactory(Items.SUNFLOWER, 10, 16, 2));
Expand Down

This file was deleted.

Loading

0 comments on commit 91332b4

Please sign in to comment.