Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

// :::datagen-setup:generator
}

// :::datagen-setup:generator

Check failure on line 67 in reference/latest/src/client/java/com/example/docs/datagen/ExampleModDataGenerator.java

View workflow job for this annotation

GitHub Actions / mod

trailing whitespace
// :::datagen-enchantments:bootstrap
@Override
public void buildRegistry(RegistrySetBuilder registryBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public static void registerScaled2x(Item item, ItemModelGenerators generator) {
Identifier itemModel = SCALED2X.create(item, TextureMapping.singleSlot(TextureSlot.LAYER0, ModelLocationUtils.getModelLocation(item)), generator.modelOutput);
generator.itemModelOutput.accept(item, ItemModelUtils.plainModel(itemModel));
}

//:::custom-item-datagen-method

@SuppressWarnings("SameParameterValue")
Expand All @@ -189,7 +188,6 @@ public static void registerScaled2x(Item item, ItemModelGenerators generator) {
private static ModelTemplate item(String parent, TextureSlot requiredTextureKeys) {
return new ModelTemplate(Optional.of(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "item/" + parent)), Optional.empty(), requiredTextureKeys);
}

//:::custom-item-model:::
}
// :::custom-item-model-generator:::
Expand All @@ -209,7 +207,6 @@ private static ModelTemplate block(String parent, TextureSlot... requiredTexture
private static ModelTemplate block(String parent, String variant, TextureSlot... requiredTextureKeys) {
return new ModelTemplate(Optional.of(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "block/" + parent)), Optional.of(variant), requiredTextureKeys);
}

// :::custom-model

// :::custom-texture-map
Expand All @@ -219,7 +216,6 @@ public static TextureMapping blockAndTopForEnds(Block block) {
.put(TextureSlot.BOTTOM, ModelLocationUtils.getModelLocation(block, "_top"))
.put(TextureSlot.SIDE, ModelLocationUtils.getModelLocation(block));
}

// :::custom-texture-map

// :::custom-supplier
Expand All @@ -238,7 +234,6 @@ private static BlockModelDefinitionGenerator createVerticalSlabBlockStates(Block
.select(Direction.WEST, false, fullBlockModel.with(BlockModelGenerators.UV_LOCK))
);
}

// :::custom-supplier

// :::custom-gen
Expand All @@ -248,7 +243,6 @@ public static void registerVerticalSlab(BlockModelGenerators generator, Block ve
generator.blockStateOutput.accept(createVerticalSlabBlockStates(vertSlabBlock, slabModel, fullBlockModel));
generator.registerSimpleItemModel(vertSlabBlock, slabModel);
}

// :::custom-gen
}
// :::custom-blockstate-model-generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private static void handleS2CEngineSoundPacket(EngineSoundInstancePacket packet,
soundManager.getPlayingSoundInstance(CustomSounds.ENGINE_LOOP).ifPresent(AbstractDynamicSoundInstance::end);
}
}

// :::1

public static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ private static void render(GuiGraphics graphics, DeltaTracker tickCounter) {
graphics.fill(0, 0, 10, 10, lerpedColor);
}
}

// :::1
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float
// x1, y1, x2, y2, startColor, endColor
int startColor = 0xFF00FF00; // Green
int endColor = 0xFF0000FF; // Blue

// :::1

// :::2
// This is in the "renderWidget" method, so we can check if the mouse is hovering over the widget.
if (isHovered()) {
startColor = 0xFFFF0000; // Red
endColor = 0xFF00FFFF; // Cyan
}

// :::2
// :::1

graphics.fillGradient(getX(), getY(), getX() + this.width, getY() + this.height, startColor, endColor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public boolean canStartSilent() {
// or add your own condition to the SoundInstance, if necessary
return true;
}

// :::3

// :::4
Expand Down Expand Up @@ -104,7 +103,6 @@ public void tick() {
// apply volume and pitch modulation here,
// if you use a normal SoundInstance class
}

// :::4

// :::5
Expand All @@ -123,7 +121,6 @@ protected void modulateSoundForTransition() {
protected void modulateSoundForStress() {
this.pitch = Mth.lerp(this.soundSource.getNormalizedStress(), this.minPitch, this.maxPitch);
}

// :::5

// :::6
Expand All @@ -139,7 +136,6 @@ protected void setPositionToEntity() {
public void end() {
this.transitionState = TransitionState.ENDING;
}

// :::6
// :::1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static DynamicSoundManager getInstance() {

return instance;
}

// :::1

// :::2
Expand Down Expand Up @@ -63,7 +62,6 @@ public Optional<AbstractDynamicSoundInstance> getPlayingSoundInstance(SoundEvent

return Optional.empty();
}

// :::2

// :::1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class UseToolCriterion extends SimpleCriterionTrigger<UseToolCriterion.Co
public void trigger(ServerPlayer player) {
trigger(player, Conditions::requirementsMet);
}

// :::datagen-advancements:criterion-trigger
// :::datagen-advancements:criterion-base

Expand All @@ -32,13 +31,12 @@ public record Conditions(Optional<ContextAwarePredicate> playerPredicate) implem
public Optional<ContextAwarePredicate> player() {
return playerPredicate;
}

// :::datagen-advancements:criterion-base

// :::datagen-advancements:conditions-test
public boolean requirementsMet() {
return true; // AbstractCriterion#trigger helpfully checks the playerPredicate for us.
}

// :::datagen-advancements:conditions-test
// :::datagen-advancements:criterion-base
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
BlockBehaviour.Properties.of().sound(SoundType.GRASS),
true
);

// :::2

// :::3
public static final Block CONDENSED_OAK_LOG = register(
"condensed_oak_log",
RotatedPillarBlock::new,
BlockBehaviour.Properties.of().sound(SoundType.WOOD),
true
);

// :::3

// :::4
public static final Block PRISMARINE_LAMP = register(
"prismarine_lamp",
Expand All @@ -64,6 +64,7 @@
true
);
// :::4

Check failure on line 67 in reference/latest/src/main/java/com/example/docs/block/ModBlocks.java

View workflow job for this annotation

GitHub Actions / mod

trailing whitespace
Comment thread
Wind292 marked this conversation as resolved.
Outdated
public static final ResourceKey<Block> ENGINE_BLOCK_KEY = ResourceKey.create(
Registries.BLOCK,
Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "engine")
Expand Down Expand Up @@ -160,7 +161,6 @@
private static ResourceKey<Item> keyOfItem(String name) {
return ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, name));
}

// :::1

public static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected MapCodec<? extends BaseEntityBlock> codec() {
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new CounterBlockEntity(pos, state);
}

// :::1

// :::2
Expand All @@ -49,7 +48,6 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP

return InteractionResult.SUCCESS;
}

// :::2

// :::3
Expand All @@ -58,7 +56,6 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return createTickerHelper(type, ModBlockEntities.COUNTER_BLOCK_ENTITY, CounterBlockEntity::tick);
}

// :::3

// :::1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level w

return InteractionResult.SUCCESS;
}

// :::useon

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
// Set the default state of the block to be deactivated.
registerDefaultState(defaultBlockState().setValue(ACTIVATED, false));
}

// :::3

// :::2
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(ACTIVATED);
}

// :::2

// :::4
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hit) {
Expand All @@ -52,8 +52,8 @@
return InteractionResult.SUCCESS;
}
}

// :::4

// :::5
public static int getLuminance(BlockState currentBlockState) {
// Get the value of the "activated" property.
Expand All @@ -62,8 +62,8 @@
// Return a light level if activated = true
return activated ? 15 : 0;
}

// :::5

Check failure on line 66 in reference/latest/src/main/java/com/example/docs/block/custom/PrismarineLampBlock.java

View workflow job for this annotation

GitHub Actions / mod

trailing whitespace
Comment thread
Wind292 marked this conversation as resolved.
Outdated
// :::1
}
// :::1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos,
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.getBlockSupportShape(state, level, pos);
}

// :::custom-collision

// :::custom-replace
Expand All @@ -87,7 +86,6 @@ protected boolean canBeReplaced(BlockState state, BlockPlaceContext context) {

return false;
}

// :::custom-replace

// :::custom-placement
Expand Down Expand Up @@ -115,15 +113,13 @@ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return state2.setValue(FACING, direction);
}
}

// :::custom-placement

// :::custom-append
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(SINGLE, FACING);
}

// :::custom-append

// :::custom-constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private static <T extends BlockEntity> BlockEntityType<T> register(
Identifier id = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, name);
return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, id, FabricBlockEntityTypeBuilder.<T>create(entityFactory, blocks).build());
}

// :::1

public static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class CounterBlockEntity extends BlockEntity {
public CounterBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.COUNTER_BLOCK_ENTITY, pos, state);
}

// :::1

// :::2
Expand All @@ -45,7 +44,6 @@ public void incrementClicks() {
clicks++;
setChanged();
}

// :::2

// :::3
Expand All @@ -55,7 +53,6 @@ protected void saveAdditional(ValueOutput output) {

super.saveAdditional(output);
}

// :::3

// :::4
Expand All @@ -65,22 +62,19 @@ protected void loadAdditional(ValueInput input) {

clicks = input.getIntOr("clicks", 0);
}

// :::4

// :::5
public static void tick(Level level, BlockPos blockPos, BlockState blockState, CounterBlockEntity entity) {
entity.ticksSinceLast++;
}

// :::5

// :::7
@Override
public CompoundTag getUpdateTag(HolderLookup.Provider registryLookup) {
return saveWithoutMetadata(registryLookup);
}

// :::7

// :::1
Expand Down
Loading
Loading