Skip to content

Commit

Permalink
Port fabric-item-api-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 9, 2023
1 parent 68a72ab commit 8abdd9d
Show file tree
Hide file tree
Showing 36 changed files with 284 additions and 685 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Missing -> Added -> Tested
| fabric-events-interaction-v0 | ✅ Tested | Stable |
| fabric-game-rule-api-v1 | ✅ Tested | Stable |
| fabric-gametest-api-v1 | ⚠️ Missing | Stable |
| fabric-item-api-v1 | ⚠️ Missing | Stable |
| fabric-item-api-v1 | ✅ Tested | Stable |
| fabric-item-group-api-v1 | ✅ Tested | Stable |
| fabric-key-binding-api-v1 | ✅ Tested | Stable |
| fabric-lifecycle-events-v1 | ✅ Tested | Stable |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;

public class ExampleBlock extends Block {
public ExampleBlock() {
super(Settings.of(Material.METAL));
super(Settings.create());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.fluid.EmptyFluid;
Expand All @@ -29,7 +28,7 @@ public class BlockRenderLayerTest {
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
private static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, MODID);

public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(AbstractBlock.Settings.of(Material.METAL)));
public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(AbstractBlock.Settings.create()));
public static final RegistryObject<Fluid> EXAMPLE_FLUID = FLUIDS.register("example_item", EmptyFluid::new);

public BlockRenderLayerTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"HoneycombItemMixin",
"LandPathNodeMakerMixin",
"FireBlockMixin",
"VibrationListenerMixin",
"ShovelItemAccessor",
"VillagerEntityAccessor"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class EntityEventHooks {
@SubscribeEvent
public static void onLivingAttack(LivingAttackEvent event) {
LivingEntity entity = event.getEntity();
if (!entity.world.isClient && !ServerLivingEntityEvents.ALLOW_DAMAGE.invoker().allowDamage(entity, event.getSource(), event.getAmount())) {
if (!entity.getWorld().isClient && !ServerLivingEntityEvents.ALLOW_DAMAGE.invoker().allowDamage(entity, event.getSource(), event.getAmount())) {
event.setCanceled(true);
}
}
Expand All @@ -34,8 +34,8 @@ public static void onSleepingLocationCheck(SleepingLocationCheckEvent event) {
LivingEntity entity = event.getEntity();
BlockPos sleepingPos = event.getSleepingLocation();

BlockState bedState = entity.world.getBlockState(sleepingPos);
boolean vanillaResult = bedState.getBlock().isBed(bedState, entity.world, sleepingPos, entity);
BlockState bedState = entity.getWorld().getBlockState(sleepingPos);
boolean vanillaResult = bedState.getBlock().isBed(bedState, entity.getWorld(), sleepingPos, entity);
ActionResult result = EntitySleepEvents.ALLOW_BED.invoker().allowBed(entity, sleepingPos, bedState, vanillaResult);

if (result != ActionResult.PASS) {
Expand All @@ -56,7 +56,7 @@ public static void onPlayerSleepInBed(PlayerSleepInBedEvent event) {
public static void onPlayerSleepingTimeCheck(SleepingTimeCheckEvent event) {
event.getSleepingLocation().ifPresent(sleepingPos -> {
PlayerEntity player = event.getEntity();
ActionResult result = EntitySleepEvents.ALLOW_SLEEP_TIME.invoker().allowSleepTime(player, sleepingPos, !player.world.isDay());
ActionResult result = EntitySleepEvents.ALLOW_SLEEP_TIME.invoker().allowSleepTime(player, sleepingPos, !player.getWorld().isDay());
if (result != ActionResult.PASS) {
event.setResult(result.isAccepted() ? Event.Result.ALLOW : Event.Result.DENY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void onGetSleepingDirection(CallbackInfoReturnable<Direction> info, @Nul
@ModifyVariable(method = {"lambda$stopSleeping$11", "method_18404", "sleep"}, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"), require = 2)
private BlockState modifyBedForOccupiedState(BlockState state, BlockPos sleepingPos) {
LivingEntity entity = (LivingEntity) (Object) this;
ActionResult result = EntitySleepEvents.ALLOW_BED.invoker().allowBed((LivingEntity) (Object) this, sleepingPos, state, state.isBed(entity.world, sleepingPos, entity));
ActionResult result = EntitySleepEvents.ALLOW_BED.invoker().allowBed((LivingEntity) (Object) this, sleepingPos, state, state.isBed(entity.getWorld(), sleepingPos, entity));

// If a valid bed, replace with vanilla red bed so that the BlockState#isBed and BlockState#getValue(FACING) check both succeed
if (result.isAccepted()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.fabricmc.fabric.impl.client.item;

import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;

import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;

public final class ItemApiClientEventHooks {

@SubscribeEvent
public static void onItemTooltip(ItemTooltipEvent event) {
ItemTooltipCallback.EVENT.invoker().getTooltip(event.getItemStack(), event.getFlags(), event.getToolTip());
}

public static PlayerEntity getClientPlayerSafely() {
return MinecraftClient.getInstance().player;
}

private ItemApiClientEventHooks() {}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8abdd9d

Please sign in to comment.