mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-26 05:08:34 +01:00
fixed effect powders not being visible to clients
This commit is contained in:
parent
e539a3c808
commit
204007cfd7
1 changed files with 36 additions and 36 deletions
|
@ -35,6 +35,8 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING);
|
private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING);
|
||||||
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
||||||
private static final DataParameter<Integer> AMOUNT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
private static final DataParameter<Integer> AMOUNT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
||||||
|
private ResourceLocation lastEffect;
|
||||||
|
private boolean powderListDirty;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public int renderTicks;
|
public int renderTicks;
|
||||||
|
@ -56,13 +58,14 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
@Override
|
@Override
|
||||||
public void onAddedToWorld() {
|
public void onAddedToWorld() {
|
||||||
super.onAddedToWorld();
|
super.onAddedToWorld();
|
||||||
this.addToPowderList();
|
this.powderListDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemovedFromWorld() {
|
public void onRemovedFromWorld() {
|
||||||
this.removeFromPowderList();
|
|
||||||
super.onRemovedFromWorld();
|
super.onRemovedFromWorld();
|
||||||
|
this.setInhibitedEffect(null);
|
||||||
|
this.updatePowderListStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,43 +75,27 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
this.dataManager.register(AMOUNT, 0);
|
this.dataManager.register(AMOUNT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyDataManagerChange(DataParameter<?> key) {
|
||||||
|
super.notifyDataManagerChange(key);
|
||||||
|
if (INHIBITED_EFFECT.equals(key) || AMOUNT.equals(key))
|
||||||
|
this.powderListDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(double x, double y, double z) {
|
public void setPosition(double x, double y, double z) {
|
||||||
boolean should = x != this.getPosX() || y != this.getPosY() || z != this.getPosZ();
|
if (x != this.getPosX() || y != this.getPosY() || z != this.getPosZ())
|
||||||
if (should)
|
this.powderListDirty = true;
|
||||||
this.removeFromPowderList();
|
|
||||||
super.setPosition(x, y, z);
|
super.setPosition(x, y, z);
|
||||||
if (should)
|
|
||||||
this.addToPowderList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToPowderList() {
|
|
||||||
if (!this.isAddedToWorld() || this.getInhibitedEffect() == null)
|
|
||||||
return;
|
|
||||||
List<Tuple<Vector3d, Integer>> powders = this.getPowderList();
|
|
||||||
powders.add(new Tuple<>(this.getPositionVec(), this.getAmount()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromPowderList() {
|
|
||||||
if (!this.isAddedToWorld() || this.getInhibitedEffect() == null)
|
|
||||||
return;
|
|
||||||
List<Tuple<Vector3d, Integer>> powders = this.getPowderList();
|
|
||||||
Vector3d pos = this.getPositionVec();
|
|
||||||
for (int i = 0; i < powders.size(); i++)
|
|
||||||
if (pos.equals(powders.get(i).getA())) {
|
|
||||||
powders.remove(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Tuple<Vector3d, Integer>> getPowderList() {
|
|
||||||
ListMultimap<ResourceLocation, Tuple<Vector3d, Integer>> powders = ((WorldData) IWorldData.getWorldData(this.world)).effectPowders;
|
|
||||||
return powders.get(this.getInhibitedEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
|
||||||
|
if (this.powderListDirty)
|
||||||
|
this.updatePowderListStatus();
|
||||||
|
|
||||||
if (this.world.isRemote) {
|
if (this.world.isRemote) {
|
||||||
if (this.world.getGameTime() % 5 == 0) {
|
if (this.world.getGameTime() % 5 == 0) {
|
||||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||||
|
@ -170,9 +157,7 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInhibitedEffect(ResourceLocation effect) {
|
public void setInhibitedEffect(ResourceLocation effect) {
|
||||||
this.removeFromPowderList();
|
this.dataManager.set(INHIBITED_EFFECT, effect != null ? effect.toString() : null);
|
||||||
this.dataManager.set(INHIBITED_EFFECT, effect.toString());
|
|
||||||
this.addToPowderList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColor() {
|
public int getColor() {
|
||||||
|
@ -188,9 +173,7 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmount(int amount) {
|
public void setAmount(int amount) {
|
||||||
this.removeFromPowderList();
|
|
||||||
this.dataManager.set(AMOUNT, amount);
|
this.dataManager.set(AMOUNT, amount);
|
||||||
this.addToPowderList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -204,4 +187,21 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
||||||
public int getVisualizationColor(World world, BlockPos pos) {
|
public int getVisualizationColor(World world, BlockPos pos) {
|
||||||
return this.getColor();
|
return this.getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updatePowderListStatus() {
|
||||||
|
ListMultimap<ResourceLocation, Tuple<Vector3d, Integer>> powders = ((WorldData) IWorldData.getWorldData(this.world)).effectPowders;
|
||||||
|
if (this.lastEffect != null) {
|
||||||
|
List<Tuple<Vector3d, Integer>> oldList = powders.get(this.lastEffect);
|
||||||
|
oldList.removeIf(t -> this.getPositionVec().equals(t.getA()));
|
||||||
|
System.out.println("Removing from old list with effect " + this.lastEffect);
|
||||||
|
}
|
||||||
|
ResourceLocation effect = this.getInhibitedEffect();
|
||||||
|
if (effect != null) {
|
||||||
|
List<Tuple<Vector3d, Integer>> newList = powders.get(effect);
|
||||||
|
newList.add(new Tuple<>(this.getPositionVec(), this.getAmount()));
|
||||||
|
System.out.println("Adding to new list with effect " + effect);
|
||||||
|
}
|
||||||
|
this.powderListDirty = false;
|
||||||
|
this.lastEffect = effect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue