mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
fix license headers
This commit is contained in:
parent
897478bb9a
commit
0ca8947681
9 changed files with 117 additions and 72 deletions
10
build.gradle
10
build.gradle
|
@ -3,11 +3,11 @@ buildscript {
|
|||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'http://maven.modmuss50.me/'
|
||||
url = 'http://maven.fabricmc.net/'
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
archivesBaseName = "fabric"
|
||||
version = "0.1.0-SNAPSHOT"
|
||||
version = "0.1.0"
|
||||
|
||||
minecraft {
|
||||
refmapName = "net.fabricmc.fabric.refmap.json"
|
||||
|
@ -31,8 +31,8 @@ minecraft {
|
|||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:18w49a"
|
||||
mappings "net.fabricmc:pomf:18w49a.16"
|
||||
modCompile "net.fabricmc:fabric-loader:0.1.0.52"
|
||||
mappings "net.fabricmc:pomf:18w49a.19"
|
||||
modCompile "net.fabricmc:fabric-loader:0.2.0.53"
|
||||
}
|
||||
|
||||
apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle'
|
||||
|
|
|
@ -30,14 +30,14 @@ import net.minecraft.world.loot.LootTables;
|
|||
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.
|
||||
*
|
||||
* To use it, simply replace Block.Builder.create() with
|
||||
* FabricBlockBuilder.create() and add .build() at the end to return the
|
||||
* vanilla Block.Builder instance beneath.
|
||||
* To use it, simply replace Block.Settings.create() with
|
||||
* FabricBlockSettings.create() and add .build() at the end to return the
|
||||
* vanilla Block.Settings instance beneath.
|
||||
*/
|
||||
public class FabricBlockBuilder {
|
||||
public class FabricBlockSettings {
|
||||
public interface Delegate {
|
||||
void fabric_setMapColor(MaterialColor color);
|
||||
void fabric_setCollidable(boolean value);
|
||||
|
@ -50,51 +50,51 @@ public class FabricBlockBuilder {
|
|||
void fabric_setDropTable(Identifier id);
|
||||
}
|
||||
|
||||
protected final Block.Builder delegate;
|
||||
private final FabricBlockBuilder.Delegate castDelegate;
|
||||
protected final Block.Settings delegate;
|
||||
private final FabricBlockSettings.Delegate castDelegate;
|
||||
|
||||
protected FabricBlockBuilder(Material material) {
|
||||
delegate = Block.Builder.create(material);
|
||||
castDelegate = (FabricBlockBuilder.Delegate) delegate;
|
||||
protected FabricBlockSettings(Material material) {
|
||||
delegate = Block.Settings.create(material);
|
||||
castDelegate = (FabricBlockSettings.Delegate) delegate;
|
||||
}
|
||||
|
||||
protected FabricBlockBuilder(Block base) {
|
||||
delegate = Block.Builder.copy(base);
|
||||
castDelegate = (FabricBlockBuilder.Delegate) delegate;
|
||||
protected FabricBlockSettings(Block base) {
|
||||
delegate = Block.Settings.copy(base);
|
||||
castDelegate = (FabricBlockSettings.Delegate) delegate;
|
||||
}
|
||||
|
||||
public static FabricBlockBuilder create(Material material) {
|
||||
return new FabricBlockBuilder(material);
|
||||
public static FabricBlockSettings create(Material material) {
|
||||
return new FabricBlockSettings(material);
|
||||
}
|
||||
|
||||
public static FabricBlockBuilder copy(Block base) {
|
||||
return new FabricBlockBuilder(base);
|
||||
public static FabricBlockSettings copy(Block base) {
|
||||
return new FabricBlockSettings(base);
|
||||
}
|
||||
|
||||
/* FABRIC HELPERS */
|
||||
|
||||
public FabricBlockBuilder setBreakByHand(boolean value) {
|
||||
ToolManager.get(delegate).breakByHand(value);
|
||||
public FabricBlockSettings setBreakByHand(boolean value) {
|
||||
ToolManager.entry(delegate).setBreakByHand(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setBreakByTool(Tag<Item> tag) {
|
||||
public FabricBlockSettings setBreakByTool(Tag<Item> tag) {
|
||||
return setBreakByTool(tag, 0);
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setBreakByTool(Tag<Item> tag, int miningLevel) {
|
||||
ToolManager.get(delegate).putBreakByTool(tag, miningLevel);
|
||||
public FabricBlockSettings setBreakByTool(Tag<Item> tag, int miningLevel) {
|
||||
ToolManager.entry(delegate).putBreakByTool(tag, miningLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* DELEGATE WRAPPERS */
|
||||
|
||||
public FabricBlockBuilder setMaterialColor(MaterialColor color) {
|
||||
public FabricBlockSettings setMaterialColor(MaterialColor color) {
|
||||
castDelegate.fabric_setMapColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setMaterialColor(DyeColor color) {
|
||||
public FabricBlockSettings setMaterialColor(DyeColor color) {
|
||||
castDelegate.fabric_setMapColor(color.getMaterialColor());
|
||||
return this;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class FabricBlockBuilder {
|
|||
* @deprecated Use {@link #setMaterialColor(MaterialColor) setMaterialColor} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public FabricBlockBuilder setMapColor(MaterialColor color) {
|
||||
public FabricBlockSettings setMapColor(MaterialColor color) {
|
||||
return setMaterialColor(color);
|
||||
}
|
||||
|
||||
|
@ -111,74 +111,74 @@ public class FabricBlockBuilder {
|
|||
* @deprecated Use {@link #setMaterialColor(DyeColor) setMaterialColor} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public FabricBlockBuilder setMapColor(DyeColor color) {
|
||||
public FabricBlockSettings setMapColor(DyeColor color) {
|
||||
return setMaterialColor(color);
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setCollidable(boolean value) {
|
||||
public FabricBlockSettings setCollidable(boolean value) {
|
||||
castDelegate.fabric_setCollidable(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setSoundGroup(BlockSoundGroup group) {
|
||||
public FabricBlockSettings setSoundGroup(BlockSoundGroup group) {
|
||||
castDelegate.fabric_setSoundGroup(group);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder acceptRandomTicks() {
|
||||
public FabricBlockSettings acceptRandomTicks() {
|
||||
castDelegate.fabric_setRandomTicks(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setLuminance(int value) {
|
||||
public FabricBlockSettings setLuminance(int value) {
|
||||
castDelegate.fabric_setLuminance(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setHardness(float value) {
|
||||
public FabricBlockSettings setHardness(float value) {
|
||||
castDelegate.fabric_setHardness(value);
|
||||
castDelegate.fabric_setResistance(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setResistance(float value) {
|
||||
public FabricBlockSettings setResistance(float value) {
|
||||
castDelegate.fabric_setResistance(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setStrength(float hardness, float resistance) {
|
||||
public FabricBlockSettings setStrength(float hardness, float resistance) {
|
||||
castDelegate.fabric_setHardness(hardness);
|
||||
castDelegate.fabric_setResistance(resistance);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder noDropTable() {
|
||||
public FabricBlockSettings noDropTable() {
|
||||
castDelegate.fabric_setDropTable(LootTables.EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder copyDropTable(Block block) {
|
||||
public FabricBlockSettings copyDropTable(Block block) {
|
||||
castDelegate.fabric_setDropTable(block.getDropTableId());
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setDropTable(Identifier id) {
|
||||
public FabricBlockSettings setDropTable(Identifier id) {
|
||||
castDelegate.fabric_setDropTable(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockBuilder setFrictionCoefficient(float value) {
|
||||
public FabricBlockSettings setFrictionCoefficient(float value) {
|
||||
castDelegate.fabric_setFriction(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* BUILDING LOGIC */
|
||||
|
||||
public Block.Builder build() {
|
||||
public Block.Settings build() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public <T> T build(Function<Block.Builder, T> function) {
|
||||
public <T> T build(Function<Block.Settings, T> function) {
|
||||
return function.apply(delegate);
|
||||
}
|
||||
}
|
|
@ -24,13 +24,13 @@ import net.minecraft.item.Item;
|
|||
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
|
||||
* your own methods and transparently add the resulting information to a Map.
|
||||
*/
|
||||
public final class ObjectBuilderEvent {
|
||||
public static final HandlerRegistry<BiConsumer<Block.Builder, Block>> BLOCK = new HandlerList<>();
|
||||
public static final HandlerRegistry<BiConsumer<Item.Builder, Item>> ITEM = new HandlerList<>();
|
||||
public static final HandlerRegistry<BiConsumer<Block.Settings, Block>> BLOCK = new HandlerList<>();
|
||||
public static final HandlerRegistry<BiConsumer<Item.Settings, Item>> ITEM = new HandlerList<>();
|
||||
|
||||
private ObjectBuilderEvent() {
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
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.Material;
|
||||
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.Shadow;
|
||||
|
||||
@Mixin(Block.Builder.class)
|
||||
public class MixinBlockBuilder implements FabricBlockBuilder.Delegate {
|
||||
@Mixin(Block.Settings.class)
|
||||
public class MixinBlockBuilder implements FabricBlockSettings.Delegate {
|
||||
@Shadow
|
||||
private Material material;
|
||||
@Shadow
|
||||
|
|
|
@ -28,10 +28,10 @@ import java.util.function.BiConsumer;
|
|||
|
||||
@Mixin(Block.class)
|
||||
public class MixinBlock {
|
||||
@Inject(method = "<init>(Lnet/minecraft/block/Block$Builder;)V", at = @At("RETURN"))
|
||||
public void init(Block.Builder builder, CallbackInfo info) {
|
||||
for (Object o : ((HandlerList<BiConsumer<Block.Builder, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) {
|
||||
((BiConsumer<Block.Builder, Block>) o).accept(builder, (Block) (Object) this);
|
||||
@Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
|
||||
public void init(Block.Settings builder, CallbackInfo info) {
|
||||
for (Object o : ((HandlerList<BiConsumer<Block.Settings, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) {
|
||||
((BiConsumer<Block.Settings, Block>) o).accept(builder, (Block) (Object) this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ import java.util.function.BiConsumer;
|
|||
|
||||
@Mixin(Item.class)
|
||||
public class MixinItem {
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item$Builder;)V", at = @At("RETURN"))
|
||||
public void init(Item.Builder builder, CallbackInfo info) {
|
||||
for (Object o : ((HandlerList<BiConsumer<Item.Builder, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) {
|
||||
((BiConsumer<Item.Builder, Item>) o).accept(builder, (Item) (Object) this);
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
|
||||
public void init(Item.Settings builder, CallbackInfo info) {
|
||||
for (Object o : ((HandlerList<BiConsumer<Item.Settings, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) {
|
||||
((BiConsumer<Item.Settings, Item>) o).accept(builder, (Item) (Object) this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
|
|
@ -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;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
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.util.TriState;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -31,7 +31,7 @@ import java.util.Map;
|
|||
|
||||
public final class ToolManager {
|
||||
public interface Entry {
|
||||
void breakByHand(boolean value);
|
||||
void setBreakByHand(boolean value);
|
||||
void putBreakByTool(Tag<Item> tag, int miningLevel);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public final class ToolManager {
|
|||
private TriState defaultValue = TriState.DEFAULT;
|
||||
|
||||
@Override
|
||||
public void breakByHand(boolean value) {
|
||||
public void setBreakByHand(boolean 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 ToolManager() {
|
||||
|
@ -78,40 +78,50 @@ public final class ToolManager {
|
|||
ObjectBuilderEvent.BLOCK.register(ToolManager::onBlockRegistered);
|
||||
}
|
||||
|
||||
private static void onBlockRegistered(Block.Builder builder, Block block) {
|
||||
EntryImpl entry = entriesPre.get(builder);
|
||||
private static void onBlockRegistered(Block.Settings settings, Block block) {
|
||||
EntryImpl entry = entriesPre.get(settings);
|
||||
if (entry != null) {
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
@Deprecated
|
||||
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.
|
||||
*/
|
||||
@Deprecated
|
||||
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) {
|
||||
return ((ToolItem) stack.getItem()).getType().getMiningLevel();
|
||||
} else {
|
||||
|
@ -119,6 +129,9 @@ public final class ToolManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for ItemStack.isEffectiveOn and similar methods.
|
||||
*/
|
||||
public static TriState handleIsEffectiveOn(ItemStack stack, BlockState state) {
|
||||
EntryImpl entry = entries.get(state.getBlock());
|
||||
if (entry != null) {
|
||||
|
|
Loading…
Reference in a new issue