mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-23 21:40:02 -04:00
Refactor FabricBlockSettings to copy and override new stuff (#2741)
* Copy new block settings * Sort method calls in copy method * Add more overrides
This commit is contained in:
parent
112a38be2a
commit
e9dee004f1
2 changed files with 81 additions and 49 deletions
fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric
api/object/builder/v1/block
mixin/object/builder
|
@ -16,6 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.api.object.builder.v1.block;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
|
@ -24,6 +25,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.MapColor;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.resource.featuretoggle.FeatureFlag;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -53,6 +55,7 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
AbstractBlockSettingsAccessor thisAccessor = (AbstractBlockSettingsAccessor) this;
|
||||
AbstractBlockSettingsAccessor otherAccessor = (AbstractBlockSettingsAccessor) settings;
|
||||
|
||||
// Copied in vanilla: sorted by vanilla copy order
|
||||
thisAccessor.setMaterial(otherAccessor.getMaterial());
|
||||
this.hardness(otherAccessor.getHardness());
|
||||
this.resistance(otherAccessor.getResistance());
|
||||
|
@ -63,18 +66,23 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
this.sounds(otherAccessor.getSoundGroup());
|
||||
this.slipperiness(otherAccessor.getSlipperiness());
|
||||
this.velocityMultiplier(otherAccessor.getVelocityMultiplier());
|
||||
this.jumpVelocityMultiplier(otherAccessor.getJumpVelocityMultiplier());
|
||||
thisAccessor.setDynamicBounds(otherAccessor.getDynamicBounds());
|
||||
thisAccessor.setOpaque(otherAccessor.getOpaque());
|
||||
thisAccessor.setIsAir(otherAccessor.getIsAir());
|
||||
thisAccessor.setToolRequired(otherAccessor.isToolRequired());
|
||||
this.offsetType(otherAccessor.getOffsetType());
|
||||
thisAccessor.setBlockBreakParticles(otherAccessor.getBlockBreakParticles());
|
||||
thisAccessor.setRequiredFeatures(otherAccessor.getRequiredFeatures());
|
||||
|
||||
// Not copied in vanilla: field definition order
|
||||
this.jumpVelocityMultiplier(otherAccessor.getJumpVelocityMultiplier());
|
||||
this.drops(otherAccessor.getLootTableId());
|
||||
this.allowsSpawning(otherAccessor.getAllowsSpawningPredicate());
|
||||
this.solidBlock(otherAccessor.getSolidBlockPredicate());
|
||||
this.suffocates(otherAccessor.getSuffocationPredicate());
|
||||
this.blockVision(otherAccessor.getBlockVisionPredicate());
|
||||
this.postProcess(otherAccessor.getPostProcessPredicate());
|
||||
this.emissiveLighting(otherAccessor.getEmissiveLightingPredicate());
|
||||
this.offsetType(otherAccessor.getOffsetType());
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of(Material material) {
|
||||
|
@ -175,6 +183,12 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings dropsNothing() {
|
||||
super.dropsNothing();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings dropsLike(Block block) {
|
||||
super.dropsLike(block);
|
||||
|
@ -223,6 +237,57 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the block require tool to drop and slows down mining speed if the incorrect tool is used.
|
||||
*/
|
||||
@Override
|
||||
public FabricBlockSettings requiresTool() {
|
||||
super.requiresTool();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings mapColor(MapColor color) {
|
||||
super.mapColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings hardness(float hardness) {
|
||||
super.hardness(hardness);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings resistance(float resistance) {
|
||||
super.resistance(resistance);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings offsetType(AbstractBlock.OffsetType offsetType) {
|
||||
super.offsetType(offsetType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings offsetType(Function<BlockState, AbstractBlock.OffsetType> offsetType) {
|
||||
super.offsetType(offsetType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings noBlockBreakParticles() {
|
||||
super.noBlockBreakParticles();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings requires(FeatureFlag... features) {
|
||||
super.requires(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC ADDITIONS*/
|
||||
|
||||
/**
|
||||
|
@ -239,30 +304,11 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the block require tool to drop and slows down mining speed if the incorrect tool is used.
|
||||
*/
|
||||
@Override
|
||||
public FabricBlockSettings requiresTool() {
|
||||
super.requiresTool();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC DELEGATE WRAPPERS */
|
||||
|
||||
/**
|
||||
|
@ -281,11 +327,6 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
return this.mapColor(color);
|
||||
}
|
||||
|
||||
public FabricBlockSettings mapColor(MapColor color) {
|
||||
((AbstractBlockSettingsAccessor) this).setMapColorProvider(ignored -> color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FabricBlockSettings mapColor(DyeColor color) {
|
||||
return this.mapColor(color.getMapColor());
|
||||
}
|
||||
|
|
|
@ -21,14 +21,13 @@ import java.util.function.ToIntFunction;
|
|||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
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.MapColor;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
|
@ -101,16 +100,19 @@ public interface AbstractBlockSettingsAccessor {
|
|||
@Accessor
|
||||
Function<BlockState, AbstractBlock.OffsetType> getOffsetType();
|
||||
|
||||
@Accessor
|
||||
Identifier getLootTableId();
|
||||
|
||||
@Accessor
|
||||
boolean getBlockBreakParticles();
|
||||
|
||||
@Accessor
|
||||
FeatureSet getRequiredFeatures();
|
||||
|
||||
/* SETTERS */
|
||||
@Accessor
|
||||
void setMaterial(Material material);
|
||||
|
||||
@Accessor
|
||||
void setHardness(float hardness);
|
||||
|
||||
@Accessor
|
||||
void setResistance(float resistance);
|
||||
|
||||
@Accessor
|
||||
void setCollidable(boolean collidable);
|
||||
|
||||
|
@ -135,20 +137,9 @@ public interface AbstractBlockSettingsAccessor {
|
|||
@Accessor
|
||||
void setToolRequired(boolean toolRequired);
|
||||
|
||||
// Cannot be an invoker due to conflicts in mixin: method_9631(Ljava/util/function/ToIntFunction;)Lnet/minecraft/class_4970$class_2251; for target net.minecraft.block.AbstractBlock$Settings conflicts with existing mapping field_10663:Ljava/util/function/ToIntFunction;
|
||||
@Accessor("luminance")
|
||||
void setLuminanceFunction(ToIntFunction<BlockState> luminanceFunction);
|
||||
@Accessor
|
||||
void setBlockBreakParticles(boolean blockBreakParticles);
|
||||
|
||||
/* INVOKERS */
|
||||
@Invoker
|
||||
Block.Settings invokeSounds(BlockSoundGroup group);
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeBreakInstantly();
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeStrength(float strength);
|
||||
|
||||
@Invoker
|
||||
Block.Settings invokeTicksRandomly();
|
||||
@Accessor
|
||||
void setRequiredFeatures(FeatureSet requiredFeatures);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue