WeatheringCopper .java

net.minecraft.world.level.block.WeatheringCopper (interface, 121 lines): members: PREVIOUS_BY_BLOCK, NEXT_BY_BLOCK, WeatherState, getPrevious, getNext.

net.minecraft.world.level.blockinterface121 linescommonextends ChangeOverTimeBlock<WeatheringCopper.WeatherState>3.8 KB

API Surface (4)

String getSerializedName()
void forEach(final Consumer<WeatheringCopper.WeatherState> consumer)
WeatheringCopper.WeatherState next()
WeatheringCopper.WeatherState previous()

Fields & Constants (2)

NEXT_BY_BLOCK
PREVIOUS_BY_BLOCK

String literals (4)

"unaffected"
"exposed"
"weathered"
"oxidized"

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

WeatheringCopper.java121 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import com.google.common.base.Suppliers;
4
import com.google.common.collect.BiMap;
5
import com.google.common.collect.ImmutableBiMap;
6
import com.google.common.collect.ImmutableBiMap.Builder;
7
import com.mojang.serialization.Codec;
8
import io.netty.buffer.ByteBuf;
9
import java.util.Optional;
10
import java.util.function.Consumer;
11
import java.util.function.IntFunction;
12
import java.util.function.Supplier;
13
import java.util.stream.Stream;
14
import net.minecraft.network.codec.ByteBufCodecs;
15
import net.minecraft.network.codec.StreamCodec;
16
import net.minecraft.util.ByIdMap;
17
import net.minecraft.util.StringRepresentable;
18
import net.minecraft.world.level.block.state.BlockState;
19
20
/**
21
 * @see net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry registry for modded oxidizable blocks
22
 */
23
public interface WeatheringCopper extends ChangeOverTimeBlock<WeatheringCopper.WeatherState> {
24
	Supplier<BiMap<Block, Block>> NEXT_BY_BLOCK = Suppliers.memoize(
25
		() -> {
26
			Builder<Block, Block> builder = ImmutableBiMap.builder();
27
			Stream.of(
28
					Blocks.COPPER_BLOCK,
29
					Blocks.CUT_COPPER,
30
					Blocks.CHISELED_COPPER,
31
					Blocks.CUT_COPPER_SLAB,
32
					Blocks.CUT_COPPER_STAIRS,
33
					Blocks.COPPER_DOOR,
34
					Blocks.COPPER_TRAPDOOR,
35
					Blocks.COPPER_BARS,
36
					Blocks.COPPER_GRATE,
37
					Blocks.COPPER_BULB,
38
					Blocks.COPPER_LANTERN,
39
					Blocks.COPPER_CHEST,
40
					Blocks.COPPER_GOLEM_STATUE,
41
					Blocks.LIGHTNING_ROD,
42
					Blocks.COPPER_CHAIN
43
				)
44
				.forEach(collection -> collection.weathering().progressMapping(builder::put));
45
			return builder.build();
46
		}
47
	);
48
	Supplier<BiMap<Block, Block>> PREVIOUS_BY_BLOCK = Suppliers.memoize(() -> NEXT_BY_BLOCK.get().inverse());
49
50
	static Optional<Block> getPrevious(final Block block) {
51
		return Optional.ofNullable(PREVIOUS_BY_BLOCK.get().get(block));
52
	}
53
54
	static Block getFirst(final Block block) {
55
		Block candiate = block;
56
57
		for (Block previous = PREVIOUS_BY_BLOCK.get().get(candiate); previous != null; previous = PREVIOUS_BY_BLOCK.get().get(candiate)) {
58
			candiate = previous;
59
		}
60
61
		return candiate;
62
	}
63
64
	static Optional<BlockState> getPrevious(final BlockState state) {
65
		return getPrevious(state.getBlock()).map(s -> s.withPropertiesOf(state));
66
	}
67
68
	static Optional<Block> getNext(final Block block) {
69
		return Optional.ofNullable(NEXT_BY_BLOCK.get().get(block));
70
	}
71
72
	static BlockState getFirst(final BlockState state) {
73
		return getFirst(state.getBlock()).withPropertiesOf(state);
74
	}
75
76
	@Override
77
	default Optional<BlockState> getNext(final BlockState state) {
78
		return getNext(state.getBlock()).map(s -> s.withPropertiesOf(state));
79
	}
80
81
	@Override
82
	default float getChanceModifier() {
83
		return this.getAge() == WeatheringCopper.WeatherState.UNAFFECTED ? 0.75F : 1.0F;
84
	}
85
86
	enum WeatherState implements StringRepresentable {
87
		UNAFFECTED("unaffected"),
88
		EXPOSED("exposed"),
89
		WEATHERED("weathered"),
90
		OXIDIZED("oxidized");
91
92
		public static final IntFunction<WeatheringCopper.WeatherState> BY_ID = ByIdMap.continuous(Enum::ordinal, values(), ByIdMap.OutOfBoundsStrategy.CLAMP);
93
		public static final Codec<WeatheringCopper.WeatherState> CODEC = StringRepresentable.fromEnum(WeatheringCopper.WeatherState::values);
94
		public static final StreamCodec<ByteBuf, WeatheringCopper.WeatherState> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Enum::ordinal);
95
		private final String name;
96
97
		WeatherState(final String name) {
98
			this.name = name;
99
		}
100
101
		@Override
102
		public String getSerializedName() {
103
			return this.name;
104
		}
105
106
		public static void forEach(final Consumer<WeatheringCopper.WeatherState> consumer) {
107
			for (WeatheringCopper.WeatherState weatherState : values()) {
108
				consumer.accept(weatherState);
109
			}
110
		}
111
112
		public WeatheringCopper.WeatherState next() {
113
			return BY_ID.apply(this.ordinal() + 1);
114
		}
115
116
		public WeatheringCopper.WeatherState previous() {
117
			return BY_ID.apply(this.ordinal() - 1);
118
		}
119
	}
120
}
121

Decompiled Minecraft 26.3 source of WeatheringCopper (net/minecraft/world/level/block/WeatheringCopper.java) with Mojang official mappings, stored verbatim on the site.