gui -> screen

This commit is contained in:
Adrian Siekierka 2019-02-09 16:46:52 +01:00
parent 562d9fce4e
commit cc6ae9d3cf
8 changed files with 30 additions and 30 deletions

View file

@ -26,7 +26,7 @@ import net.minecraft.world.World;
/** /**
* Convienence interface for blocks which listen to "break interactions" (left-click). * Convienence interface for blocks which listen to "break interactions" (left-click).
*/ */
public interface BreakInteractable { public interface AttackInteractable {
/** /**
* @return True if the block accepted the player and it should no longer be processed. * @return True if the block accepted the player and it should no longer be processed.
*/ */

View file

@ -14,13 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package net.fabricmc.fabric.api.client.gui; package net.fabricmc.fabric.api.client.screen;
import net.minecraft.client.gui.ContainerScreen; import net.minecraft.client.gui.ContainerScreen;
import net.minecraft.container.Container; import net.minecraft.container.Container;
@FunctionalInterface @FunctionalInterface
public interface GuiFactory<C extends Container> { public interface ContainerScreenFactory<C extends Container> {
ContainerScreen create(C container); ContainerScreen create(C container);

View file

@ -14,27 +14,27 @@
* limitations under the License. * limitations under the License.
*/ */
package net.fabricmc.fabric.api.client.gui; package net.fabricmc.fabric.api.client.screen;
import net.fabricmc.fabric.api.container.ContainerFactory; import net.fabricmc.fabric.api.container.ContainerFactory;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry; import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.impl.client.gui.GuiProviderImpl; import net.fabricmc.fabric.impl.client.gui.ScreenProviderRegistryImpl;
import net.minecraft.client.gui.ContainerScreen; import net.minecraft.client.gui.ContainerScreen;
import net.minecraft.container.Container; import net.minecraft.container.Container;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public interface GuiProviderRegistry { public interface ScreenProviderRegistry {
GuiProviderRegistry INSTANCE = GuiProviderImpl.INSTANCE; ScreenProviderRegistry INSTANCE = ScreenProviderRegistryImpl.INSTANCE;
/** /**
* *
* Register a "Container -> ContainerScreen" factory. This is used only on the client side. * Register a "Container -> ContainerScreen" factory. This is used only on the client side.
* *
* @param identifier a shared identifier, this identifier should also be used to register a container using {@link ContainerProviderRegistry} * @param identifier a shared identifier, this identifier should also be used to register a container using {@link ContainerProviderRegistry}
* @param guiFactory the supplier that should be used to create the new gui * @param containerScreenFactory the supplier that should be used to create the new gui
*/ */
<C extends Container> void registerFactory(Identifier identifier, GuiFactory<C> guiFactory); <C extends Container> void registerFactory(Identifier identifier, ContainerScreenFactory<C> containerScreenFactory);
/** /**
* *

View file

@ -16,7 +16,7 @@
package net.fabricmc.fabric.api.container; package net.fabricmc.fabric.api.container;
import net.fabricmc.fabric.api.client.gui.GuiProviderRegistry; import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.impl.container.ContainerProviderImpl; import net.fabricmc.fabric.impl.container.ContainerProviderImpl;
import net.minecraft.container.Container; import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -34,7 +34,7 @@ public interface ContainerProviderRegistry {
* *
* Register a "packet buffer -> container" factory. This is used both on the client and server side. * Register a "packet buffer -> container" factory. This is used both on the client and server side.
* *
* @param identifier a shared identifier, this identifier should also be used to register a container using {@link GuiProviderRegistry} * @param identifier a shared identifier, this identifier should also be used to register a container using {@link ScreenProviderRegistry}
* @param factory the ContainerFactory that should return a new {@link Container} * @param factory the ContainerFactory that should return a new {@link Container}
*/ */
void registerFactory(Identifier identifier, ContainerFactory<Container> factory); void registerFactory(Identifier identifier, ContainerFactory<Container> factory);

View file

@ -17,7 +17,7 @@
package net.fabricmc.fabric.impl; package net.fabricmc.fabric.impl;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.impl.client.gui.GuiProviderImpl; import net.fabricmc.fabric.impl.client.gui.ScreenProviderRegistryImpl;
import net.fabricmc.fabric.api.network.CustomPayloadPacketRegistry; import net.fabricmc.fabric.api.network.CustomPayloadPacketRegistry;
import net.fabricmc.fabric.impl.registry.RegistrySyncManager; import net.fabricmc.fabric.impl.registry.RegistrySyncManager;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -30,6 +30,6 @@ public class FabricAPIClientInitializer implements ClientModInitializer {
RegistrySyncManager.receivePacket(ctx, buf, !MinecraftClient.getInstance().isInSingleplayer()); RegistrySyncManager.receivePacket(ctx, buf, !MinecraftClient.getInstance().isInSingleplayer());
}); });
((GuiProviderImpl)GuiProviderImpl.INSTANCE).init(); ((ScreenProviderRegistryImpl) ScreenProviderRegistryImpl.INSTANCE).init();
} }
} }

View file

@ -17,8 +17,8 @@
package net.fabricmc.fabric.impl; package net.fabricmc.fabric.impl;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.block.AttackInteractable;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.fabricmc.fabric.api.block.BreakInteractable;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -27,12 +27,12 @@ public class FabricAPIInitializer implements ModInitializer {
public void onInitialize() { public void onInitialize() {
AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> { AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
if (state instanceof BreakInteractable) { if (state instanceof AttackInteractable) {
if (((BreakInteractable) state).onBreakInteract(state, world, pos, player, hand, direction)) { if (((AttackInteractable) state).onBreakInteract(state, world, pos, player, hand, direction)) {
return ActionResult.FAILURE; return ActionResult.FAILURE;
} }
} else if (state.getBlock() instanceof BreakInteractable) { } else if (state.getBlock() instanceof AttackInteractable) {
if (((BreakInteractable) state.getBlock()).onBreakInteract(state, world, pos, player, hand, direction)) { if (((AttackInteractable) state.getBlock()).onBreakInteract(state, world, pos, player, hand, direction)) {
return ActionResult.FAILURE; return ActionResult.FAILURE;
} }
} }

View file

@ -16,9 +16,9 @@
package net.fabricmc.fabric.impl.client.gui; package net.fabricmc.fabric.impl.client.gui;
import net.fabricmc.fabric.api.client.gui.GuiProviderRegistry; import net.fabricmc.fabric.api.client.screen.ContainerScreenFactory;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.api.container.ContainerFactory; import net.fabricmc.fabric.api.container.ContainerFactory;
import net.fabricmc.fabric.api.client.gui.GuiFactory;
import net.fabricmc.fabric.impl.container.ContainerProviderImpl; import net.fabricmc.fabric.impl.container.ContainerProviderImpl;
import net.fabricmc.fabric.api.network.CustomPayloadPacketRegistry; import net.fabricmc.fabric.api.network.CustomPayloadPacketRegistry;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -31,12 +31,12 @@ import org.apache.logging.log4j.Logger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class GuiProviderImpl implements GuiProviderRegistry { public class ScreenProviderRegistryImpl implements ScreenProviderRegistry {
/** /**
* Use the instance provided by GuiProviderRegistry * Use the instance provided by ScreenProviderRegistry
*/ */
public static final GuiProviderRegistry INSTANCE = new GuiProviderImpl(); public static final ScreenProviderRegistry INSTANCE = new ScreenProviderRegistryImpl();
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@ -51,14 +51,14 @@ public class GuiProviderImpl implements GuiProviderRegistry {
} }
@Override @Override
public <C extends Container> void registerFactory(Identifier identifier, GuiFactory<C> guiFactory) { public <C extends Container> void registerFactory(Identifier identifier, ContainerScreenFactory<C> containerScreenFactory) {
registerFactory(identifier, (syncId, identifier1, player, buf) -> { registerFactory(identifier, (syncId, identifier1, player, buf) -> {
C container = ContainerProviderImpl.INSTANCE.createContainer(syncId, identifier1, player, buf); C container = ContainerProviderImpl.INSTANCE.createContainer(syncId, identifier1, player, buf);
if(container == null){ if(container == null){
LOGGER.error("Could not open container for {} - a null object was created!", identifier1.toString()); LOGGER.error("Could not open container for {} - a null object was created!", identifier1.toString());
return null; return null;
} }
return guiFactory.create(container); return containerScreenFactory.create(container);
}); });
} }

View file

@ -18,7 +18,7 @@ package net.fabricmc.fabric.containers;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.gui.GuiProviderRegistry; import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.minecraft.client.gui.ContainerScreen; import net.minecraft.client.gui.ContainerScreen;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.StringTextComponent; import net.minecraft.text.StringTextComponent;
@ -30,16 +30,16 @@ public class ContainerModClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
//Registers a gui factory that opens our example gui, this reads the block pos from the buffer //Registers a gui factory that opens our example gui, this reads the block pos from the buffer
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER, (syncId, identifier, player, buf) -> { ScreenProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER, (syncId, identifier, player, buf) -> {
BlockPos pos = buf.readBlockPos(); BlockPos pos = buf.readBlockPos();
return new ExampleContainerScreen(syncId, pos, player); return new ExampleContainerScreen(syncId, pos, player);
}); });
//Registers a gui factory that opens our example gui, this uses the container created by ContainerProviderRegistry //Registers a gui factory that opens our example gui, this uses the container created by ContainerProviderRegistry
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER_2, ExampleContainerScreen2::new); ScreenProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER_2, ExampleContainerScreen2::new);
//Registers a gui factory that opens our example inventory gui //Registers a gui factory that opens our example inventory gui
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_INVENTORY_CONTAINER, ExampleInventoryContainerScreen::new); ScreenProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_INVENTORY_CONTAINER, ExampleInventoryContainerScreen::new);
} }
//A container gui that shows the block pos that was sent //A container gui that shows the block pos that was sent
@ -59,7 +59,7 @@ public class ContainerModClient implements ClientModInitializer {
} }
//A container gui that shows how you can take in a container provided by a GuiFactory //A container gui that shows how you can take in a container provided by a ContainerScreenFactory
public static class ExampleContainerScreen2 extends ContainerScreen<ContainerMod.ExampleContainer> { public static class ExampleContainerScreen2 extends ContainerScreen<ContainerMod.ExampleContainer> {
BlockPos pos; BlockPos pos;