Skip to content

Commit

Permalink
1.16-pre3
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <daniel@shedaniel.me>
  • Loading branch information
shedaniel committed Jun 11, 2020
1 parent 3913836 commit 01e2cf7
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 32 deletions.
5 changes: 5 additions & 0 deletions README.md
@@ -1,5 +1,9 @@
# Cloth API
## Maven
```groovy
modApi "me.shedaniel.cloth.api:cloth-api:${project.cloth_api_version}"
include "me.shedaniel.cloth.api:cloth-api:${project.cloth_api_version}"
```
## APIs
#### cloth-armor-api-v1
**To be implemented:**
Expand All @@ -16,6 +20,7 @@
- ClothClientHooks#SCREEN_INIT_PRE: Called before Screen#init
- ClothClientHooks#SCREEN_INIT_POST: Called after Screen#init
- ClothClientHooks#SCREEN_ADD_BUTTON: Called on Screen#addButton
- ClothClientHooks#SCREEN_ADD_CHILD: Called on Screen#addChild
- ClothClientHooks#SCREEN_MOUSE_SCROLLED: Called on mouseScrolled
- ClothClientHooks#SCREEN_MOUSE_CLICKED: Called on mouseClicked
- ClothClientHooks#SCREEN_MOUSE_RELEASED: Called on mouseReleased
Expand Down
13 changes: 7 additions & 6 deletions build.gradle
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'fabric-loom' version '0.4.18' apply false
id 'fabric-loom' version '0.4-SNAPSHOT' apply false
id 'net.minecrell.licenser' version '0.4.1'
id "org.ajoberstar.grgit" version "3.1.1"
id 'com.matthewprenger.cursegradle' version "1.4.0"
Expand Down Expand Up @@ -47,9 +47,14 @@ allprojects {
}
}

repositories {
maven { url "https://dl.bintray.com/shedaniel/legacy-yarn-updated" }
mavenLocal()
}

dependencies {
minecraft "com.mojang:minecraft:$project.minecraft_version"
mappings "net.fabricmc:yarn:${project.yarn_version}:v2"
mappings "me.shedaniel:legacy-yarn:${project.yarn_version}:v2"
modCompile "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
Expand All @@ -60,10 +65,6 @@ allprojects {
dev
}

repositories {
mavenLocal()
}

jar {
classifier = "dev"
}
Expand Down
Expand Up @@ -36,8 +36,15 @@

public interface CustomTexturedArmor {
@Environment(EnvType.CLIENT)
@Deprecated
@Nullable
default String getArmorTexture(EquipmentSlot slot, ArmorItem armorItem, boolean secondLayer, @Nullable String suffix) {
return this.getArmorTexture(armorItem, secondLayer, suffix);
}

@Environment(EnvType.CLIENT)
@Nullable
default String getArmorTexture(ArmorItem armorItem, boolean secondLayer, @Nullable String suffix) {
return null;
}
}
Expand Up @@ -56,7 +56,7 @@
public abstract class MixinArmorFeatureRenderer extends FeatureRenderer {
@Shadow
@Final
protected static Map<String, Identifier> ARMOR_TEXTURE_CACHE;
private static Map<String, Identifier> ARMOR_TEXTURE_CACHE;

public MixinArmorFeatureRenderer(FeatureRendererContext context) {
super(context);
Expand All @@ -81,10 +81,10 @@ private void getArmor(EquipmentSlot slot, CallbackInfoReturnable<BipedEntityMode
}

@Inject(method = "getArmorTexture", at = @At("HEAD"), cancellable = true)
private void getArmorTexture(EquipmentSlot slot, ArmorItem armorItem, boolean secondLayer,
@Nullable String suffix, CallbackInfoReturnable<Identifier> cir) {
private void getArmorTexture(ArmorItem armorItem, boolean secondLayer, @Nullable String suffix, CallbackInfoReturnable<Identifier> cir) {
if (armorItem instanceof CustomTexturedArmor) {
String model = ((CustomTexturedArmor) armorItem).getArmorTexture(slot, armorItem, secondLayer, suffix);
@SuppressWarnings("deprecation")
String model = ((CustomTexturedArmor) armorItem).getArmorTexture(armorItem.getSlotType(), armorItem, secondLayer, suffix);
if (model != null) {
cir.setReturnValue(ARMOR_TEXTURE_CACHE.computeIfAbsent(model, Identifier::new));
}
Expand Down
Expand Up @@ -84,9 +84,19 @@ public class ClothClientHooks {
};
});
public static final Event<ScreenAddButtonCallback> SCREEN_ADD_BUTTON = EventFactory.createArrayBacked(ScreenAddButtonCallback.class, listeners -> {
return (client, screen, hooks) -> {
return (client, screen, button) -> {
for (ScreenAddButtonCallback listener : listeners) {
ActionResult result = listener.addButton(client, screen, hooks);
ActionResult result = listener.addButton(client, screen, button);
if (result != ActionResult.PASS)
return result;
}
return ActionResult.PASS;
};
});
public static final Event<ScreenAddChildCallback> SCREEN_ADD_CHILD = EventFactory.createArrayBacked(ScreenAddChildCallback.class, listeners -> {
return (client, screen, element) -> {
for (ScreenAddChildCallback listener : listeners) {
ActionResult result = listener.addChild(client, screen, element);
if (result != ActionResult.PASS)
return result;
}
Expand Down
@@ -0,0 +1,40 @@
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

package me.shedaniel.cloth.api.client.events.v0;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ActionResult;

/**
* Called on {@link Screen#addChild(Element)}
*/
public interface ScreenAddChildCallback {
ActionResult addChild(MinecraftClient client, Screen screen, Element element);
}
Expand Up @@ -33,7 +33,6 @@
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
Expand Down Expand Up @@ -65,6 +64,8 @@ public abstract class MixinScreen implements ScreenHooks {
@Shadow
protected abstract <T extends AbstractButtonWidget> T addButton(T abstractButtonWidget_1);

@Shadow public int width;

@Override
public List<AbstractButtonWidget> cloth$getButtonWidgets() {
return buttons;
Expand Down Expand Up @@ -112,11 +113,20 @@ public void onPostInit(MinecraftClient minecraftClient_1, int int_1, int int_2,
}

@Inject(method = "addButton", at = @At("HEAD"), cancellable = true)
public void onAddButton(AbstractButtonWidget widget, CallbackInfoReturnable<ButtonWidget> info) {
public void onAddButton(AbstractButtonWidget widget, CallbackInfoReturnable<AbstractButtonWidget> info) {
if (!info.isCancelled()) {
ActionResult result = ClothClientHooks.SCREEN_ADD_BUTTON.invoker().addButton(client, (Screen) (Object) this, widget);
if (result != ActionResult.PASS)
info.cancel();
info.setReturnValue(widget);
}
}

@Inject(method = "addChild", at = @At("HEAD"), cancellable = true)
public void addChild(Element widget, CallbackInfoReturnable<Element> info) {
if (!info.isCancelled()) {
ActionResult result = ClothClientHooks.SCREEN_ADD_CHILD.invoker().addChild(client, (Screen) (Object) this, widget);
if (result != ActionResult.PASS)
info.setReturnValue(widget);
}
}

Expand Down
Expand Up @@ -32,7 +32,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.IWorld;

public interface BlockBreakCallback {
Event<BlockBreakCallback> EVENT = EventFactory.createArrayBacked(BlockBreakCallback.class, callbacks -> (world, pos, state, player) -> {
Expand All @@ -41,5 +41,5 @@ public interface BlockBreakCallback {
}
});

void onBroken(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player);
void onBroken(IWorld world, BlockPos pos, BlockState state, PlayerEntity player);
}
Expand Up @@ -31,12 +31,10 @@
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

import javax.annotation.Nullable;

Expand Down
Expand Up @@ -29,26 +29,26 @@

import com.mojang.authlib.GameProfile;
import me.shedaniel.cloth.api.common.events.v1.PlayerChangeWorldCallback;
import net.minecraft.container.ContainerListener;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerListener;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener {
public abstract class MixinServerPlayerEntity extends PlayerEntity implements ContainerListener {
public MixinServerPlayerEntity(World world, BlockPos blockPos, GameProfile gameProfile) {
super(world, blockPos, gameProfile);
}

@Inject(method = "changeDimension", at = @At("HEAD"))
private void changeDimension(RegistryKey<World> newWorld, CallbackInfoReturnable<Entity> cir) {
PlayerChangeWorldCallback.EVENT.invoker().onChangeWorld((ServerPlayerEntity) (Object) this, this.world.method_27983(), newWorld);
private void changeDimension(ServerWorld newWorld, CallbackInfoReturnable<Entity> cir) {
PlayerChangeWorldCallback.EVENT.invoker().onChangeWorld((ServerPlayerEntity) (Object) this, this.world.getRegistryKey(), newWorld.getRegistryKey());
}
}
Expand Up @@ -46,7 +46,7 @@ public class MixinServerPlayerInteractionManager {
@Shadow public ServerPlayerEntity player;

@Inject(method = "tryBreakBlock", at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"))
target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"))
private void onBreak(BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
BlockState blockState = this.world.getBlockState(blockPos);
BlockBreakCallback.EVENT.invoker().onBroken(this.world, blockPos, blockState, this.player);
Expand Down
Expand Up @@ -29,14 +29,14 @@

import me.shedaniel.cloth.api.common.events.v1.WorldLoadCallback;
import me.shedaniel.cloth.api.common.events.v1.WorldSaveCallback;
import net.minecraft.class_5304;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ProgressListener;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Spawner;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.level.storage.LevelStorage;
Expand All @@ -51,7 +51,7 @@
@Mixin(ServerWorld.class)
public class MixinServerWorld {
@Inject(method = "<init>", at = @At("RETURN"))
private void init(MinecraftServer minecraftServer, Executor executor, LevelStorage.Session session, ServerWorldProperties serverWorldProperties, RegistryKey<World> registryKey, RegistryKey<DimensionType> registryKey2, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List<class_5304> list, boolean bl2, CallbackInfo ci) {
private void init(MinecraftServer minecraftServer, Executor executor, LevelStorage.Session session, ServerWorldProperties serverWorldProperties, RegistryKey<World> registryKey, RegistryKey<DimensionType> registryKey2, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List<Spawner> list, boolean bl2, CallbackInfo ci) {
WorldLoadCallback.EVENT.invoker().onLoad(registryKey, (ServerWorld) (Object) this);
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
@@ -1,8 +1,8 @@
#org.gradle.daemon=false
org.gradle.jvmargs=-Xmx2G
minecraft_version=20w22a
yarn_version=20w22a+build.4
fabric_loader_version=0.8.4+build.198
fabric_version=0.11.1+build.350-1.16
mod_version=1.0.1
minecraft_version=1.16-pre3
yarn_version=1.16-pre3+build.1+legacy.20w09a+build.8
fabric_loader_version=0.8.7+build.201
fabric_version=0.11.8+build.357-1.16
mod_version=1.0.2
cloth_basic_math=0.5.1

0 comments on commit 01e2cf7

Please sign in to comment.