Skip to content

Commit

Permalink
More 1.21 port fixes
Browse files Browse the repository at this point in the history
78 -> 38 compile errors
  • Loading branch information
BrokenK3yboard committed Oct 1, 2024
1 parent 018f3cd commit 0134975
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ public Set<ResourceLocation> getTargets() {

@Override
public boolean apply(ResourceLocation res, IMutableAdvancement adv) {

ItemLike[] array = fishes.toArray(ItemLike[]::new);
Criterion criterion = FishingRodHookedTrigger.
TriggerInstance.fishedItem(
Optional.empty(), Optional.empty(), Optional.of(ItemPredicate.Builder.item().of(array).build()));

Criterion<FishingRodHookedTrigger.TriggerInstance> criterion = FishingRodHookedTrigger.TriggerInstance.fishedItem(
Optional.empty(), Optional.empty(), Optional.of(ItemPredicate.Builder.item().of(array).build()));
String name = BuiltInRegistries.ITEM.getKey(array[0].asItem()).toString();
adv.addOrCriterion(name, criterion);

return true;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.neoforged.neoforge.common.ItemAbility;
import net.neoforged.neoforge.common.util.TriState;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
Expand All @@ -38,8 +39,8 @@ default boolean makesOpenTrapdoorAboveClimbableZeta(BlockState state, LevelReade
return state.getBlock() instanceof LadderBlock && state.getValue(LadderBlock.FACING) == trapdoorState.getValue(TrapDoorBlock.FACING);
}

default boolean canSustainPlantZeta(BlockState state, BlockGetter level, BlockPos pos, Direction facing, String plantabletype) {
return false;
default TriState canSustainPlantZeta(BlockState state, BlockGetter level, BlockPos soilPosition, Direction facing, BlockState plant) {
return TriState.DEFAULT;
}

default boolean isConduitFrameZeta(BlockState state, LevelReader level, BlockPos pos, BlockPos conduit) {
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/violetmoon/zeta/event/play/ZBonemeal.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package org.violetmoon.zeta.event.play;

import org.violetmoon.zeta.event.bus.IZetaPlayEvent;
import org.violetmoon.zeta.event.bus.Resultable;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.violetmoon.zeta.event.bus.Cancellable;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

import javax.annotation.Nullable;

public interface ZBonemeal extends IZetaPlayEvent, Cancellable {

public interface ZBonemeal extends IZetaPlayEvent, Resultable {
@Nullable Player getPlayer();
Level getLevel();
BlockPos getPos();
BlockState getBlock();
ItemStack getStack();
boolean isValidBonemealTarget();
void setSuccessful(boolean success);
boolean isSuccessful();
void setCanceled(boolean canceled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;

public interface ZRightClickBlock extends IZetaPlayEvent, Cancellable, Resultable, PlayerGetter {
public interface ZRightClickBlock extends IZetaPlayEvent, Cancellable, PlayerGetter {
Level getLevel();
BlockPos getPos();
InteractionHand getHand();
ItemStack getItemStack();
BlockHitResult getHitVec();
Direction getFace();

TriState getUseBlock();

InteractionResult getCancellationResult();
void setCancellationResult(InteractionResult result);

interface Low extends IZetaPlayEvent, ZRightClickBlock { }
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/org/violetmoon/zeta/item/ext/IZetaItemExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,55 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.LevelReader;
import org.jetbrains.annotations.NotNull;
import net.neoforged.neoforge.registries.datamaps.builtin.FurnaceFuel;
import net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

public interface IZetaItemExtensions {

default InteractionResult onItemUseFirstZeta(UseOnContext context) {
private Item self() {
return (Item)this;
}

default InteractionResult onItemUseFirstZeta(ItemStack stack, UseOnContext context) {
return InteractionResult.PASS;
}

default boolean isRepairableZeta() {
default boolean isRepairableZeta(ItemStack stack) {
return false;
}

default boolean onEntityItemUpdateZeta(ItemEntity entity) {
default boolean onEntityItemUpdateZeta(ItemStack stack, ItemEntity entity) {
return false;
}

default boolean doesSneakBypassUseZeta(LevelReader level, BlockPos pos, Player player) {
default boolean doesSneakBypassUseZeta(ItemStack stack, LevelReader level, BlockPos pos, Player player) {
return false;
}

default boolean canEquipZeta(EquipmentSlot armorType, LivingEntity entity) {
default boolean canEquipZeta(ItemStack stack, EquipmentSlot armorType, LivingEntity entity) {
return false;
}

default boolean isBookEnchantableZeta(ItemStack book) {
default boolean isBookEnchantableZeta(ItemStack stack, ItemStack book) {
return true;
}

default int getEnchantmentValueZeta() {
return stack.getEnchantmentValue();
default int getEnchantmentValueZeta(ItemStack stack) {
return this.self().getEnchantmentValue();
}

default boolean canShearZeta(ItemStack stack) { //canPerformAction
return stack.getItem() instanceof ShearsItem;
}

default int getEnchantmentLevelZeta(Holder<Enchantment> enchantment) {
return EnchantmentHelper.getTagEnchantmentLevel(enchantment, stack);
default int getEnchantmentLevelZeta(ItemStack stack, Holder<Enchantment> enchantment) {
ItemEnchantments itemenchantments = stack.getTagEnchantments();
return itemenchantments.getLevel(enchantment);
}

default ItemEnchantments getAllEnchantmentsZeta(ItemStack stack, HolderLookup.RegistryLookup<Enchantment> lookup) {
Expand All @@ -67,10 +72,10 @@ default boolean shouldCauseReequipAnimationZeta(ItemStack oldStack, ItemStack ne
return !oldStack.equals(newStack);
}

//TODO: initCapabilities

// IItemExtension#getBurnTime is annotated as OverrideOnly for some reason, hardcode to be safe for now
default int getBurnTimeZeta(ItemStack stack, @Nullable RecipeType<?> recipeType) {
return 0;
FurnaceFuel furnaceFuel = this.self().builtInRegistryHolder().getData(NeoForgeDataMaps.FURNACE_FUELS);
return furnaceFuel == null ? 0 : furnaceFuel.burnTime();
}

default <T extends LivingEntity> int damageItemZeta(ItemStack stack, int amount, T entity, Consumer<Item> onBroken) {
Expand All @@ -82,11 +87,6 @@ default boolean isEnderMaskZeta(ItemStack stack, Player player, EnderMan enderbo
}

default boolean canElytraFlyZeta(ItemStack stack, LivingEntity entity) {
//forge has a funky little extension for this
return stack.getItem() instanceof ElytraItem && ElytraItem.isFlyEnabled(stack);
}

default int getDefaultTooltipHideFlagsZeta(@NotNull ItemStack stack) {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ public interface ItemExtensionFactory {
IZetaItemExtensions getInternal(ItemStack stack);

default IZetaItemExtensions get(ItemStack stack) {
if(stack.getItem() instanceof IZetaItemExtensions ext)
return ext;
else
return getInternal(stack);
return stack.getItem() instanceof IZetaItemExtensions ext ? ext : getInternal(stack);
}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.neoforged.neoforge.common.ItemAbility;
import net.neoforged.neoforge.common.util.TriState;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.block.ext.IZetaBlockExtensions;

Expand All @@ -37,8 +38,8 @@ public boolean makesOpenTrapdoorAboveClimbableZeta(BlockState state, LevelReader
}

@Override
public boolean canSustainPlantZeta(BlockState state, BlockGetter level, BlockPos pos, Direction facing, String plantabletype) {
return false; //TODO thread the IPlantable through
public TriState canSustainPlantZeta(BlockState state, BlockGetter level, BlockPos soilPosition, Direction facing, BlockState plant) {
return TriState.DEFAULT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.violetmoon.zetaimplforge.event.play;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.event.entity.player.BonemealEvent;
import org.violetmoon.zeta.event.bus.ZResult;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.event.play.ZBonemeal;
import org.violetmoon.zetaimplforge.ForgeZeta;

public class ForgeZBonemeal implements ZBonemeal {

private final BonemealEvent e;

public ForgeZBonemeal(BonemealEvent e) {
this.e = e;
}

@Nullable
@Override
public Player getPlayer() {
return e.getPlayer();
}

@Override
public Level getLevel() {
return e.getLevel();
Expand All @@ -37,12 +44,27 @@ public ItemStack getStack() {
}

@Override
public boolean getResult() {
public boolean isValidBonemealTarget() {
return e.isValidBonemealTarget();
}

@Override
public void setSuccessful(boolean success) {
e.setSuccessful(success);
}

@Override
public boolean isSuccessful() {
return e.isSuccessful();
}

@Override
public void setResult(ZResult value) {
e.setResult(ForgeZeta.to(value));
public boolean isCanceled() {
return e.isCanceled();
}

@Override
public void setCanceled(boolean cancel) {
e.setCanceled(cancel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.violetmoon.zetaimplforge.ForgeZeta;

public class ForgeZRightClickBlock implements ZRightClickBlock {

private final PlayerInteractEvent.RightClickBlock e;

public ForgeZRightClickBlock(PlayerInteractEvent.RightClickBlock e) {
Expand Down Expand Up @@ -61,29 +62,28 @@ public TriState getUseBlock() {
return e.getUseBlock();
}

@Override
public void setCancellationResult(InteractionResult result) {
e.setCancellationResult(result);
}

@Override
public boolean isCanceled() {
return e.isCanceled();
}

@Override
public void setCanceled(boolean cancel) {
e.setCanceled(cancel);
public void setCanceled(boolean canceled) {
e.setCanceled(canceled);
if (canceled) {
e.setUseBlock(TriState.FALSE);
e.setUseItem(TriState.FALSE);
}
}

@Override
public InteractionResult getResult() {
public InteractionResult getCancellationResult() {
return e.getCancellationResult();
}

@Override
public void setResult(ZResult value) {
e.setResult(ForgeZeta.to(value));
public void setCancellationResult(InteractionResult result) {
e.setCancellationResult(result);
}

public static class Low extends ForgeZRightClickBlock implements ZRightClickBlock.Low {
Expand Down
Loading

0 comments on commit 0134975

Please sign in to comment.