Skip to content

Commit

Permalink
Fix dying blocks to their current color. Close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Jan 7, 2025
1 parent f069918 commit 401279f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod_name=Ex Nihilo\: Coloratus
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.0.0
mod_version=1.0.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}

rootProject.name = 'color-stages'
rootProject.name = 'ExNihiloColoratus'
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class EXNCBlocks {
private static final BlockRegistry BLOCKS = new BlockRegistry(ExNihiloColoratus.MODID);

public static final BlockDefinition<CrucibleBlock> NONE_CRUCIBLE = BLOCKS.burnableBlock("Colorless Crucible", "none_crucible", ColoredWoodCrucibleBlock::new);
public static final BlockDefinition<BarrelBlock> NONE_BARREL = BLOCKS.burnableBlock("Colorless Barrel", "none_barrel", ColoredWoodBarrelBlock::new);
public static final BlockDefinition<CrucibleBlock> NONE_CRUCIBLE = BLOCKS.burnableBlock("Colorless Crucible", "none_crucible", () -> new ColoredWoodCrucibleBlock(Optional.empty()));
public static final BlockDefinition<BarrelBlock> NONE_BARREL = BLOCKS.burnableBlock("Colorless Barrel", "none_barrel", () -> new ColoredWoodBarrelBlock(Optional.empty()));
public static final Map<DyeColor, BlockDefinition<CrucibleBlock>> CRUCIBLES = Util.make(() -> {
ImmutableMap.Builder<DyeColor, BlockDefinition<CrucibleBlock>> builder = ImmutableMap.builder();
for (DyeColor value : DyeColor.values()) {
builder.put(value, BLOCKS.burnableBlock(titleCase(value.getName()) + " Crucible", value.getName() + "_crucible", ColoredWoodCrucibleBlock::new));
builder.put(value, BLOCKS.burnableBlock(titleCase(value.getName()) + " Crucible", value.getName() + "_crucible", () -> new ColoredWoodCrucibleBlock(Optional.of(value))));
}
return builder.build();
});

public static final Map<DyeColor, BlockDefinition<BarrelBlock>> BARRELS = Util.make(() -> {
ImmutableMap.Builder<DyeColor, BlockDefinition<BarrelBlock>> builder = ImmutableMap.builder();
for (DyeColor value : DyeColor.values()) {
builder.put(value, BLOCKS.burnableBlock(titleCase(value.getName()) + " Barrel", value.getName() + "_barrel", ColoredWoodBarrelBlock::new));
builder.put(value, BLOCKS.burnableBlock(titleCase(value.getName()) + " Barrel", value.getName() + "_barrel", () -> new ColoredWoodBarrelBlock(Optional.of(value))));
}
return builder.build();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand All @@ -19,18 +20,27 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ColoredWoodBarrelBlock extends WoodBarrelBlock {


private final Optional<DyeColor> color;

public ColoredWoodBarrelBlock(Optional<DyeColor> color) {
this.color = color;
}

@Override
public @NotNull InteractionResult use(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) {

ItemStack stack = player.getItemInHand(handIn);
if (level.getBlockEntity(pos) instanceof WoodBarrelBlockEntity be) {
Block newBlock = null;
if (be.getFluidAmount() == 0) {
if (stack.getItem() instanceof DyeItem dyeItem) {
if (stack.getItem() instanceof DyeItem dyeItem && this.color.filter(dyeColor -> dyeColor != dyeItem.getDyeColor()).isPresent()) {
newBlock = EXNCBlocks.BARRELS.get(dyeItem.getDyeColor()).block();
} else if(stack.is(ExNihiloColoratus.NONE_DYE_TAG)) {
} else if(this.color.isPresent() && stack.is(ExNihiloColoratus.NONE_DYE_TAG)) {
newBlock = EXNCBlocks.NONE_BARREL.block();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ColoredWoodCrucibleBlock extends WoodCrucibleBlock {

private final Optional<DyeColor> color;

public ColoredWoodCrucibleBlock(Optional<DyeColor> color) {
this.color = color;
}

@Override
public @NotNull InteractionResult use(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) {

ItemStack stack = player.getItemInHand(handIn);
if (level.getBlockEntity(pos) instanceof WoodCrucibleBlockEntity be) {
Block newBlock = null;
if (be.getFluidAmount() == 0) {
if (stack.getItem() instanceof DyeItem dyeItem) {
if (stack.getItem() instanceof DyeItem dyeItem && this.color.filter(dyeColor -> dyeColor != dyeItem.getDyeColor()).isPresent()) {
newBlock = EXNCBlocks.CRUCIBLES.get(dyeItem.getDyeColor()).block();
} else if(stack.is(ExNihiloColoratus.NONE_DYE_TAG)) {
} else if(this.color.isPresent() && stack.is(ExNihiloColoratus.NONE_DYE_TAG)) {
newBlock = EXNCBlocks.NONE_CRUCIBLE.block();
}
}
Expand Down

0 comments on commit 401279f

Please sign in to comment.