Skip to content

Commit

Permalink
Fixed drugs affecting unrelated players. Fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 24, 2024
1 parent 233f9b0 commit fabab2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -128,14 +127,11 @@ public <T extends Drug> T getDrug(DrugType<T> type) {
}

public float getDrugValue(DrugType<?> type) {
if (!drugs.containsKey(type)) {
return 0F;
}
return (float) getDrug(type).getActiveValue();
return (float)getDrug(type).getActiveValue();
}

public boolean isDrugActive(DrugType<?> type) {
return drugs.containsKey(type) && getDrugValue(type) > MathHelper.EPSILON;
return getDrugValue(type) > MathHelper.EPSILON;
}

public boolean isTripping() {
Expand Down Expand Up @@ -293,7 +289,6 @@ public void onTick() {
public void sendCapabilities() {
if (!entity.getWorld().isClient) {
Channel.UPDATE_DRUG_PROPERTIES.sendToSurroundingPlayers(new MsgDrugProperties(this, entity.getRegistryManager()), entity);
Channel.UPDATE_DRUG_PROPERTIES.sendToPlayer(new MsgDrugProperties(this, entity.getRegistryManager()), (ServerPlayerEntity)entity);
}
}

Expand Down Expand Up @@ -324,14 +319,14 @@ public void copyFrom(DrugProperties old, boolean alive) {
drugs.putAll(old.drugs);
timeBreathingSmoke = old.timeBreathingSmoke;
breathSmokeColor = old.breathSmokeColor;
dirty = true;
markDirty();
}
}

public boolean onAwoken() {
drugs.values().forEach(drug -> drug.onWakeUp(this));
influences.clear();
dirty = true;
markDirty();

// TODO: (Sollace) Implement longer sleeping/comas
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.function.Function;

import com.mojang.serialization.MapCodec;
Expand Down Expand Up @@ -68,7 +66,7 @@ static <T extends Drug> DrugType<T> register(String name, DrugAttributeFunctions
}

static <T extends Drug> DrugType<T> register(String name, DrugAttributeFunctions functions, Function<DrugType<T>, MapCodec<T>> codec, Function<DrugType<T>, T> constructor) {
DrugType<T> type = new DrugType<>(Psychedelicraft.id(name), Util.memoize(constructor), codec, functions);
DrugType<T> type = new DrugType<>(Psychedelicraft.id(name), constructor, codec, functions);
PSSounds.register("drug." + name);
return Registry.register(REGISTRY, type.id(), type);
}
Expand Down

0 comments on commit fabab2f

Please sign in to comment.