fix license headers

This commit is contained in:
Adrian Siekierka 2018-12-09 17:45:27 +01:00
parent 897478bb9a
commit 0ca8947681
9 changed files with 117 additions and 72 deletions

View file

@ -3,11 +3,11 @@ buildscript {
jcenter() jcenter()
maven { maven {
name = 'Fabric' name = 'Fabric'
url = 'http://maven.modmuss50.me/' url = 'http://maven.fabricmc.net/'
} }
} }
dependencies { dependencies {
classpath "net.fabricmc:fabric-loom:0.0.14-SNAPSHOT" classpath "net.fabricmc:fabric-loom:0.1.0-SNAPSHOT"
} }
} }
@ -23,7 +23,7 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
archivesBaseName = "fabric" archivesBaseName = "fabric"
version = "0.1.0-SNAPSHOT" version = "0.1.0"
minecraft { minecraft {
refmapName = "net.fabricmc.fabric.refmap.json" refmapName = "net.fabricmc.fabric.refmap.json"
@ -31,8 +31,8 @@ minecraft {
dependencies { dependencies {
minecraft "com.mojang:minecraft:18w49a" minecraft "com.mojang:minecraft:18w49a"
mappings "net.fabricmc:pomf:18w49a.16" mappings "net.fabricmc:pomf:18w49a.19"
modCompile "net.fabricmc:fabric-loader:0.1.0.52" modCompile "net.fabricmc:fabric-loader:0.2.0.53"
} }
apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle' apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle'

View file

@ -30,14 +30,14 @@ import net.minecraft.world.loot.LootTables;
import java.util.function.Function; import java.util.function.Function;
/** /**
* Fabric's version of Block.Builder. Adds additional methods and hooks * Fabric's version of Block.Settings. Adds additional methods and hooks
* not found in the original class. * not found in the original class.
* *
* To use it, simply replace Block.Builder.create() with * To use it, simply replace Block.Settings.create() with
* FabricBlockBuilder.create() and add .build() at the end to return the * FabricBlockSettings.create() and add .build() at the end to return the
* vanilla Block.Builder instance beneath. * vanilla Block.Settings instance beneath.
*/ */
public class FabricBlockBuilder { public class FabricBlockSettings {
public interface Delegate { public interface Delegate {
void fabric_setMapColor(MaterialColor color); void fabric_setMapColor(MaterialColor color);
void fabric_setCollidable(boolean value); void fabric_setCollidable(boolean value);
@ -50,51 +50,51 @@ public class FabricBlockBuilder {
void fabric_setDropTable(Identifier id); void fabric_setDropTable(Identifier id);
} }
protected final Block.Builder delegate; protected final Block.Settings delegate;
private final FabricBlockBuilder.Delegate castDelegate; private final FabricBlockSettings.Delegate castDelegate;
protected FabricBlockBuilder(Material material) { protected FabricBlockSettings(Material material) {
delegate = Block.Builder.create(material); delegate = Block.Settings.create(material);
castDelegate = (FabricBlockBuilder.Delegate) delegate; castDelegate = (FabricBlockSettings.Delegate) delegate;
} }
protected FabricBlockBuilder(Block base) { protected FabricBlockSettings(Block base) {
delegate = Block.Builder.copy(base); delegate = Block.Settings.copy(base);
castDelegate = (FabricBlockBuilder.Delegate) delegate; castDelegate = (FabricBlockSettings.Delegate) delegate;
} }
public static FabricBlockBuilder create(Material material) { public static FabricBlockSettings create(Material material) {
return new FabricBlockBuilder(material); return new FabricBlockSettings(material);
} }
public static FabricBlockBuilder copy(Block base) { public static FabricBlockSettings copy(Block base) {
return new FabricBlockBuilder(base); return new FabricBlockSettings(base);
} }
/* FABRIC HELPERS */ /* FABRIC HELPERS */
public FabricBlockBuilder setBreakByHand(boolean value) { public FabricBlockSettings setBreakByHand(boolean value) {
ToolManager.get(delegate).breakByHand(value); ToolManager.entry(delegate).setBreakByHand(value);
return this; return this;
} }
public FabricBlockBuilder setBreakByTool(Tag<Item> tag) { public FabricBlockSettings setBreakByTool(Tag<Item> tag) {
return setBreakByTool(tag, 0); return setBreakByTool(tag, 0);
} }
public FabricBlockBuilder setBreakByTool(Tag<Item> tag, int miningLevel) { public FabricBlockSettings setBreakByTool(Tag<Item> tag, int miningLevel) {
ToolManager.get(delegate).putBreakByTool(tag, miningLevel); ToolManager.entry(delegate).putBreakByTool(tag, miningLevel);
return this; return this;
} }
/* DELEGATE WRAPPERS */ /* DELEGATE WRAPPERS */
public FabricBlockBuilder setMaterialColor(MaterialColor color) { public FabricBlockSettings setMaterialColor(MaterialColor color) {
castDelegate.fabric_setMapColor(color); castDelegate.fabric_setMapColor(color);
return this; return this;
} }
public FabricBlockBuilder setMaterialColor(DyeColor color) { public FabricBlockSettings setMaterialColor(DyeColor color) {
castDelegate.fabric_setMapColor(color.getMaterialColor()); castDelegate.fabric_setMapColor(color.getMaterialColor());
return this; return this;
} }
@ -103,7 +103,7 @@ public class FabricBlockBuilder {
* @deprecated Use {@link #setMaterialColor(MaterialColor) setMaterialColor} instead. * @deprecated Use {@link #setMaterialColor(MaterialColor) setMaterialColor} instead.
*/ */
@Deprecated @Deprecated
public FabricBlockBuilder setMapColor(MaterialColor color) { public FabricBlockSettings setMapColor(MaterialColor color) {
return setMaterialColor(color); return setMaterialColor(color);
} }
@ -111,74 +111,74 @@ public class FabricBlockBuilder {
* @deprecated Use {@link #setMaterialColor(DyeColor) setMaterialColor} instead. * @deprecated Use {@link #setMaterialColor(DyeColor) setMaterialColor} instead.
*/ */
@Deprecated @Deprecated
public FabricBlockBuilder setMapColor(DyeColor color) { public FabricBlockSettings setMapColor(DyeColor color) {
return setMaterialColor(color); return setMaterialColor(color);
} }
public FabricBlockBuilder setCollidable(boolean value) { public FabricBlockSettings setCollidable(boolean value) {
castDelegate.fabric_setCollidable(value); castDelegate.fabric_setCollidable(value);
return this; return this;
} }
public FabricBlockBuilder setSoundGroup(BlockSoundGroup group) { public FabricBlockSettings setSoundGroup(BlockSoundGroup group) {
castDelegate.fabric_setSoundGroup(group); castDelegate.fabric_setSoundGroup(group);
return this; return this;
} }
public FabricBlockBuilder acceptRandomTicks() { public FabricBlockSettings acceptRandomTicks() {
castDelegate.fabric_setRandomTicks(true); castDelegate.fabric_setRandomTicks(true);
return this; return this;
} }
public FabricBlockBuilder setLuminance(int value) { public FabricBlockSettings setLuminance(int value) {
castDelegate.fabric_setLuminance(value); castDelegate.fabric_setLuminance(value);
return this; return this;
} }
public FabricBlockBuilder setHardness(float value) { public FabricBlockSettings setHardness(float value) {
castDelegate.fabric_setHardness(value); castDelegate.fabric_setHardness(value);
castDelegate.fabric_setResistance(value); castDelegate.fabric_setResistance(value);
return this; return this;
} }
public FabricBlockBuilder setResistance(float value) { public FabricBlockSettings setResistance(float value) {
castDelegate.fabric_setResistance(value); castDelegate.fabric_setResistance(value);
return this; return this;
} }
public FabricBlockBuilder setStrength(float hardness, float resistance) { public FabricBlockSettings setStrength(float hardness, float resistance) {
castDelegate.fabric_setHardness(hardness); castDelegate.fabric_setHardness(hardness);
castDelegate.fabric_setResistance(resistance); castDelegate.fabric_setResistance(resistance);
return this; return this;
} }
public FabricBlockBuilder noDropTable() { public FabricBlockSettings noDropTable() {
castDelegate.fabric_setDropTable(LootTables.EMPTY); castDelegate.fabric_setDropTable(LootTables.EMPTY);
return this; return this;
} }
public FabricBlockBuilder copyDropTable(Block block) { public FabricBlockSettings copyDropTable(Block block) {
castDelegate.fabric_setDropTable(block.getDropTableId()); castDelegate.fabric_setDropTable(block.getDropTableId());
return this; return this;
} }
public FabricBlockBuilder setDropTable(Identifier id) { public FabricBlockSettings setDropTable(Identifier id) {
castDelegate.fabric_setDropTable(id); castDelegate.fabric_setDropTable(id);
return this; return this;
} }
public FabricBlockBuilder setFrictionCoefficient(float value) { public FabricBlockSettings setFrictionCoefficient(float value) {
castDelegate.fabric_setFriction(value); castDelegate.fabric_setFriction(value);
return this; return this;
} }
/* BUILDING LOGIC */ /* BUILDING LOGIC */
public Block.Builder build() { public Block.Settings build() {
return delegate; return delegate;
} }
public <T> T build(Function<Block.Builder, T> function) { public <T> T build(Function<Block.Settings, T> function) {
return function.apply(delegate); return function.apply(delegate);
} }
} }

View file

@ -24,13 +24,13 @@ import net.minecraft.item.Item;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
/** /**
* This is a class for events emitted when a Block.Builder/Item.Builder is * This is a class for events emitted when a Block.Settings/Item.Settings is
* turned into a Block or Item. You can use these to extend these builders with * turned into a Block or Item. You can use these to extend these builders with
* your own methods and transparently add the resulting information to a Map. * your own methods and transparently add the resulting information to a Map.
*/ */
public final class ObjectBuilderEvent { public final class ObjectBuilderEvent {
public static final HandlerRegistry<BiConsumer<Block.Builder, Block>> BLOCK = new HandlerList<>(); public static final HandlerRegistry<BiConsumer<Block.Settings, Block>> BLOCK = new HandlerList<>();
public static final HandlerRegistry<BiConsumer<Item.Builder, Item>> ITEM = new HandlerList<>(); public static final HandlerRegistry<BiConsumer<Item.Settings, Item>> ITEM = new HandlerList<>();
private ObjectBuilderEvent() { private ObjectBuilderEvent() {

View file

@ -16,7 +16,7 @@
package net.fabricmc.fabric.mixin.block; package net.fabricmc.fabric.mixin.block;
import net.fabricmc.fabric.block.FabricBlockBuilder; import net.fabricmc.fabric.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor; import net.minecraft.block.MaterialColor;
@ -25,8 +25,8 @@ import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(Block.Builder.class) @Mixin(Block.Settings.class)
public class MixinBlockBuilder implements FabricBlockBuilder.Delegate { public class MixinBlockBuilder implements FabricBlockSettings.Delegate {
@Shadow @Shadow
private Material material; private Material material;
@Shadow @Shadow

View file

@ -28,10 +28,10 @@ import java.util.function.BiConsumer;
@Mixin(Block.class) @Mixin(Block.class)
public class MixinBlock { public class MixinBlock {
@Inject(method = "<init>(Lnet/minecraft/block/Block$Builder;)V", at = @At("RETURN")) @Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
public void init(Block.Builder builder, CallbackInfo info) { public void init(Block.Settings builder, CallbackInfo info) {
for (Object o : ((HandlerList<BiConsumer<Block.Builder, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) { for (Object o : ((HandlerList<BiConsumer<Block.Settings, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) {
((BiConsumer<Block.Builder, Block>) o).accept(builder, (Block) (Object) this); ((BiConsumer<Block.Settings, Block>) o).accept(builder, (Block) (Object) this);
} }
} }
} }

View file

@ -28,10 +28,10 @@ import java.util.function.BiConsumer;
@Mixin(Item.class) @Mixin(Item.class)
public class MixinItem { public class MixinItem {
@Inject(method = "<init>(Lnet/minecraft/item/Item$Builder;)V", at = @At("RETURN")) @Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
public void init(Item.Builder builder, CallbackInfo info) { public void init(Item.Settings builder, CallbackInfo info) {
for (Object o : ((HandlerList<BiConsumer<Item.Builder, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) { for (Object o : ((HandlerList<BiConsumer<Item.Settings, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) {
((BiConsumer<Item.Builder, Item>) o).accept(builder, (Item) (Object) this); ((BiConsumer<Item.Settings, Item>) o).accept(builder, (Item) (Object) this);
} }
} }
} }

View file

@ -1,3 +1,19 @@
/*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.tags; package net.fabricmc.fabric.tags;
import net.minecraft.item.Item; import net.minecraft.item.Item;

View file

@ -1,3 +1,19 @@
/*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.tags; package net.fabricmc.fabric.tags;
import net.minecraft.block.Block; import net.minecraft.block.Block;

View file

@ -16,7 +16,7 @@
package net.fabricmc.fabric.tools; package net.fabricmc.fabric.tools;
import net.fabricmc.fabric.block.FabricBlockBuilder; import net.fabricmc.fabric.block.FabricBlockSettings;
import net.fabricmc.fabric.events.ObjectBuilderEvent; import net.fabricmc.fabric.events.ObjectBuilderEvent;
import net.fabricmc.fabric.util.TriState; import net.fabricmc.fabric.util.TriState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -31,7 +31,7 @@ import java.util.Map;
public final class ToolManager { public final class ToolManager {
public interface Entry { public interface Entry {
void breakByHand(boolean value); void setBreakByHand(boolean value);
void putBreakByTool(Tag<Item> tag, int miningLevel); void putBreakByTool(Tag<Item> tag, int miningLevel);
} }
@ -42,7 +42,7 @@ public final class ToolManager {
private TriState defaultValue = TriState.DEFAULT; private TriState defaultValue = TriState.DEFAULT;
@Override @Override
public void breakByHand(boolean value) { public void setBreakByHand(boolean value) {
this.defaultValue = TriState.of(value); this.defaultValue = TriState.of(value);
} }
@ -67,7 +67,7 @@ public final class ToolManager {
} }
} }
private static final Map<Block.Builder, EntryImpl> entriesPre = new HashMap<>(); private static final Map<Block.Settings, EntryImpl> entriesPre = new HashMap<>();
private static final Map<Block, EntryImpl> entries = new HashMap<>(); private static final Map<Block, EntryImpl> entries = new HashMap<>();
private ToolManager() { private ToolManager() {
@ -78,40 +78,50 @@ public final class ToolManager {
ObjectBuilderEvent.BLOCK.register(ToolManager::onBlockRegistered); ObjectBuilderEvent.BLOCK.register(ToolManager::onBlockRegistered);
} }
private static void onBlockRegistered(Block.Builder builder, Block block) { private static void onBlockRegistered(Block.Settings settings, Block block) {
EntryImpl entry = entriesPre.get(builder); EntryImpl entry = entriesPre.get(settings);
if (entry != null) { if (entry != null) {
entries.put(block, entry); entries.put(block, entry);
} }
} }
public static Entry get(Block.Builder builder) { /**
return entriesPre.computeIfAbsent(builder, (bb) -> new EntryImpl()); * Get the Entry for a given instance of Block.Settings.
*
* This method is meant to be used by Block.Settings wrappers, and it is
* recommended that you simply use the wrapper methods in
* {@link FabricBlockSettings} instead.
*
* @param settings
* @return
*/
public static Entry entry(Block.Settings settings) {
return entriesPre.computeIfAbsent(settings, (bb) -> new EntryImpl());
} }
private static Entry get(Block block) { private static Entry entry(Block block) {
return entries.computeIfAbsent(block, (bb) -> new EntryImpl()); return entries.computeIfAbsent(block, (bb) -> new EntryImpl());
} }
/** /**
* @deprecated Use {@link FabricBlockBuilder FabricBlockBuilder} for your own blocks. * @deprecated Use {@link FabricBlockSettings FabricBlockSettings} for your own blocks.
* TODO: Add a way to manipulate the values for non-owned blocks. * TODO: Add a way to manipulate the values for non-owned blocks.
*/ */
@Deprecated @Deprecated
public static void registerBreakByHand(Block block, boolean value) { public static void registerBreakByHand(Block block, boolean value) {
get(block).breakByHand(value); entry(block).setBreakByHand(value);
} }
/** /**
* @deprecated Use {@link FabricBlockBuilder FabricBlockBuilder} for your own blocks. * @deprecated Use {@link FabricBlockSettings FabricBlockSettings} for your own blocks.
* TODO: Add a way to manipulate the values for non-owned blocks. * TODO: Add a way to manipulate the values for non-owned blocks.
*/ */
@Deprecated @Deprecated
public static void registerBreakByTool(Block block, Tag<Item> tag, int miningLevel) { public static void registerBreakByTool(Block block, Tag<Item> tag, int miningLevel) {
get(block).putBreakByTool(tag, miningLevel); entry(block).putBreakByTool(tag, miningLevel);
} }
public static int getMiningLevel(ItemStack stack) { private static int getMiningLevel(ItemStack stack) {
if (stack.getItem() instanceof ToolItem) { if (stack.getItem() instanceof ToolItem) {
return ((ToolItem) stack.getItem()).getType().getMiningLevel(); return ((ToolItem) stack.getItem()).getType().getMiningLevel();
} else { } else {
@ -119,6 +129,9 @@ public final class ToolManager {
} }
} }
/**
* Hook for ItemStack.isEffectiveOn and similar methods.
*/
public static TriState handleIsEffectiveOn(ItemStack stack, BlockState state) { public static TriState handleIsEffectiveOn(ItemStack stack, BlockState state) {
EntryImpl entry = entries.get(state.getBlock()); EntryImpl entry = entries.get(state.getBlock());
if (entry != null) { if (entry != null) {