19w02a update

This commit is contained in:
asie 2019-01-09 21:29:39 +01:00
parent 0c93861d27
commit 1ac17fe430
13 changed files with 61 additions and 53 deletions

View file

@ -27,7 +27,7 @@ targetCompatibility = 1.8
archivesBaseName = "fabric"
def baseVersion = "0.1.4"
def mcVersion = "18w50a"
def mcVersion = "19w02a"
def ENV = System.getenv()
version = baseVersion + "." + (ENV.BUILD_NUMBER ?: "local")
@ -38,7 +38,7 @@ minecraft {
dependencies {
minecraft "com.mojang:minecraft:$mcVersion"
mappings "net.fabricmc:yarn:$mcVersion.91"
mappings "net.fabricmc:yarn:$mcVersion.10"
modCompile "net.fabricmc:fabric-loader:0.3.2.91"
}

View file

@ -27,11 +27,12 @@ public interface ContainerFactory<T> {
*
* Creates the new object.
*
* @param syncId The container synchronization ID.
* @param identifier the Identifier is the name that was used when registering the factory
* @param player the player that is opening the gui/container
* @param buf the buffer contains the same data that was provided with {@Link ContainerProviderRegistry.openContainer}
* @return the new gui or container
*/
T create(Identifier identifier, PlayerEntity player, PacketByteBuf buf);
T create(int syncId, Identifier identifier, PlayerEntity player, PacketByteBuf buf);
}

View file

@ -19,7 +19,7 @@ package net.fabricmc.fabric.events;
import net.fabricmc.fabric.util.HandlerArray;
import net.fabricmc.fabric.util.HandlerRegistry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Profiler;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.World;
import java.util.function.Consumer;
@ -39,22 +39,22 @@ public final class TickEvent {
public static <T> void tick(HandlerRegistry<Consumer<T>> registry, T object, Profiler profiler) {
Consumer<T>[] handlers = ((HandlerArray<Consumer<T>>) registry).getBackingArray();
if (handlers.length > 0) {
profiler.begin("fabric");
profiler.push("fabric");
int i = 0;
for (Consumer<T> handler : handlers) {
if ((i++) == 0) {
profiler.begin(handler.getClass().getName());
profiler.push(handler.getClass().getName());
} else {
profiler.endBegin(handler.getClass().getName());
profiler.swap(handler.getClass().getName());
}
handler.accept(object);
}
if (i > 0) {
profiler.end();
profiler.pop();
}
profiler.end();
profiler.pop();
}
}
}

View file

@ -53,8 +53,8 @@ public class GuiProviderImpl implements GuiProviderRegistry {
@Override
public <C extends Container> void registerFactory(Identifier identifier, GuiFactory<C> guiFactory) {
registerFactory(identifier, (identifier1, player, buf) -> {
C container = ContainerProviderImpl.INSTANCE.createContainer(identifier1, player, buf);
registerFactory(identifier, (syncId, identifier1, player, buf) -> {
C container = ContainerProviderImpl.INSTANCE.createContainer(syncId, identifier1, player, buf);
if(container == null){
LOGGER.error("Could not open container for %s - a null object was created!", identifier1.toString());
return null;
@ -73,8 +73,7 @@ public class GuiProviderImpl implements GuiProviderRegistry {
LOGGER.error("No GUI factory found for %s!", identifier.toString());
return;
}
ContainerGui gui = factory.create(identifier, packetContext.getPlayer(), packetByteBuf);
gui.container.syncId = syncId;
ContainerGui gui = factory.create(syncId, identifier, packetContext.getPlayer(), packetByteBuf);
MinecraftClient.getInstance().openGui(gui);
});
});

View file

@ -77,21 +77,20 @@ public class ContainerProviderImpl implements ContainerProviderRegistry {
clonedBuf.readIdentifier();
clonedBuf.readUnsignedByte();
Container container = createContainer(identifier, player, clonedBuf);
Container container = createContainer(syncId, identifier, player, clonedBuf);
if(container == null){
return;
}
player.container = container;
player.container.syncId = syncId;
player.container.addListener(player);
}
public <C extends Container> C createContainer(Identifier identifier, PlayerEntity player, PacketByteBuf buf){
public <C extends Container> C createContainer(int syncId, Identifier identifier, PlayerEntity player, PacketByteBuf buf){
ContainerFactory<Container> factory = FACTORIES.get(identifier);
if (factory == null) {
LOGGER.error("No container factory found for %s!", identifier.toString());
return null;
}
return (C) factory.create(identifier, player, buf);
return (C) factory.create(syncId, identifier, player, buf);
}
}

View file

@ -21,7 +21,9 @@ import net.fabricmc.fabric.client.itemgroup.FabricCreativeGuiComponents;
import net.minecraft.client.gui.ingame.AbstractPlayerInventoryGui;
import net.minecraft.client.gui.ingame.CreativePlayerInventoryGui;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemGroup;
import net.minecraft.text.TextComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -32,14 +34,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(CreativePlayerInventoryGui.class)
public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInventoryGui implements CreativeGuiExtensions {
public MixinCreativePlayerInventoryGui(Container container_1, PlayerInventory playerInventory_1, TextComponent textComponent_1) {
super(container_1, playerInventory_1, textComponent_1);
}
@Shadow
protected abstract void setSelectedTab(ItemGroup itemGroup_1);
private int currentPage = 0;
public MixinCreativePlayerInventoryGui(Container container_1) {
super(container_1);
}
@Override
public void fabric_nextPage() {

View file

@ -30,7 +30,7 @@ import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportElement;
import net.minecraft.util.crash.CrashReportSection;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -128,7 +128,7 @@ public abstract class MixinSpriteAtlasTexture {
for (DependentSprite sprite : dependentSprites) {
Identifier id = ((Sprite) sprite).getId();
if (!spritesToLoad.contains(id)) {
CrashReportElement element = report.addElement("Unresolved sprite");
CrashReportSection element = report.addElement("Unresolved sprite");
element.add("Sprite", id);
element.add("Dependencies", Joiner.on(',').join(sprite.getDependencies()));
}

View file

@ -18,9 +18,9 @@ package net.fabricmc.fabric.mixin.events.tick;
import net.fabricmc.fabric.events.TickEvent;
import net.fabricmc.fabric.events.client.ClientTickEvent;
import net.minecraft.class_3689;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.profiler.DisableableProfiler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -32,7 +32,7 @@ import java.util.function.BooleanSupplier;
@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {
@Shadow
private class_3689 profiler;
private DisableableProfiler profiler;
@Inject(at = @At("RETURN"), method = "tick")
public void tick(CallbackInfo info) {

View file

@ -17,8 +17,8 @@
package net.fabricmc.fabric.mixin.events.tick;
import net.fabricmc.fabric.events.TickEvent;
import net.minecraft.class_3689;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.profiler.DisableableProfiler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -30,7 +30,7 @@ import java.util.function.BooleanSupplier;
@Mixin(MinecraftServer.class)
public class MixinMinecraftServer {
@Shadow
private class_3689 profiler;
private DisableableProfiler profiler;
@Inject(at = @At("RETURN"), method = "tick")
protected void tick(BooleanSupplier var1, CallbackInfo info) {

View file

@ -17,7 +17,7 @@
package net.fabricmc.fabric.mixin.events.tick;
import net.fabricmc.fabric.events.TickEvent;
import net.minecraft.util.Profiler;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

View file

@ -22,7 +22,7 @@ import net.fabricmc.loader.ModContainer;
import net.fabricmc.loader.ModInfo;
import net.minecraft.util.SystemUtil;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportElement;
import net.minecraft.util.crash.CrashReportSection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -35,19 +35,11 @@ import java.util.*;
@Mixin(CrashReport.class)
public abstract class MixinCrashReport {
@Shadow
public abstract CrashReportElement getElement();
public abstract CrashReportSection getSystemDetailsSection();
@Inject(at = @At("HEAD"), method = "generateWittyComment", cancellable = true)
private static void generateWittyComment(CallbackInfoReturnable<String> info) {
if (SystemUtil.getMeasuringTimeNano() % 14723 == 0) {
info.setReturnValue("OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!");
info.cancel();
}
}
@Inject(at = @At("RETURN"), method = "method_559")
private void method_559(CallbackInfo info) {
getElement().add("Fabric Mods", () -> {
@Inject(at = @At("RETURN"), method = "fillSystemDetails")
private void fillSystemDetails(CallbackInfo info) {
getSystemDetailsSection().add("Fabric Mods", () -> {
Map<String, String> mods = new TreeMap<>();
for (ModContainer container : FabricLoader.INSTANCE.getModContainers()) {
mods.put(container.getInfo().getName(), container.getInfo().getVersionString() + " (" + container.getOriginFile().getName() + ")");

View file

@ -19,8 +19,10 @@ package net.fabricmc.fabric.containers;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.commands.CommandRegistry;
import net.minecraft.class_3917;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.server.command.ServerCommandManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -28,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
public class ContainerMod implements ModInitializer {
public static final Identifier EXAMPLE_CONTAINER = new Identifier("fabric_container", "example_container");
public static final Identifier EXAMPLE_CONTAINER_2 = new Identifier("fabric_container", "example_container_2");
@Override
public void onInitialize() {
@ -45,23 +48,33 @@ public class ContainerMod implements ModInitializer {
})));
//Registers a container factory that opens our example Container, this reads the block pos from the buffer
ContainerProviderRegistry.INSTANCE.registerFactory(EXAMPLE_CONTAINER, (identifier, player, buf) -> {
ContainerProviderRegistry.INSTANCE.registerFactory(EXAMPLE_CONTAINER, (syncId, identifier, player, buf) -> {
BlockPos pos = buf.readBlockPos();
return new ExampleContainer(pos, player);
return new ExampleContainer(syncId, pos, player);
});
ContainerProviderRegistry.INSTANCE.registerFactory(EXAMPLE_CONTAINER_2, (syncId, identifier, player, buf) -> {
BlockPos pos = buf.readBlockPos();
return new ExampleContainer(syncId, pos, player);
});
}
//A basic container that prints to console when opened, this should print on the client + server
public static class ExampleContainer extends Container {
public final PlayerInventory playerInventory;
BlockPos pos;
public ExampleContainer(BlockPos pos, PlayerEntity playerEntity) {
public ExampleContainer(int syncId, BlockPos pos, PlayerEntity playerEntity) {
super(syncId);
this.pos = pos;
this.playerInventory = playerEntity.inventory;
System.out.println("Opened container, " + pos);
}
@Override
public class_3917<?> method_17358() {
return null;
}
@Override
public boolean canUse(PlayerEntity playerEntity) {
return true;

View file

@ -20,6 +20,7 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.gui.GuiProviderRegistry;
import net.minecraft.client.gui.ContainerGui;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.StringTextComponent;
import net.minecraft.util.math.BlockPos;
public class ContainerModClient implements ClientModInitializer {
@ -27,22 +28,22 @@ public class ContainerModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
//Registers a gui factory that opens our example gui, this reads the block pos from the buffer
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER, (identifier, player, buf) -> {
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER, (syncId, identifier, player, buf) -> {
BlockPos pos = buf.readBlockPos();
return new ExampleContainerGui(pos, player);
return new ExampleContainerGui(syncId, pos, player);
});
//Registers a gui factory that opens our example gui, this uses the container created by ContainerProviderRegistry
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER, ExampleContainerGui2::new);
GuiProviderRegistry.INSTANCE.registerFactory(ContainerMod.EXAMPLE_CONTAINER_2, ExampleContainerGui2::new);
}
//A container gui that shows the block pos that was sent
public static class ExampleContainerGui extends ContainerGui {
public static class ExampleContainerGui extends ContainerGui<ContainerMod.ExampleContainer> {
BlockPos pos;
public ExampleContainerGui(BlockPos pos, PlayerEntity playerEntity) {
super(new ContainerMod.ExampleContainer(pos, playerEntity));
public ExampleContainerGui(int syncId, BlockPos pos, PlayerEntity playerEntity) {
super(new ContainerMod.ExampleContainer(syncId, pos, playerEntity), playerEntity.inventory, new StringTextComponent("Example GUI"));
this.pos = pos;
}
@ -54,12 +55,12 @@ public class ContainerModClient implements ClientModInitializer {
//A container gui that shows how you can take in a container provided by a GuiFactory
public static class ExampleContainerGui2 extends ContainerGui {
public static class ExampleContainerGui2 extends ContainerGui<ContainerMod.ExampleContainer> {
BlockPos pos;
public ExampleContainerGui2(ContainerMod.ExampleContainer container) {
super(container);
super(container, container.playerInventory, new StringTextComponent("Example GUI 2"));
this.pos = container.pos;
}