forked from DaFuqs/Spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFluidLogging.java
More file actions
175 lines (145 loc) · 5.79 KB
/
FluidLogging.java
File metadata and controls
175 lines (145 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package de.dafuqs.spectrum.blocks;
import de.dafuqs.spectrum.blocks.fluid.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.block.*;
import net.minecraft.entity.*;
import net.minecraft.fluid.*;
import net.minecraft.item.*;
import net.minecraft.registry.tag.*;
import net.minecraft.sound.*;
import net.minecraft.state.property.*;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.world.*;
import java.util.*;
public class FluidLogging {
public enum State implements StringIdentifiable {
NOT_LOGGED("none", 0),
WATER("water", 0),
LIQUID_CRYSTAL("liquid_crystal", LiquidCrystalFluidBlock.LUMINANCE),
MUD("mud",0);
private final String name;
private final int luminance;
State(String name, int luminance) {
this.name = name;
this.luminance = luminance;
}
@Override
public String asString() {
return this.name;
}
public FluidState getFluidState() {
switch (this) {
case LIQUID_CRYSTAL -> {
return SpectrumFluids.LIQUID_CRYSTAL.getStill(false);
}
case WATER -> {
return Fluids.WATER.getStill(false);
}
case MUD -> {
return SpectrumFluids.MUD.getStill(false);
}
default -> {
return Fluids.EMPTY.getDefaultState();
}
}
}
public static State getForFluidState(FluidState fluidState) {
if (fluidState.getFluid() == SpectrumFluids.LIQUID_CRYSTAL) {
return LIQUID_CRYSTAL;
} else if (fluidState.getFluid() == SpectrumFluids.MUD)
{
return MUD;
} else if (fluidState.isIn(FluidTags.WATER)) {
return WATER;
}
return NOT_LOGGED;
}
public int getLuminance() {
return luminance;
}
public boolean isOf(Fluid fluid) {
return this.getFluidState().isOf(fluid);
}
public boolean isIn(TagKey<Fluid> fluidTag) {
return this.getFluidState().isIn(fluidTag);
}
@Override
public String toString() {
return this.name;
}
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (this == State.LIQUID_CRYSTAL) {
SpectrumFluids.LIQUID_CRYSTAL.onEntityCollision(state, world, pos, entity);
}
else if (this == State.MUD) {
SpectrumFluids.MUD.onEntityCollision(state, world, pos, entity);
}
}
}
public static final EnumProperty<State> ANY_INCLUDING_NONE = EnumProperty.of("fluid_logged", State.class);
public static final EnumProperty<State> ANY_EXCLUDING_NONE = EnumProperty.of("fluid_logged", State.class, State.WATER, State.LIQUID_CRYSTAL, State.MUD);
public static final EnumProperty<State> WATER_AND_CRYSTAL = EnumProperty.of("fluid_logged", State.class, State.WATER, State.LIQUID_CRYSTAL);
public static final EnumProperty<State> NONE_AND_CRYSTAL = EnumProperty.of("fluid_logged", State.class, State.NOT_LOGGED, State.LIQUID_CRYSTAL);
public static final EnumProperty<State> NONE_WATER_AND_CRYSTAL = EnumProperty.of("fluid_logged", State.class, State.NOT_LOGGED, State.WATER, State.LIQUID_CRYSTAL);
public static final EnumProperty<State> NONE_WATER_AND_MUD = EnumProperty.of("fluid_logged", State.class, State.NOT_LOGGED, State.WATER, State.MUD);
public interface SpectrumFluidLoggable extends SpectrumFluidDrainable, SpectrumFluidFillable {
}
public interface SpectrumFluidFillable extends FluidFillable {
@Override
default boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
return state.get(ANY_INCLUDING_NONE) == State.NOT_LOGGED && (fluid == Fluids.WATER || fluid == SpectrumFluids.LIQUID_CRYSTAL || fluid == SpectrumFluids.MUD);
}
@Override
default boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
if (state.get(ANY_INCLUDING_NONE) == State.NOT_LOGGED) {
if (!world.isClient()) {
if (fluidState.getFluid() == Fluids.WATER) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.WATER), Block.NOTIFY_ALL);
world.scheduleFluidTick(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world));
} else if (fluidState.getFluid() == SpectrumFluids.LIQUID_CRYSTAL) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.LIQUID_CRYSTAL), Block.NOTIFY_ALL);
world.scheduleFluidTick(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world));
} else if (fluidState.getFluid() == SpectrumFluids.MUD) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.MUD), Block.NOTIFY_ALL);
world.scheduleFluidTick(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world));
}
}
return true;
} else {
return false;
}
}
}
public interface SpectrumFluidDrainable extends FluidDrainable {
@Override
default ItemStack tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) {
State fluidLog = state.get(ANY_INCLUDING_NONE);
if (fluidLog == State.WATER) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.NOT_LOGGED), Block.NOTIFY_ALL);
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
return new ItemStack(Items.WATER_BUCKET);
} else if (fluidLog == State.LIQUID_CRYSTAL) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.NOT_LOGGED), Block.NOTIFY_ALL);
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
return new ItemStack(SpectrumItems.LIQUID_CRYSTAL_BUCKET);
} else if (fluidLog == State.MUD) {
world.setBlockState(pos, state.with(ANY_INCLUDING_NONE, State.NOT_LOGGED), Block.NOTIFY_ALL);
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
return new ItemStack(SpectrumItems.MUD_BUCKET);
}
return ItemStack.EMPTY;
}
//TODO: Remove this when we add custom fill sounds for our fluids.
@Override
default Optional<SoundEvent> getBucketFillSound() {
return Fluids.WATER.getBucketFillSound();
}
}
}