-
Notifications
You must be signed in to change notification settings - Fork 755
/
SearedTankBlock.java
126 lines (110 loc) · 4.36 KB
/
SearedTankBlock.java
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
package slimeknights.tconstruct.smeltery.block.component;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.fluid.FluidTransferHelper;
import slimeknights.mantle.util.BlockEntityHelper;
import slimeknights.tconstruct.library.recipe.FluidValues;
import slimeknights.tconstruct.library.utils.NBTTags;
import slimeknights.tconstruct.smeltery.block.entity.ITankBlockEntity;
import slimeknights.tconstruct.smeltery.block.entity.component.TankBlockEntity;
import slimeknights.tconstruct.smeltery.block.entity.component.TankBlockEntity.ITankBlock;
import javax.annotation.Nullable;
import java.util.Locale;
public class SearedTankBlock extends SearedBlock implements ITankBlock, EntityBlock {
@Getter
private final int capacity;
private final PushReaction pushReaction;
public SearedTankBlock(Properties properties, int capacity, PushReaction pushReaction) {
super(properties, true);
this.capacity = capacity;
this.pushReaction = pushReaction;
}
public SearedTankBlock(Properties properties, int capacity) {
this(properties, capacity, PushReaction.BLOCK);
}
@Override
public PushReaction getPistonPushReaction(BlockState pState) {
return pushReaction;
}
@Deprecated
@Override
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
return 1.0F;
}
@Override
@Nullable
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return new TankBlockEntity(pPos, pState, this);
}
@Deprecated
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (FluidTransferHelper.interactWithTank(world, pos, player, hand, hit)) {
return InteractionResult.SUCCESS;
}
return super.use(state, world, pos, player, hand, hit);
}
@Override
public int getLightEmission(BlockState state, BlockGetter world, BlockPos pos) {
BlockEntity te = world.getBlockEntity(pos);
if (te instanceof TankBlockEntity) {
FluidStack fluid = ((TankBlockEntity) te).getTank().getFluid();
return fluid.getFluid().getFluidType().getLightLevel(fluid);
}
return super.getLightEmission(state, world, pos);
}
@Override
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
CompoundTag nbt = stack.getTag();
if (nbt != null) {
BlockEntityHelper.get(TankBlockEntity.class, worldIn, pos).ifPresent(te -> te.updateTank(nbt.getCompound(NBTTags.TANK)));
}
super.setPlacedBy(worldIn, pos, state, placer, stack);
}
@Deprecated
@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
}
@Deprecated
@Override
public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) {
return ITankBlockEntity.getComparatorInputOverride(worldIn, pos);
}
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) {
ItemStack stack = new ItemStack(this);
BlockEntityHelper.get(TankBlockEntity.class, world, pos).ifPresent(te -> te.setTankTag(stack));
return stack;
}
@AllArgsConstructor
public enum TankType implements StringRepresentable {
FUEL_TANK(TankBlockEntity.DEFAULT_CAPACITY),
FUEL_GAUGE(TankBlockEntity.DEFAULT_CAPACITY),
INGOT_TANK(FluidValues.INGOT * 48),
INGOT_GAUGE(FluidValues.INGOT * 48);
@Getter
private final int capacity;
@Override
public String getSerializedName() {
return this.toString().toLowerCase(Locale.US);
}
}
}