mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Object builders v0->v1 migration (#537)
* Migrate object builders from v0 -> v1 * Port entity attribute registry to v1
This commit is contained in:
parent
610157e1cf
commit
c38e8d9e1e
33 changed files with 1051 additions and 216 deletions
11
fabric-object-builder-api-v1/build.gradle
Normal file
11
fabric-object-builder-api-v1/build.gradle
Normal file
|
@ -0,0 +1,11 @@
|
|||
archivesBaseName = "fabric-object-builder-api-v1"
|
||||
version = getSubprojectVersion(project, "1.0.0")
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
compile project(path: ':fabric-tool-attribute-api-v1', configuration: 'dev')
|
||||
}
|
||||
|
||||
minecraft {
|
||||
accessWidener = file("src/main/resources/fabric-object-builder-api-v1.accesswidener")
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.api.object.builder.v1.block;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.impl.object.builder.BlockSettingsInternals;
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
|
||||
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor;
|
||||
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor;
|
||||
|
||||
/**
|
||||
* Fabric's version of Block.Settings. Adds additional methods and hooks
|
||||
* not found in the original class.
|
||||
*
|
||||
* <p>To use it, simply replace Block.Settings.of() with
|
||||
* FabricBlockSettings.of().
|
||||
*/
|
||||
public class FabricBlockSettings extends AbstractBlock.Settings {
|
||||
protected FabricBlockSettings(Material material, MaterialColor color) {
|
||||
super(material, color);
|
||||
}
|
||||
|
||||
protected FabricBlockSettings(AbstractBlock.Settings settings) {
|
||||
super(((AbstractBlockSettingsAccessor) settings).getMaterial(), ((AbstractBlockSettingsAccessor) settings).getMaterialColorFactory());
|
||||
// Mostly Copied from vanilla's copy method
|
||||
AbstractBlockSettingsAccessor thisAccessor = (AbstractBlockSettingsAccessor) this;
|
||||
AbstractBlockSettingsAccessor otherAccessor = (AbstractBlockSettingsAccessor) settings;
|
||||
|
||||
thisAccessor.setMaterial(otherAccessor.getMaterial());
|
||||
this.hardness(otherAccessor.getHardness());
|
||||
this.resistance(otherAccessor.getResistance());
|
||||
this.collidable(otherAccessor.getCollidable());
|
||||
thisAccessor.setRandomTicks(otherAccessor.getRandomTicks());
|
||||
this.lightLevel(otherAccessor.getLuminance());
|
||||
thisAccessor.setMaterialColorFactory(otherAccessor.getMaterialColorFactory());
|
||||
this.sounds(otherAccessor.getSoundGroup());
|
||||
this.slipperiness(otherAccessor.getSlipperiness());
|
||||
this.velocityMultiplier(otherAccessor.getVelocityMultiplier());
|
||||
thisAccessor.setDynamicBounds(otherAccessor.getDynamicBounds());
|
||||
thisAccessor.setOpaque(otherAccessor.getOpaque());
|
||||
thisAccessor.setIsAir(otherAccessor.getIsAir());
|
||||
|
||||
// Now attempt to copy fabric specific data
|
||||
BlockSettingsInternals otherInternals = (BlockSettingsInternals) settings;
|
||||
FabricBlockInternals.ExtraData extraData = otherInternals.getExtraData();
|
||||
|
||||
if (extraData != null) { // If present, populate the extra data on our new settings
|
||||
((BlockSettingsInternals) this).setExtraData(extraData);
|
||||
}
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of(Material material) {
|
||||
return of(material, material.getColor());
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of(Material material, MaterialColor color) {
|
||||
return new FabricBlockSettings(material, color);
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of(Material material, DyeColor color) {
|
||||
return new FabricBlockSettings(material, color.getMaterialColor());
|
||||
}
|
||||
|
||||
public static FabricBlockSettings copyOf(AbstractBlock block) {
|
||||
return new FabricBlockSettings(((AbstractBlockAccessor) block).getSettings());
|
||||
}
|
||||
|
||||
public static FabricBlockSettings copyOf(AbstractBlock.Settings settings) {
|
||||
return new FabricBlockSettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings noCollision() {
|
||||
super.noCollision();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings nonOpaque() {
|
||||
super.nonOpaque();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings slipperiness(float value) {
|
||||
super.slipperiness(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings velocityMultiplier(float velocityMultiplier) {
|
||||
super.velocityMultiplier(velocityMultiplier);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) {
|
||||
super.jumpVelocityMultiplier(jumpVelocityMultiplier);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings sounds(BlockSoundGroup group) {
|
||||
super.sounds(group);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings lightLevel(ToIntFunction<BlockState> levelFunction) {
|
||||
super.lightLevel(levelFunction);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings strength(float hardness, float resistance) {
|
||||
super.strength(hardness, resistance);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings breakInstantly() {
|
||||
super.breakInstantly();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings strength(float strength) {
|
||||
super.strength(strength);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings ticksRandomly() {
|
||||
super.ticksRandomly();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings dynamicBounds() {
|
||||
super.dynamicBounds();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings dropsNothing() {
|
||||
super.dropsNothing();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings dropsLike(Block block) {
|
||||
super.dropsLike(block);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings air() {
|
||||
super.air();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate<EntityType<?>> predicate) {
|
||||
super.allowsSpawning(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) {
|
||||
super.solidBlock(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) {
|
||||
super.suffocates(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) {
|
||||
super.blockVision(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) {
|
||||
super.postProcess(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) {
|
||||
super.emissiveLighting(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC ADDITIONS*/
|
||||
|
||||
public FabricBlockSettings lightLevel(int lightLevel) {
|
||||
this.lightLevel(ignored -> lightLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings hardness(float hardness) {
|
||||
((AbstractBlockSettingsAccessor) this).setHardness(hardness);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings resistance(float resistance) {
|
||||
((AbstractBlockSettingsAccessor) this).setResistance(Math.max(0.0F, resistance));
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings drops(Identifier dropTableId) {
|
||||
((AbstractBlockSettingsAccessor) this).setLootTableId(dropTableId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC DELEGATE WRAPPERS */
|
||||
|
||||
public FabricBlockSettings materialColor(MaterialColor color) {
|
||||
((AbstractBlockSettingsAccessor) this).setMaterialColorFactory(ignored -> color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings materialColor(DyeColor color) {
|
||||
return this.materialColor(color.getMaterialColor());
|
||||
}
|
||||
|
||||
public FabricBlockSettings collidable(boolean collidable) {
|
||||
((AbstractBlockSettingsAccessor) this).setCollidable(collidable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC HELPERS */
|
||||
|
||||
public FabricBlockSettings breakByHand(boolean breakByHand) {
|
||||
FabricBlockInternals.computeExtraData(this).breakByHand(breakByHand);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings breakByTool(Tag<Item> tag, int miningLevel) {
|
||||
FabricBlockInternals.computeExtraData(this).addMiningLevel(tag, miningLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings breakByTool(Tag<Item> tag) {
|
||||
return this.breakByTool(tag, 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.api.object.builder.v1.block;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.util.DyeColor;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.MaterialBuilderAccessor;
|
||||
|
||||
public class FabricMaterialBuilder extends Material.Builder {
|
||||
public FabricMaterialBuilder(MaterialColor color) {
|
||||
super(color);
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder(DyeColor color) {
|
||||
this(color.getMaterialColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder burnable() {
|
||||
super.burnable();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder pistonBehavior(PistonBehavior behavior) {
|
||||
((MaterialBuilderAccessor) this).setPistonBehavior(behavior);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder lightPassesThrough() {
|
||||
((MaterialBuilderAccessor) this).invokeLightPassesThrough();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder destroyedByPiston() {
|
||||
super.destroyedByPiston();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder blocksPistons() {
|
||||
super.blocksPistons();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder allowsMovement() {
|
||||
super.allowsMovement();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder liquid() {
|
||||
super.liquid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material.Builder notSolid() {
|
||||
super.notSolid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder replaceable() {
|
||||
super.replaceable();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder requiresTool() {
|
||||
super.requiresTool();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.api.object.builder.v1.entity;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.DefaultAttributeRegistryAccessor;
|
||||
|
||||
/**
|
||||
* Allows registering custom default attributes for living entities.
|
||||
*
|
||||
* <p>All living entity types must have default attributes registered. See {@link
|
||||
* FabricEntityTypeBuilder} for utility on entity type registration in general.</p>
|
||||
*
|
||||
* <p>A registered default attribute for an entity type can be retrieved through
|
||||
* {@link net.minecraft.entity.attribute.DefaultAttributeRegistry#get(EntityType)}.</p>
|
||||
*
|
||||
* @see net.minecraft.entity.attribute.DefaultAttributeRegistry
|
||||
* @deprecated Experimental feature, may be removed or changed without further notice.
|
||||
* Vanilla snapshot feature, subject to vanilla change.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class FabricDefaultAttributeRegistry {
|
||||
/**
|
||||
* Private logger, not exposed.
|
||||
*/
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Registers a default attribute for a type of living entity.
|
||||
*
|
||||
* <p>It can be used in a fashion similar to this:
|
||||
* <blockquote><pre>
|
||||
* EntityAttributeRegistry.INSTANCE.register(type, LivingEntity.createLivingAttributes());
|
||||
* </pre></blockquote>
|
||||
* </p>
|
||||
*
|
||||
* <p>If a registration overrides another, a debug log message will be emitted. Existing registrations
|
||||
* can be checked at {@link net.minecraft.entity.attribute.DefaultAttributeRegistry#hasDefinitionFor(EntityType)}.</p>
|
||||
*
|
||||
* @param type the entity type
|
||||
* @param builder the builder that creates the default attribute
|
||||
*/
|
||||
public static void register(EntityType<? extends LivingEntity> type, DefaultAttributeContainer.Builder builder) {
|
||||
if (DefaultAttributeRegistryAccessor.getRegistry().put(type, builder.build()) != null) {
|
||||
LOGGER.debug("Overriding existing registration for entity type {}", Registry.ENTITY_TYPE.getId(type));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.api.object.builder.v1.entity;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityType;
|
||||
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricEntityType;
|
||||
|
||||
/**
|
||||
* Extended version of {@link EntityType.Builder} with added registration for
|
||||
* server->client entity tracking values.
|
||||
*
|
||||
* @param <T> Entity class.
|
||||
*/
|
||||
public class FabricEntityTypeBuilder<T extends Entity> {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private final EntityCategory category;
|
||||
private final EntityType.EntityFactory<T> function;
|
||||
private boolean saveable = true;
|
||||
private boolean summonable = true;
|
||||
private int trackingDistance = 5;
|
||||
private int updateIntervalTicks = 3;
|
||||
private Boolean alwaysUpdateVelocity;
|
||||
private boolean fireImmune = false;
|
||||
private boolean spawnableFarFromPlayer;
|
||||
private int maxDespawnDistance = 128;
|
||||
private int minDespawnDistance = 32;
|
||||
private EntityDimensions dimensions = EntityDimensions.changing(-1.0f, -1.0f);
|
||||
|
||||
protected FabricEntityTypeBuilder(EntityCategory category, EntityType.EntityFactory<T> function) {
|
||||
this.category = category;
|
||||
this.function = function;
|
||||
this.spawnableFarFromPlayer = category == EntityCategory.CREATURE || category == EntityCategory.MISC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an entity type builder.
|
||||
*
|
||||
* @param category the entity category
|
||||
* @param <T> the type of entity
|
||||
*
|
||||
* @return a new entity type builder
|
||||
*/
|
||||
public static <T extends Entity> FabricEntityTypeBuilder<T> create(EntityCategory category) {
|
||||
return new FabricEntityTypeBuilder<>(category, (t, w) -> null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an entity type builder.
|
||||
*
|
||||
* @param category the entity category
|
||||
* @param function the entity function used to create this entity
|
||||
* @param <T> the type of entity
|
||||
*
|
||||
* @return a new entity type builder
|
||||
*/
|
||||
public static <T extends Entity> FabricEntityTypeBuilder<T> create(EntityCategory category, EntityType.EntityFactory<T> function) {
|
||||
return new FabricEntityTypeBuilder<>(category, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this entity type is summonable using the {@code /summon} command.
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> disableSummon() {
|
||||
this.summonable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> disableSaving() {
|
||||
this.saveable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this entity type to be fire immune.
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> fireImmune() {
|
||||
this.fireImmune = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this entity type can be spawned far away from a player.
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> spawnableFarFromPlayer() {
|
||||
this.spawnableFarFromPlayer = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dimensions of this entity type.
|
||||
*
|
||||
* @param dimensions the dimensions representing the entity's size
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> dimensions(EntityDimensions dimensions) {
|
||||
this.dimensions = dimensions;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum distance entities of this type can be from a player to possibly despawn.
|
||||
*
|
||||
* @param maxDespawnDistance the distance
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> maxDespawnDistance(int maxDespawnDistance) {
|
||||
this.maxDespawnDistance = maxDespawnDistance;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum distance entities of this type can be from a player to possibly despawn.
|
||||
*
|
||||
* @param minDespawnDistance the distance
|
||||
*
|
||||
* @return this builder for chaining
|
||||
*/
|
||||
public FabricEntityTypeBuilder<T> minDespawnDistance(int minDespawnDistance) {
|
||||
this.minDespawnDistance = minDespawnDistance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) {
|
||||
return trackable(trackingDistanceBlocks, updateIntervalTicks, true);
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
|
||||
this.trackingDistance = trackingDistanceBlocks;
|
||||
this.updateIntervalTicks = updateIntervalTicks;
|
||||
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the entity type.
|
||||
*
|
||||
* @return a new {@link EntityType}
|
||||
*/
|
||||
public EntityType<T> build() {
|
||||
if (this.saveable) {
|
||||
// SNIP! Modded datafixers are not supported anyway.
|
||||
// TODO: Flesh out once modded datafixers exist.
|
||||
}
|
||||
|
||||
EntityType<T> type = new FabricEntityType<T>(this.function, this.category, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.maxDespawnDistance, this.minDespawnDistance, dimensions, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity);
|
||||
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.impl.object.builder;
|
||||
|
||||
public interface BlockSettingsInternals {
|
||||
FabricBlockInternals.ExtraData getExtraData();
|
||||
|
||||
void setExtraData(FabricBlockInternals.ExtraData extraData);
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.impl.object.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tag.Tag;
|
||||
|
||||
import net.fabricmc.fabric.impl.tool.attribute.ToolManager;
|
||||
|
||||
public final class FabricBlockInternals {
|
||||
private FabricBlockInternals() {
|
||||
}
|
||||
|
||||
public static ExtraData computeExtraData(Block.Settings settings) {
|
||||
BlockSettingsInternals internals = (BlockSettingsInternals) settings;
|
||||
|
||||
if (internals.getExtraData() == null) {
|
||||
internals.setExtraData(new ExtraData(settings));
|
||||
}
|
||||
|
||||
return internals.getExtraData();
|
||||
}
|
||||
|
||||
public static void onBuild(Block.Settings settings, Block block) {
|
||||
// TODO: Load only if fabric-tool-attribute-api present
|
||||
ExtraData data = ((BlockSettingsInternals) settings).getExtraData();
|
||||
|
||||
if (data != null) {
|
||||
if (data.breakByHand != null) {
|
||||
ToolManager.entry(block).setBreakByHand(data.breakByHand);
|
||||
}
|
||||
|
||||
for (MiningLevel tml : data.miningLevels) {
|
||||
ToolManager.entry(block).putBreakByTool(tml.tag, tml.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ExtraData {
|
||||
private final List<MiningLevel> miningLevels = new ArrayList<>();
|
||||
/* @Nullable */ private Boolean breakByHand;
|
||||
|
||||
public ExtraData(Block.Settings settings) {
|
||||
}
|
||||
|
||||
public void breakByHand(boolean breakByHand) {
|
||||
this.breakByHand = breakByHand;
|
||||
}
|
||||
|
||||
public void addMiningLevel(Tag<Item> tag, int level) {
|
||||
miningLevels.add(new MiningLevel(tag, level));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class MiningLevel {
|
||||
private final Tag<Item> tag;
|
||||
private final int level;
|
||||
|
||||
MiningLevel(Tag<Item> tag, int level) {
|
||||
this.tag = tag;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.mixin.object.builder;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
|
||||
@Mixin(AbstractBlock.class)
|
||||
public interface AbstractBlockAccessor {
|
||||
@Accessor
|
||||
AbstractBlock.Settings getSettings();
|
||||
}
|
|
@ -26,12 +26,57 @@ import org.spongepowered.asm.mixin.gen.Invoker;
|
|||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(AbstractBlock.Settings.class)
|
||||
public interface BlockSettingsHooks {
|
||||
public interface AbstractBlockSettingsAccessor {
|
||||
/* GETTERS */
|
||||
@Accessor
|
||||
Material getMaterial();
|
||||
|
||||
@Accessor
|
||||
float getHardness();
|
||||
|
||||
@Accessor
|
||||
float getResistance();
|
||||
|
||||
@Accessor
|
||||
boolean getCollidable();
|
||||
|
||||
@Accessor
|
||||
boolean getRandomTicks();
|
||||
|
||||
@Accessor
|
||||
ToIntFunction<BlockState> getLuminance();
|
||||
|
||||
@Accessor
|
||||
Function<BlockState, MaterialColor> getMaterialColorFactory();
|
||||
|
||||
@Accessor
|
||||
BlockSoundGroup getSoundGroup();
|
||||
|
||||
@Accessor
|
||||
float getSlipperiness();
|
||||
|
||||
@Accessor
|
||||
float getVelocityMultiplier();
|
||||
|
||||
@Accessor
|
||||
boolean getDynamicBounds();
|
||||
|
||||
@Accessor
|
||||
boolean getOpaque();
|
||||
|
||||
@Accessor
|
||||
boolean getIsAir();
|
||||
|
||||
/* SETTERS */
|
||||
@Accessor
|
||||
void setMaterial(Material material);
|
||||
|
||||
@Accessor
|
||||
void setHardness(float hardness);
|
||||
|
||||
|
@ -41,11 +86,24 @@ public interface BlockSettingsHooks {
|
|||
@Accessor
|
||||
void setCollidable(boolean collidable);
|
||||
|
||||
@Accessor
|
||||
void setRandomTicks(boolean ticksRandomly);
|
||||
|
||||
@Accessor
|
||||
void setMaterialColorFactory(Function<BlockState, MaterialColor> materialColorFunction);
|
||||
|
||||
@Accessor
|
||||
void setLootTableId(Identifier dropTableId);
|
||||
void setDynamicBounds(boolean dynamicBounds);
|
||||
|
||||
@Accessor
|
||||
void setOpaque(boolean opaque);
|
||||
|
||||
@Accessor
|
||||
void setIsAir(boolean isAir);
|
||||
|
||||
@Accessor
|
||||
void setLootTableId(Identifier lootTableId);
|
||||
/* INVOKERS */
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeSounds(BlockSoundGroup group);
|
||||
|
@ -62,9 +120,6 @@ public interface BlockSettingsHooks {
|
|||
@Invoker
|
||||
Block.Settings invokeTicksRandomly();
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeDynamicBounds();
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeDropsNothing();
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.mixin.object.builder;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
|
||||
import net.fabricmc.fabric.impl.object.builder.BlockSettingsInternals;
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
|
||||
|
||||
@Mixin(AbstractBlock.Settings.class)
|
||||
public abstract class AbstractBlockSettingsMixin implements BlockSettingsInternals {
|
||||
@Unique
|
||||
private FabricBlockInternals.ExtraData fabricExtraData;
|
||||
|
||||
@Override
|
||||
public FabricBlockInternals.ExtraData getExtraData() {
|
||||
return this.fabricExtraData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraData(FabricBlockInternals.ExtraData extraData) {
|
||||
this.fabricExtraData = extraData;
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import net.minecraft.block.Material;
|
|||
import net.minecraft.block.piston.PistonBehavior;
|
||||
|
||||
@Mixin(Material.Builder.class)
|
||||
public interface MaterialBuilderHooks {
|
||||
public interface MaterialBuilderAccessor {
|
||||
@Accessor
|
||||
void setPistonBehavior(PistonBehavior behavior);
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 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.mixin.object.builder;
|
||||
|
||||
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.CallbackInfo;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public abstract class MixinBlock {
|
||||
@Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
|
||||
public void fabric_init(Block.Settings builder, CallbackInfo info) {
|
||||
FabricBlockInternals.onBuild(builder, (Block) (Object) this);
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,3 @@
|
|||
accessWidener v1 named
|
||||
extendable method net/minecraft/block/AbstractBlock$Settings <init> (Lnet/minecraft/block/Material;Ljava/util/function/Function;)V
|
||||
extendable method net/minecraft/block/AbstractBlock$Settings <init> (Lnet/minecraft/block/Material;Lnet/minecraft/block/MaterialColor;)V
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "net.fabricmc.fabric.mixin.object.builder",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"AbstractBlockAccessor",
|
||||
"AbstractBlockSettingsAccessor",
|
||||
"AbstractBlockSettingsMixin",
|
||||
"DefaultAttributeRegistryAccessor",
|
||||
"DefaultAttributeRegistryMixin",
|
||||
"MaterialBuilderAccessor",
|
||||
"MixinBlock"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "fabric-object-builder-api-v1",
|
||||
"name": "Fabric Object Builder API (v1)",
|
||||
"version": "${version}",
|
||||
"environment": "*",
|
||||
"license": "Apache-2.0",
|
||||
"icon": "assets/fabric-object-builder-api-v1/icon.png",
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net",
|
||||
"irc": "irc://irc.esper.net:6667/fabric",
|
||||
"issues": "https://github.com/FabricMC/fabric/issues",
|
||||
"sources": "https://github.com/FabricMC/fabric"
|
||||
},
|
||||
"authors": [
|
||||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.8.2",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-tool-attribute-api-v1": "*"
|
||||
},
|
||||
"description": "Builders for objects vanilla has locked down.",
|
||||
"mixins": [
|
||||
"fabric-object-builder-v1.mixins.json"
|
||||
],
|
||||
"accessWidener" : "fabric-object-builder-api-v1.accesswidener"
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
archivesBaseName = "fabric-object-builders"
|
||||
version = getSubprojectVersion(project, "0.4.0")
|
||||
version = getSubprojectVersion(project, "0.5.0")
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
compile project(path: ':fabric-tool-attribute-api-v1', configuration: 'dev')
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
compile project(path: ':fabric-object-builder-api-v1', configuration: 'dev')
|
||||
}
|
||||
|
|
|
@ -23,65 +23,71 @@ import net.minecraft.sound.BlockSoundGroup;
|
|||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.BlockSettingsHooks;
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
|
||||
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor;
|
||||
|
||||
/**
|
||||
* @deprecated Please migrate to v1. Please use methods in {@link net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class BlockSettingsExtensions {
|
||||
private BlockSettingsExtensions() {
|
||||
}
|
||||
|
||||
public static void breakByHand(Settings settings, boolean breakByHand) {
|
||||
FabricBlockSettings.computeExtraData(settings).breakByHand(breakByHand);
|
||||
FabricBlockInternals.computeExtraData(settings).breakByHand(breakByHand);
|
||||
}
|
||||
|
||||
public static void breakByTool(Settings settings, Tag<Item> tag, int miningLevel) {
|
||||
FabricBlockSettings.computeExtraData(settings).addMiningLevel(tag, miningLevel);
|
||||
FabricBlockInternals.computeExtraData(settings).addMiningLevel(tag, miningLevel);
|
||||
}
|
||||
|
||||
public static void hardness(Settings settings, float hardness) {
|
||||
((BlockSettingsHooks) settings).setHardness(hardness);
|
||||
((AbstractBlockSettingsAccessor) settings).setHardness(hardness);
|
||||
}
|
||||
|
||||
public static void resistance(Settings settings, float resistance) {
|
||||
((BlockSettingsHooks) settings).setResistance(Math.max(0.0F, resistance));
|
||||
((AbstractBlockSettingsAccessor) settings).setResistance(Math.max(0.0F, resistance));
|
||||
}
|
||||
|
||||
public static void collidable(Settings settings, boolean collidable) {
|
||||
((BlockSettingsHooks) settings).setCollidable(collidable);
|
||||
((AbstractBlockSettingsAccessor) settings).setCollidable(collidable);
|
||||
}
|
||||
|
||||
public static void materialColor(Settings settings, MaterialColor materialColor) {
|
||||
((BlockSettingsHooks) settings).setMaterialColorFactory(blockState -> materialColor);
|
||||
((AbstractBlockSettingsAccessor) settings).setMaterialColorFactory(ignored -> materialColor);
|
||||
}
|
||||
|
||||
public static void drops(Settings settings, Identifier dropTableId) {
|
||||
((BlockSettingsHooks) settings).setLootTableId(dropTableId);
|
||||
((AbstractBlockSettingsAccessor) settings).setLootTableId(dropTableId);
|
||||
}
|
||||
|
||||
public static void sounds(Settings settings, BlockSoundGroup soundGroup) {
|
||||
((BlockSettingsHooks) settings).invokeSounds(soundGroup);
|
||||
((AbstractBlockSettingsAccessor) settings).invokeSounds(soundGroup);
|
||||
}
|
||||
|
||||
public static void lightLevel(Settings settings, int lightLevel) {
|
||||
((BlockSettingsHooks) settings).invokeLightLevel(value -> lightLevel);
|
||||
((AbstractBlockSettingsAccessor) settings).invokeLightLevel(ignored -> lightLevel);
|
||||
}
|
||||
|
||||
public static void breakInstantly(Settings settings) {
|
||||
((BlockSettingsHooks) settings).invokeBreakInstantly();
|
||||
((AbstractBlockSettingsAccessor) settings).invokeBreakInstantly();
|
||||
}
|
||||
|
||||
public static void strength(Settings settings, float strength) {
|
||||
((BlockSettingsHooks) settings).invokeStrength(strength);
|
||||
((AbstractBlockSettingsAccessor) settings).invokeStrength(strength);
|
||||
}
|
||||
|
||||
public static void ticksRandomly(Settings settings) {
|
||||
((BlockSettingsHooks) settings).invokeTicksRandomly();
|
||||
((AbstractBlockSettingsAccessor) settings).invokeTicksRandomly();
|
||||
}
|
||||
|
||||
public static void dynamicBounds(Settings settings) {
|
||||
((BlockSettingsHooks) settings).invokeDynamicBounds();
|
||||
// Thanks Mixin
|
||||
((AbstractBlockSettingsAccessor) settings).setDynamicBounds(true);
|
||||
}
|
||||
|
||||
public static void dropsNothing(Settings settings) {
|
||||
((BlockSettingsHooks) settings).invokeDropsNothing();
|
||||
((AbstractBlockSettingsAccessor) settings).invokeDropsNothing();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
|
||||
package net.fabricmc.fabric.api.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -31,70 +27,12 @@ import net.minecraft.tag.Tag;
|
|||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.fabric.api.event.registry.BlockConstructedCallback;
|
||||
import net.fabricmc.fabric.impl.tool.attribute.ToolManager;
|
||||
|
||||
/**
|
||||
* Fabric's version of Block.Settings. Adds additional methods and hooks
|
||||
* not found in the original class.
|
||||
*
|
||||
* <p>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.
|
||||
* @deprecated Please migrate to v1. Please use {@link net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class FabricBlockSettings {
|
||||
static {
|
||||
BlockConstructedCallback.EVENT.register(FabricBlockSettings::onBuild);
|
||||
}
|
||||
|
||||
private static final Map<Block.Settings, ExtraData> EXTRA_DATA = new HashMap<>();
|
||||
|
||||
protected final Block.Settings delegate;
|
||||
|
||||
static final class ExtraData {
|
||||
private final List<MiningLevel> miningLevels = new ArrayList<>();
|
||||
/* @Nullable */ private Boolean breakByHand;
|
||||
|
||||
private ExtraData(Block.Settings settings) {
|
||||
}
|
||||
|
||||
void breakByHand(boolean breakByHand) {
|
||||
this.breakByHand = breakByHand;
|
||||
}
|
||||
|
||||
void addMiningLevel(Tag<Item> tag, int level) {
|
||||
miningLevels.add(new MiningLevel(tag, level));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MiningLevel {
|
||||
private final Tag<Item> tag;
|
||||
private final int level;
|
||||
|
||||
MiningLevel(Tag<Item> tag, int level) {
|
||||
this.tag = tag;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
||||
static ExtraData computeExtraData(Block.Settings settings) {
|
||||
return EXTRA_DATA.computeIfAbsent(settings, ExtraData::new);
|
||||
}
|
||||
|
||||
private static void onBuild(Block.Settings settings, Block block) {
|
||||
// TODO: Load only if fabric-mining-levels present
|
||||
ExtraData data = EXTRA_DATA.get(settings);
|
||||
|
||||
if (data != null) {
|
||||
if (data.breakByHand != null) {
|
||||
ToolManager.entry(block).setBreakByHand(data.breakByHand);
|
||||
}
|
||||
|
||||
for (MiningLevel tml : data.miningLevels) {
|
||||
ToolManager.entry(block).putBreakByTool(tml.tag, tml.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected final net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings delegate;
|
||||
|
||||
protected FabricBlockSettings(Material material, MaterialColor color) {
|
||||
this(Block.Settings.of(material, color));
|
||||
|
@ -105,7 +43,7 @@ public class FabricBlockSettings {
|
|||
}
|
||||
|
||||
protected FabricBlockSettings(final Block.Settings delegate) {
|
||||
this.delegate = delegate;
|
||||
this.delegate = net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings.copyOf(delegate);
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of(Material material) {
|
||||
|
@ -131,118 +69,120 @@ public class FabricBlockSettings {
|
|||
/* FABRIC HELPERS */
|
||||
|
||||
public FabricBlockSettings breakByHand(boolean breakByHand) {
|
||||
computeExtraData(delegate).breakByHand(breakByHand);
|
||||
this.delegate.breakByHand(breakByHand);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings breakByTool(Tag<Item> tag, int miningLevel) {
|
||||
computeExtraData(delegate).addMiningLevel(tag, miningLevel);
|
||||
this.delegate.breakByTool(tag, miningLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings breakByTool(Tag<Item> tag) {
|
||||
return breakByTool(tag, 0);
|
||||
this.delegate.breakByTool(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* DELEGATE WRAPPERS */
|
||||
|
||||
public FabricBlockSettings materialColor(MaterialColor color) {
|
||||
BlockSettingsExtensions.materialColor(delegate, color);
|
||||
this.delegate.materialColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings materialColor(DyeColor color) {
|
||||
return materialColor(color.getMaterialColor());
|
||||
this.delegate.materialColor(color.getMaterialColor());
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings collidable(boolean collidable) {
|
||||
BlockSettingsExtensions.collidable(delegate, collidable);
|
||||
this.delegate.collidable(collidable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings noCollision() {
|
||||
delegate.noCollision();
|
||||
this.delegate.noCollision();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings nonOpaque() {
|
||||
delegate.nonOpaque();
|
||||
this.delegate.nonOpaque();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings sounds(BlockSoundGroup group) {
|
||||
BlockSettingsExtensions.sounds(delegate, group);
|
||||
this.delegate.sounds(group);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings ticksRandomly() {
|
||||
BlockSettingsExtensions.ticksRandomly(delegate);
|
||||
this.delegate.ticksRandomly();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings lightLevel(int lightLevel) {
|
||||
BlockSettingsExtensions.lightLevel(delegate, lightLevel);
|
||||
this.delegate.lightLevel(lightLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings hardness(float hardness) {
|
||||
BlockSettingsExtensions.hardness(delegate, hardness);
|
||||
this.delegate.hardness(hardness);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings resistance(float resistance) {
|
||||
BlockSettingsExtensions.resistance(delegate, resistance);
|
||||
this.delegate.resistance(resistance);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings strength(float hardness, float resistance) {
|
||||
delegate.strength(hardness, resistance);
|
||||
this.delegate.strength(hardness, resistance);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings breakInstantly() {
|
||||
BlockSettingsExtensions.breakInstantly(delegate);
|
||||
this.delegate.breakInstantly();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings dropsNothing() {
|
||||
BlockSettingsExtensions.dropsNothing(delegate);
|
||||
this.delegate.dropsNothing();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings dropsLike(Block block) {
|
||||
delegate.dropsLike(block);
|
||||
this.delegate.dropsLike(block);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings drops(Identifier dropTableId) {
|
||||
BlockSettingsExtensions.drops(delegate, dropTableId);
|
||||
this.delegate.drops(dropTableId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FabricBlockSettings friction(float friction) {
|
||||
delegate.slipperiness(friction);
|
||||
this.delegate.slipperiness(friction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings slipperiness(float value) {
|
||||
delegate.slipperiness(value);
|
||||
this.delegate.slipperiness(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings dynamicBounds() {
|
||||
BlockSettingsExtensions.dynamicBounds(delegate);
|
||||
this.delegate.dynamicBounds();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* BUILDING LOGIC */
|
||||
|
||||
public Block.Settings build() {
|
||||
return delegate;
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public <T> T build(Function<Block.Settings, T> function) {
|
||||
return function.apply(delegate);
|
||||
return function.apply(this.delegate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,16 @@ import net.minecraft.block.MaterialColor;
|
|||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.util.DyeColor;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.MaterialBuilderHooks;
|
||||
|
||||
/**
|
||||
* @deprecated Please migrate to v1. Please use {@link net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class FabricMaterialBuilder extends Material.Builder {
|
||||
private net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder delegate;
|
||||
|
||||
public FabricMaterialBuilder(MaterialColor color) {
|
||||
super(color);
|
||||
this.delegate = new net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder(color);
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder(DyeColor color) {
|
||||
|
@ -34,59 +39,64 @@ public class FabricMaterialBuilder extends Material.Builder {
|
|||
|
||||
@Override
|
||||
public FabricMaterialBuilder burnable() {
|
||||
super.burnable();
|
||||
this.delegate.burnable();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder pistonBehavior(PistonBehavior behavior) {
|
||||
((MaterialBuilderHooks) this).setPistonBehavior(behavior);
|
||||
this.delegate.pistonBehavior(behavior);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricMaterialBuilder lightPassesThrough() {
|
||||
((MaterialBuilderHooks) this).invokeLightPassesThrough();
|
||||
this.delegate.lightPassesThrough();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder destroyedByPiston() {
|
||||
super.destroyedByPiston();
|
||||
this.delegate.destroyedByPiston();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder blocksPistons() {
|
||||
super.blocksPistons();
|
||||
this.delegate.blocksPistons();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder allowsMovement() {
|
||||
super.allowsMovement();
|
||||
this.delegate.allowsMovement();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder liquid() {
|
||||
super.liquid();
|
||||
this.delegate.liquid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder notSolid() {
|
||||
super.notSolid();
|
||||
this.delegate.notSolid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder replaceable() {
|
||||
super.replaceable();
|
||||
this.delegate.replaceable();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricMaterialBuilder requiresTool() {
|
||||
super.requiresTool();
|
||||
this.delegate.requiresTool();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material build() {
|
||||
return this.delegate.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,54 +16,20 @@
|
|||
|
||||
package net.fabricmc.fabric.api.entity;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.DefaultAttributeRegistryAccessor;
|
||||
|
||||
/**
|
||||
* Allows registering custom default attributes for living entities.
|
||||
*
|
||||
* <p>All living entity types must have default attributes registered. See {@link
|
||||
* FabricEntityTypeBuilder} for utility on entity type registration in general.</p>
|
||||
*
|
||||
* <p>A registered default attribute for an entity type can be retrieved through
|
||||
* {@link net.minecraft.entity.attribute.DefaultAttributeRegistry#get(EntityType)}.</p>
|
||||
*
|
||||
* @see net.minecraft.entity.attribute.DefaultAttributeRegistry
|
||||
* @deprecated Experimental feature, may be removed or changed without further notice.
|
||||
* Vanilla snapshot feature, subject to vanilla change.
|
||||
* @deprecated Please use {@link net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class FabricDefaultAttributeRegistry {
|
||||
/**
|
||||
* Private logger, not exposed.
|
||||
*/
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Registers a default attribute for a type of living entity.
|
||||
*
|
||||
* <p>It can be used in a fashion similar to this:
|
||||
* <blockquote><pre>
|
||||
* EntityAttributeRegistry.INSTANCE.register(type, LivingEntity.createLivingAttributes());
|
||||
* </pre></blockquote>
|
||||
* </p>
|
||||
*
|
||||
* <p>If a registration overrides another, a debug log message will be emitted. Existing registrations
|
||||
* can be checked at {@link net.minecraft.entity.attribute.DefaultAttributeRegistry#hasDefinitionFor(EntityType)}.</p>
|
||||
*
|
||||
* @param type the entity type
|
||||
* @param builder the builder that creates the default attribute
|
||||
* @deprecated Please {@link net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry#register(EntityType, DefaultAttributeContainer.Builder)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void register(EntityType<? extends LivingEntity> type, DefaultAttributeContainer.Builder builder) {
|
||||
if (DefaultAttributeRegistryAccessor.getRegistry().put(type, builder.build()) != null) {
|
||||
LOGGER.debug("Overriding existing registration for entity type {}", Registry.ENTITY_TYPE.getId(type));
|
||||
}
|
||||
net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry.register(type, builder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,44 +18,21 @@ package net.fabricmc.fabric.api.entity;
|
|||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricEntityType;
|
||||
|
||||
/**
|
||||
* Extended version of {@link EntityType.Builder} with added registration for
|
||||
* server->client entity tracking values.
|
||||
*
|
||||
* <p>For living entities, they must have {@link FabricDefaultAttributeRegistry
|
||||
* default attributes registered} after the entity type is registered.</p>
|
||||
*
|
||||
* @param <T> Entity class.
|
||||
* @deprecated Please migrate to v1. Please use {@link net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder} instead.
|
||||
*/
|
||||
// TODO more javadocs
|
||||
@Deprecated
|
||||
public class FabricEntityTypeBuilder<T extends Entity> {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private final EntityCategory category;
|
||||
private final EntityType.EntityFactory<T> function;
|
||||
private boolean saveable = true;
|
||||
private boolean summonable = true;
|
||||
private int trackingDistance = 5;
|
||||
private int updateIntervalTicks = 3;
|
||||
private Boolean alwaysUpdateVelocity;
|
||||
private boolean immuneToFire = false;
|
||||
private int maxDespawnDistance = 128;
|
||||
private int minDespawnDistance = 32;
|
||||
private EntityDimensions size = EntityDimensions.changing(-1.0f, -1.0f);
|
||||
private final net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder<T> delegate;
|
||||
|
||||
protected FabricEntityTypeBuilder(EntityCategory category, EntityType.EntityFactory<T> function) {
|
||||
this.category = category;
|
||||
this.function = function;
|
||||
this.delegate = net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder.create(category, function);
|
||||
}
|
||||
|
||||
public static <T extends Entity> FabricEntityTypeBuilder<T> create(EntityCategory category) {
|
||||
|
@ -75,17 +52,17 @@ public class FabricEntityTypeBuilder<T extends Entity> {
|
|||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> disableSummon() {
|
||||
this.summonable = false;
|
||||
this.delegate.disableSummon();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> disableSaving() {
|
||||
this.saveable = false;
|
||||
this.delegate.disableSaving();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> setImmuneToFire() {
|
||||
this.immuneToFire = true;
|
||||
this.delegate.fireImmune();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -94,35 +71,26 @@ public class FabricEntityTypeBuilder<T extends Entity> {
|
|||
*/
|
||||
@Deprecated
|
||||
public FabricEntityTypeBuilder<T> size(float width, float height) {
|
||||
this.size = EntityDimensions.changing(width, height);
|
||||
this.delegate.dimensions(EntityDimensions.changing(width, height));
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> size(EntityDimensions size) {
|
||||
this.size = size;
|
||||
this.delegate.dimensions(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) {
|
||||
return trackable(trackingDistanceBlocks, updateIntervalTicks, true);
|
||||
this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
|
||||
this.trackingDistance = trackingDistanceBlocks;
|
||||
this.updateIntervalTicks = updateIntervalTicks;
|
||||
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
|
||||
this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityType<T> build() {
|
||||
if (this.saveable) {
|
||||
// SNIP! Modded datafixers are not supported anyway.
|
||||
// TODO: Flesh out once modded datafixers exist.
|
||||
}
|
||||
|
||||
boolean figureMeOut1 = this.category == EntityCategory.CREATURE || this.category == EntityCategory.MISC; // TODO
|
||||
EntityType<T> type = new FabricEntityType<T>(this.function, this.category, this.saveable, this.summonable, this.immuneToFire, figureMeOut1, maxDespawnDistance, minDespawnDistance, size, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity);
|
||||
|
||||
return type;
|
||||
return this.delegate.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ import net.minecraft.block.Block;
|
|||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
|
||||
/**
|
||||
* @deprecated Please migrate to v1. Please use registry events instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface BlockConstructedCallback {
|
||||
Event<BlockConstructedCallback> EVENT = EventFactory.createArrayBacked(BlockConstructedCallback.class,
|
||||
(listeners) -> (settings, builtBlock) -> {
|
||||
|
|
|
@ -21,6 +21,10 @@ import net.minecraft.item.Item;
|
|||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
|
||||
/**
|
||||
* @deprecated Please migrate to v1. Please use Please use registry events instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ItemConstructedCallback {
|
||||
Event<ItemConstructedCallback> EVENT = EventFactory.createArrayBacked(ItemConstructedCallback.class,
|
||||
(listeners) -> (settings, builtItem) -> {
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.block.Block;
|
|||
import net.fabricmc.fabric.api.event.registry.BlockConstructedCallback;
|
||||
|
||||
@Mixin(Block.class)
|
||||
@Deprecated
|
||||
public class MixinBlock {
|
||||
@Inject(method = "<init>(Lnet/minecraft/block/AbstractBlock$Settings;)V", at = @At("RETURN"))
|
||||
public void init(Block.Settings builder, CallbackInfo info) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.item.Item;
|
|||
import net.fabricmc.fabric.api.event.registry.ItemConstructedCallback;
|
||||
|
||||
@Mixin(Item.class)
|
||||
@Deprecated
|
||||
public class MixinItem {
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
|
||||
public void init(Item.Settings builder, CallbackInfo info) {
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
"package": "net.fabricmc.fabric.mixin.object.builder",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"BlockSettingsHooks",
|
||||
"DefaultAttributeRegistryAccessor",
|
||||
"DefaultAttributeRegistryMixin",
|
||||
"MaterialBuilderHooks",
|
||||
"MixinBlock",
|
||||
"MixinItem"
|
||||
],
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabricloader": ">=0.8.2",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-tool-attribute-api-v1": "*"
|
||||
"fabric-object-builder-api-v1": "*"
|
||||
},
|
||||
"description": "Builders for objects vanilla has locked down.",
|
||||
"description": "Legacy builders for objects vanilla has locked down, superseded by fabric-object-builder-api-v1.",
|
||||
"mixins": [
|
||||
"fabric-object-builders-v0.mixins.json"
|
||||
]
|
||||
|
|
|
@ -30,6 +30,7 @@ include 'fabric-mining-levels-v0'
|
|||
include 'fabric-models-v0'
|
||||
include 'fabric-networking-v0'
|
||||
include 'fabric-networking-blockentity-v0'
|
||||
include 'fabric-object-builder-api-v1'
|
||||
include 'fabric-object-builders-v0'
|
||||
include 'fabric-particles-v1'
|
||||
include 'fabric-registry-sync-v0'
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.8",
|
||||
"fabricloader": ">=0.8.2",
|
||||
"minecraft": "~1.16-alpha.20.14.a"
|
||||
},
|
||||
"description": "Core API module providing key hooks and intercompatibility features."
|
||||
|
|
Loading…
Reference in a new issue