-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathHoloScreenEntity.java
More file actions
182 lines (147 loc) · 5.03 KB
/
HoloScreenEntity.java
File metadata and controls
182 lines (147 loc) · 5.03 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
176
177
178
179
180
181
182
package com.cleanroommc.modularui.holoui;
import com.cleanroommc.modularui.api.IMuiScreen;
import com.cleanroommc.modularui.api.MCHelper;
import com.cleanroommc.modularui.screen.*;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Highly experimental
*/
@ApiStatus.Experimental
public class HoloScreenEntity extends Entity {
private IMuiScreen wrapper;
private ModularPanel panel;
private final Plane3D plane3D;
private static final DataParameter<Byte> ORIENTATION = EntityDataManager.createKey(HoloScreenEntity.class, DataSerializers.BYTE);
public HoloScreenEntity(World worldIn, Plane3D plane3D) {
super(worldIn);
this.plane3D = plane3D;
}
public HoloScreenEntity(World world) {
this(world, new Plane3D());
}
public void setWrapper(IMuiScreen wrapper) {
this.wrapper = wrapper;
this.wrapper.getGuiScreen().setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight());
this.wrapper.getScreen().getContext().holoScreen = this;
this.wrapper.getScreen().getContext().isHoloScreen = true;
}
public void setPanel(ModularPanel panel) {
this.panel = panel;
}
public ModularScreen getScreen() {
return this.getWrapper().getScreen();
}
public IMuiScreen getWrapper() {
return this.wrapper;
}
public void spawnInWorld() {
getEntityWorld().spawnEntity(this);
if (world.isRemote)
onResize();
}
@SideOnly(Side.CLIENT)
public void onResize() {
getScreen().onResize((int) plane3D.getWidth(), (int) plane3D.getHeight());
}
public void setOrientation(ScreenOrientation orientation) {
this.dataManager.set(ORIENTATION, (byte) orientation.ordinal());
}
public ScreenOrientation getOrientation() {
return ScreenOrientation.values()[this.dataManager.get(ORIENTATION)];
}
public boolean isName(String name) {
if (this.panel == null) return false;
return this.panel.getName().equals(name);
}
public Plane3D getPlane3D() {
return this.plane3D;
}
@Override
protected void entityInit() {
this.dataManager.register(ORIENTATION, (byte) 1);
}
@Override
public void onEntityUpdate() {
this.world.profiler.startSection("entityBaseTick");
this.prevDistanceWalkedModified = this.distanceWalkedModified;
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
if (this.posY < -64.0D) {
this.outOfWorld();
}
if (this.world.isRemote) {
this.extinguish();
int w = (int) this.plane3D.getWidth(), h = (int) this.plane3D.getHeight();
if (this.wrapper == null) {
this.getEntityWorld().removeEntity(this);
return;
}
var wrapper = this.wrapper.getGuiScreen();
if (w != wrapper.width || h != wrapper.height) {
wrapper.onResize(Minecraft.getMinecraft(), w, h);
}
this.wrapper.getScreen().onUpdate();
}
this.firstUpdate = false;
this.world.profiler.endSection();
}
@Override
public boolean isInRangeToRender3d(double x, double y, double z) {
return true;
}
@Override
public boolean isInRangeToRenderDist(double distance) {
return true;
}
@Override
protected void readEntityFromNBT(@NotNull NBTTagCompound compound) {
}
@Override
protected void writeEntityToNBT(@NotNull NBTTagCompound compound) {
}
@Override
public boolean doesEntityNotTriggerPressurePlate() {
return true;
}
@Override
public boolean isImmuneToExplosions() {
return true;
}
@Override
public boolean isCreatureType(@NotNull EnumCreatureType type, boolean forSpawnCount) {
return false;
}
@Override
public boolean canTrample(@NotNull World world, @NotNull Block block, @NotNull BlockPos pos, float fallDistance) {
return false;
}
@Override
protected boolean canBeRidden(@NotNull Entity entityIn) {
return false;
}
@Override
public boolean shouldRenderInPass(int pass) {
return pass == 1;
}
@SideOnly(Side.CLIENT)
@Override
public int getBrightnessForRender() {
return 15728880;
}
}