mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-11 22:45:38 -04:00
final name changes, compilation fix
This commit is contained in:
parent
b5b9f82997
commit
33c36f8f29
12 changed files with 38 additions and 37 deletions
build.gradle
src/main
java/net/fabricmc/fabric
api
impl
mixin
block/entity
events/playerinteraction
resources
|
@ -26,7 +26,7 @@ targetCompatibility = 1.8
|
|||
|
||||
archivesBaseName = "fabric"
|
||||
|
||||
def baseVersion = "0.1.5"
|
||||
def baseVersion = "0.2.0"
|
||||
def mcVersion = "19w06a"
|
||||
|
||||
def ENV = System.getenv()
|
||||
|
|
|
@ -26,9 +26,9 @@ import net.minecraft.world.World;
|
|||
/**
|
||||
* Convienence interface for blocks which listen to "break interactions" (left-click).
|
||||
*/
|
||||
public interface AttackInteractable {
|
||||
public interface BlockAttackInteractionAware {
|
||||
/**
|
||||
* @return True if the block accepted the player and it should no longer be processed.
|
||||
*/
|
||||
boolean onBreakInteract(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction direction);
|
||||
boolean onAttackInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction direction);
|
||||
}
|
|
@ -23,6 +23,6 @@ import net.minecraft.util.hit.HitResult;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
public interface ContextSensitivePickable {
|
||||
ItemStack getPickStack(BlockState state, BlockView view, BlockPos pos, /* nullable */ PlayerEntity player, /* nullable */ HitResult result);
|
||||
public interface BlockPickInteractionAware {
|
||||
ItemStack getPickedStack(BlockState state, BlockView view, BlockPos pos, /* nullable */ PlayerEntity player, /* nullable */ HitResult result);
|
||||
}
|
|
@ -22,7 +22,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
* Implement this interace on a BlockEntity which you would like to be
|
||||
* synchronized with the client side using the built-in engine methods.
|
||||
*/
|
||||
public interface ClientSerializable {
|
||||
public interface BlockEntityClientSerializable {
|
||||
void fromClientTag(CompoundTag tag);
|
||||
CompoundTag toClientTag(CompoundTag tag);
|
||||
}
|
|
@ -20,6 +20,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
|
||||
public interface ContextSensitivePickable {
|
||||
ItemStack getPickStack(/* nullable */ PlayerEntity player, /* nullable */ HitResult result);
|
||||
public interface EntityPickInteractionAware {
|
||||
ItemStack getPickedStack(/* nullable */ PlayerEntity player, /* nullable */ HitResult result);
|
||||
}
|
|
@ -30,7 +30,7 @@ import net.minecraft.util.hit.HitResult;
|
|||
* wish for execution to continue, return false to cancel the item picking
|
||||
* operation (for example, if you want to route to the server side, etc.)
|
||||
*/
|
||||
public interface ClientPickItemCallback {
|
||||
public interface ClientPickBlockCallback {
|
||||
public static final class Container {
|
||||
private ItemStack stack;
|
||||
|
||||
|
@ -47,9 +47,9 @@ public interface ClientPickItemCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public static final Event<ClientPickItemCallback> EVENT = EventFactory.arrayBacked(ClientPickItemCallback.class,
|
||||
public static final Event<ClientPickBlockCallback> EVENT = EventFactory.createArrayBacked(ClientPickBlockCallback.class,
|
||||
(listeners) -> (player, result, container) -> {
|
||||
for (ClientPickItemCallback event : listeners) {
|
||||
for (ClientPickBlockCallback event : listeners) {
|
||||
if (!event.pick(player, result, container)) {
|
||||
return false;
|
||||
}
|
|
@ -17,8 +17,9 @@
|
|||
package net.fabricmc.fabric.impl;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.block.ContextSensitivePickable;
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickItemCallback;
|
||||
import net.fabricmc.fabric.api.block.BlockPickInteractionAware;
|
||||
import net.fabricmc.fabric.api.entity.EntityPickInteractionAware;
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockCallback;
|
||||
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
||||
import net.fabricmc.fabric.impl.client.gui.ScreenProviderRegistryImpl;
|
||||
import net.fabricmc.fabric.impl.registry.RegistrySyncManager;
|
||||
|
@ -38,20 +39,20 @@ public class FabricAPIClientInitializer implements ClientModInitializer {
|
|||
RegistrySyncManager.receivePacket(ctx, buf, !MinecraftClient.getInstance().isInSingleplayer());
|
||||
});
|
||||
|
||||
ClientPickItemCallback.EVENT.register(((player, result, container) -> {
|
||||
ClientPickBlockCallback.EVENT.register(((player, result, container) -> {
|
||||
if (result instanceof BlockHitResult) {
|
||||
BlockView view = player.getEntityWorld();
|
||||
BlockPos pos = ((BlockHitResult) result).getBlockPos();
|
||||
BlockState state = view.getBlockState(pos);
|
||||
|
||||
if (state.getBlock() instanceof ContextSensitivePickable) {
|
||||
container.setStack(((ContextSensitivePickable) state.getBlock()).getPickStack(state, view, pos, player, result));
|
||||
if (state.getBlock() instanceof BlockPickInteractionAware) {
|
||||
container.setStack(((BlockPickInteractionAware) state.getBlock()).getPickedStack(state, view, pos, player, result));
|
||||
}
|
||||
} else if (result instanceof EntityHitResult) {
|
||||
Entity entity = ((EntityHitResult) result).getEntity();
|
||||
|
||||
if (entity instanceof net.fabricmc.fabric.api.entity.ContextSensitivePickable) {
|
||||
container.setStack(((net.fabricmc.fabric.api.entity.ContextSensitivePickable) entity).getPickStack(player, result));
|
||||
if (entity instanceof EntityPickInteractionAware) {
|
||||
container.setStack(((EntityPickInteractionAware) entity).getPickedStack(player, result));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package net.fabricmc.fabric.impl;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.block.AttackInteractable;
|
||||
import net.fabricmc.fabric.api.block.BlockAttackInteractionAware;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
@ -27,12 +27,12 @@ public class FabricAPIInitializer implements ModInitializer {
|
|||
public void onInitialize() {
|
||||
AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (state instanceof AttackInteractable) {
|
||||
if (((AttackInteractable) state).onBreakInteract(state, world, pos, player, hand, direction)) {
|
||||
if (state instanceof BlockAttackInteractionAware) {
|
||||
if (((BlockAttackInteractionAware) state).onAttackInteraction(state, world, pos, player, hand, direction)) {
|
||||
return ActionResult.FAILURE;
|
||||
}
|
||||
} else if (state.getBlock() instanceof AttackInteractable) {
|
||||
if (((AttackInteractable) state.getBlock()).onBreakInteract(state, world, pos, player, hand, direction)) {
|
||||
} else if (state.getBlock() instanceof BlockAttackInteractionAware) {
|
||||
if (((BlockAttackInteractionAware) state.getBlock()).onAttackInteraction(state, world, pos, player, hand, direction)) {
|
||||
return ActionResult.FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.block.entity;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.ClientSerializable;
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.network.packet.BlockEntityUpdateClientPacket;
|
||||
|
@ -41,7 +41,7 @@ public abstract class MixinBlockEntity {
|
|||
public void toUpdatePacket(CallbackInfoReturnable<BlockEntityUpdateClientPacket> info) {
|
||||
Object self = (Object) this;
|
||||
|
||||
if (self instanceof ClientSerializable) {
|
||||
if (self instanceof BlockEntityClientSerializable) {
|
||||
// Mojang's serialization of x/y/z into the update packet is redundant,
|
||||
// as we have a separate fromClientTag() we don't do it.
|
||||
// However, we use the "id" field for type discernment, as actionId
|
||||
|
@ -55,7 +55,7 @@ public abstract class MixinBlockEntity {
|
|||
}
|
||||
|
||||
tag.putString("id", entityId.toString());
|
||||
tag = ((ClientSerializable) self).toClientTag(tag);
|
||||
tag = ((BlockEntityClientSerializable) self).toClientTag(tag);
|
||||
info.setReturnValue(new BlockEntityUpdateClientPacket(getPos(), 127, tag));
|
||||
info.cancel();
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ public abstract class MixinBlockEntity {
|
|||
public void toInitialChunkDataTag(CallbackInfoReturnable<CompoundTag> info) {
|
||||
Object self = (Object) this;
|
||||
|
||||
if (self instanceof ClientSerializable && info.getReturnValue() != null) {
|
||||
info.setReturnValue(((ClientSerializable) self).toClientTag(info.getReturnValue()));
|
||||
if (self instanceof BlockEntityClientSerializable && info.getReturnValue() != null) {
|
||||
info.setReturnValue(((BlockEntityClientSerializable) self).toClientTag(info.getReturnValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.block.entity;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.ClientSerializable;
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
|
@ -39,9 +39,9 @@ public class MixinClientPlayNetworkHandler {
|
|||
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/packet/BlockEntityUpdateClientPacket;getActionId()I", ordinal = 0), method = "onBlockEntityUpdate", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void onBlockEntityUpdate(BlockEntityUpdateClientPacket packet, CallbackInfo info, BlockEntity entity) {
|
||||
if (entity instanceof ClientSerializable) {
|
||||
if (entity instanceof BlockEntityClientSerializable) {
|
||||
if (packet.getActionId() == 127) {
|
||||
ClientSerializable serializable = (ClientSerializable) entity;
|
||||
BlockEntityClientSerializable serializable = (BlockEntityClientSerializable) entity;
|
||||
String id = packet.getCompoundTag().getString("id");
|
||||
if (id != null) {
|
||||
Identifier otherIdObj = BlockEntityType.getId(entity.getType());
|
||||
|
@ -65,8 +65,8 @@ public class MixinClientPlayNetworkHandler {
|
|||
|
||||
@Redirect(method = "onChunkData", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;fromTag(Lnet/minecraft/nbt/CompoundTag;)V"))
|
||||
public void deserializeBlockEntityChunkData(BlockEntity entity, CompoundTag tag) {
|
||||
if (entity instanceof ClientSerializable) {
|
||||
((ClientSerializable) entity).fromClientTag(tag);
|
||||
if (entity instanceof BlockEntityClientSerializable) {
|
||||
((BlockEntityClientSerializable) entity).fromClientTag(tag);
|
||||
} else {
|
||||
entity.fromTag(tag);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.events.playerinteraction;
|
||||
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickItemCallback;
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -31,11 +31,11 @@ public class MixinMinecraftClient {
|
|||
|
||||
@ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 2), method = "doItemPick", ordinal = 0)
|
||||
public ItemStack modifyItemPick(ItemStack stack) {
|
||||
ClientPickItemCallback.Container ctr = new ClientPickItemCallback.Container(stack);
|
||||
ClientPickBlockCallback.Container ctr = new ClientPickBlockCallback.Container(stack);
|
||||
//noinspection ConstantConditions
|
||||
MinecraftClient client = (MinecraftClient) (Object) this;
|
||||
|
||||
boolean toContinue = ClientPickItemCallback.EVENT.invoker().pick(client.player, client.hitResult, ctr);
|
||||
boolean toContinue = ClientPickBlockCallback.EVENT.invoker().pick(client.player, client.hitResult, ctr);
|
||||
if (!toContinue) {
|
||||
fabric_itemPickCancelled = true;
|
||||
return ItemStack.EMPTY;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "fabric",
|
||||
"name": "Fabric API",
|
||||
"version": "0.1.5",
|
||||
"version": "0.2.0",
|
||||
"side": "universal",
|
||||
"description": "Core API module providing key hooks and intercompatibility features.",
|
||||
"license": "Apache-2.0",
|
||||
|
|
Loading…
Add table
Reference in a new issue