-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathMetaTileEntityMufflerHatch.java
More file actions
113 lines (95 loc) · 4.3 KB
/
Copy pathMetaTileEntityMufflerHatch.java
File metadata and controls
113 lines (95 loc) · 4.3 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
package gregtech.common.metatileentities.multi.multiblockpart;
import gregtech.api.capability.IMufflerHatch;
import gregtech.api.metatileentity.ITieredMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.*;
import gregtech.api.util.GTUtility;
import gregtech.client.particle.VanillaParticleEffects;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.TooltipHelper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class MetaTileEntityMufflerHatch extends MetaTileEntityMultiblockPart implements
IMultiblockAbilityPart<IMufflerHatch>, ITieredMetaTileEntity, IMufflerHatch {
private boolean frontFaceFree;
public MetaTileEntityMufflerHatch(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, tier);
}
@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntityMufflerHatch(metaTileEntityId, getTier());
}
@Override
public void update() {
super.update();
if (getWorld().isRemote) {
if (getController() instanceof MultiblockWithDisplayBase controller && controller.isActive()) {
VanillaParticleEffects.mufflerEffect(this, controller.getMufflerParticle());
}
} else if (getOffsetTimer() % 10 == 0) {
this.frontFaceFree = checkFrontFaceFree();
}
}
/**
* @return true if front face is free and contains only air blocks in 1x1 area
*/
@Override
public boolean isFrontFaceFree() {
return frontFaceFree;
}
private boolean checkFrontFaceFree() {
BlockPos frontPos = getPos().offset(getFrontFacing());
IBlockState blockState = getWorld().getBlockState(frontPos);
// break a snow layer if it exists, and if this machine is running
if (getController() instanceof MultiblockWithDisplayBase controller && controller.isActive()) {
if (GTUtility.tryBreakSnow(getWorld(), frontPos, blockState, true)) {
return true;
}
return blockState.getBlock().isAir(blockState, getWorld(), frontPos);
}
return blockState.getBlock().isAir(blockState, getWorld(), frontPos) || GTUtility.isBlockSnow(blockState);
}
@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
if (shouldRenderOverlay()) {
Textures.MUFFLER_OVERLAY.renderSided(getFrontFacing(), renderState, translation, pipeline);
}
}
@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
tooltip.add(I18n.format("gregtech.machine.muffler_hatch.tooltip1"));
tooltip.add(I18n.format("gregtech.universal.enabled"));
tooltip.add(TooltipHelper.BLINKING_RED + I18n.format("gregtech.machine.muffler_hatch.tooltip2"));
}
@Override
public void addToolUsages(ItemStack stack, @Nullable World world, List<String> tooltip, boolean advanced) {
tooltip.add(I18n.format("gregtech.tool_action.screwdriver.access_covers"));
tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing"));
super.addToolUsages(stack, world, tooltip, advanced);
}
@Override
public MultiblockAbility<IMufflerHatch> getAbility() {
return MultiblockAbility.MUFFLER_HATCH;
}
@Override
public void registerAbilities(@NotNull AbilityInstances abilityInstances) {
abilityInstances.add(this);
}
@Override
protected boolean openGUIOnRightClick() {
return false;
}
}