-
Notifications
You must be signed in to change notification settings - Fork 752
/
CommonProxy.java
144 lines (116 loc) · 5.37 KB
/
CommonProxy.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package slimeknights.tconstruct.common;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import slimeknights.mantle.network.AbstractPacket;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.network.SpawnParticlePacket;
import slimeknights.tconstruct.library.client.particle.Particles;
import slimeknights.tconstruct.shared.client.ParticleEffect;
/**
* This class contains all the base functions for server and clientside proxy that should be called. Can be used when no
* specific handling is needed. Can be replaced with a specific implementation at any time.
*
* Also doubles as documentation when what should happen.
*/
public class CommonProxy {
public void preInit() {
if(!Loader.instance().isInState(LoaderState.PREINITIALIZATION)) {
TConstruct.log.error(
"Proxy.preInit has to be called during Pre-Initialisation.");
}
}
public void init() {
if(!Loader.instance().isInState(LoaderState.INITIALIZATION)) {
TConstruct.log.error(
"Proxy.init has to be called during Initialisation.");
}
}
public void postInit() {
if(!Loader.instance().isInState(LoaderState.POSTINITIALIZATION)) {
TConstruct.log.error(
"Proxy.postInit has to be called during Post-Initialisation.");
}
}
public void registerModels() {
if(Loader.instance().hasReachedState(LoaderState.INITIALIZATION)) {
TConstruct.log.error(
"Proxy.registerModels has to be called during preInit. Otherwise the models wont be found on first load.");
}
}
public void sendPacketToServerOnly(AbstractPacket packet) {
}
public void spawnAttackParticle(Particles particleType, Entity entity, double height) {
float distance = 0.017453292f;
double xd = -MathHelper.sin(entity.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entity.rotationPitch / 180.0F * (float) Math.PI);
double zd = +MathHelper.cos(entity.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(entity.rotationPitch / 180.0F * (float) Math.PI);
double yd = -MathHelper.sin(entity.rotationPitch / 180.0F * (float) Math.PI);
distance = 1f;
xd *= distance;
yd *= distance;
zd *= distance;
//double xd = (double)(-MathHelper.sin(entity.rotationYaw * distance));
//double zd = (double)MathHelper.cos(entity.rotationYaw * distance);
//double yd = (double)(-MathHelper.sin(entity.rotationPitch * distance));
spawnParticle(particleType,
entity.getEntityWorld(),
entity.posX + xd,
entity.posY + entity.height * height,
entity.posZ + zd,
xd, yd, zd);
}
public void spawnEffectParticle(ParticleEffect.Type type, Entity entity, int count) {
spawnParticle(Particles.EFFECT, entity.getEntityWorld(), entity.posX, entity.posY + entity.height * 0.5f, entity.posZ, 0d, 1d, 0d, count, type.ordinal());
}
public void spawnEffectParticle(ParticleEffect.Type type, World world, double x, double y, double z, int count) {
spawnParticle(Particles.EFFECT, world, x, y, z, 0d, -1d, 0d, count, type.ordinal());
}
public void spawnParticle(Particles particleType, World world, double x, double y, double z, int... data) {
spawnParticle(particleType, world, x, y, z, 0d, 0d, 0d, data);
}
public void spawnParticle(Particles particleType, World world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, int... data) {
// 32*32 = 1024 = vanilla particle range
NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(world.provider.getDimension(), x, y, z, 32);
AbstractPacket packet = new SpawnParticlePacket(particleType, x, y, z, xSpeed, ySpeed, zSpeed, data);
TinkerNetwork.sendToAllAround(packet, point);
}
public void spawnSlimeParticle(World world, double x, double y, double z) {
}
public void registerFluidModels(Fluid fluid) {
}
public void preventPlayerSlowdown(Entity player, float originalSpeed, Item item) {
// clientside only
}
// replicates the World.newExplosion code to separate behaviour on server/client for any explosion implementation
public void customExplosion(World world, Explosion explosion) {
// server side
if(net.minecraftforge.event.ForgeEventFactory.onExplosionStart(world, explosion)) {
return;
}
explosion.doExplosionA();
explosion.doExplosionB(false);
if(!explosion.damagesTerrain) {
explosion.clearAffectedBlockPositions();
}
// todo: send custom explosion packet to clients
// Send packets so player are moved around
/*
for (EntityPlayer entityplayer : world.playerEntities)
{
//if (entityplayer.getDistanceSq(x, y, z) < 4096.0D)
{
Vec3d vec = explosion.getPosition();
((EntityPlayerMP)entityplayer).playerNetServerHandler.sendPacket(new SPacketExplosion(vec.xCoord, vec.yCoord, vec.zCoord, 1, explosion.getAffectedBlockPositions(), (Vec3d)explosion.getPlayerKnockbackMap().get(entityplayer)));
}
}*/
}
public void updateEquippedItemForRendering(EnumHand hand) {
}
}