Skip to content

Commit

Permalink
Fixed a few bugs
Browse files Browse the repository at this point in the history
* Nether spawn now hopefully works as in the 1.16.1 version again
* Nether spawn now no longer prevents players from choosing origins of additional layers
* Players are now invulnerable while choosing origins
  • Loading branch information
apace100 committed Aug 12, 2020
1 parent 5e1eaaf commit d862913
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.9.1+build.205

# Mod Properties
mod_version = 1.16.2-0.3.5
mod_version = 1.16.2-0.3.6
maven_group = io.github.apace100.origins
archives_base_name = Origins

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/github/apace100/origins/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package io.github.apace100.origins.mixin;

import io.github.apace100.origins.component.OriginComponent;
import io.github.apace100.origins.power.InvulnerablePower;
import io.github.apace100.origins.power.PowerTypes;
import io.github.apace100.origins.registry.ModComponents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -11,6 +16,16 @@
@Mixin(Entity.class)
public class EntityMixin {

@Inject(at = @At("HEAD"), method = "isInvulnerableTo", cancellable = true)
private void makeOriginInvulnerable(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
if((Object)this instanceof PlayerEntity) {
OriginComponent component = ModComponents.ORIGIN.get(this);
if(component.getPowers(InvulnerablePower.class).stream().anyMatch(inv -> inv.doesApply(damageSource))) {
cir.setReturnValue(true);
}
}
}

@Inject(at = @At("HEAD"), method = "isInvisible", cancellable = true)
private void phantomInvisibility(CallbackInfoReturnable<Boolean> info) {
if(PowerTypes.INVISIBILITY.isActive((Entity)(Object)this) && PowerTypes.INVISIBILITY.get((Entity)(Object)this).isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ private void preventStatusEffects(StatusEffectInstance effect, CallbackInfoRetur
}
}

// FIRE_IMMUNITY & FALL_IMMUNITY
@Inject(at = @At("HEAD"), method = "damage", cancellable = true)
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) {
if(source.isFire() && PowerTypes.FIRE_IMMUNITY.isActive(this)) {
info.setReturnValue(false);
}
if(source == DamageSource.FALL && PowerTypes.FALL_IMMUNITY.isActive(this)) {
info.setReturnValue(false);
}
}

@ModifyVariable(method = "damage", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;despawnCounter:I"), ordinal = 0, argsOnly = true)
private float modifyDamageAmount(float originalAmount, DamageSource source, float amount) {
if((Object)this instanceof PlayerEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public abstract class LoginMixin {

@Inject(at = @At("TAIL"), method = "Lnet/minecraft/server/PlayerManager;onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V")
private void openOriginsGui(ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
OriginComponent component = ModComponents.ORIGIN.get(player);

PacketByteBuf originListData = new PacketByteBuf(Unpooled.buffer());
originListData.writeInt(OriginRegistry.size() - 1);
OriginRegistry.entries().forEach((entry) -> {
Expand All @@ -40,12 +42,17 @@ private void openOriginsGui(ClientConnection connection, ServerPlayerEntity play
originLayerData.writeInt(OriginLayers.size());
OriginLayers.getLayers().forEach((layer) -> {
layer.write(originLayerData);
if(layer.isEnabled()) {
if(!component.hasOrigin(layer)) {
component.setOrigin(layer, Origin.EMPTY);
}
}
});
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, ModPackets.LAYER_LIST, originLayerData);
List<ServerPlayerEntity> playerList = getPlayerList();
playerList.forEach(spe -> ModComponents.ORIGIN.get(spe).syncWith(player));
OriginComponent.sync(player);
if(!ModComponents.ORIGIN.get(player).hasAllOrigins()) {
if(!component.hasAllOrigins()) {
PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
data.writeBoolean(true);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, ModPackets.OPEN_ORIGIN_SCREEN, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ public static void register() {
Origin origin = OriginRegistry.get(id);
if(origin.isChoosable() && layer.contains(origin)) {
boolean hadOriginBefore = component.hadOriginBefore();
boolean hadAllOrigins = component.hasAllOrigins();
component.setOrigin(layer, origin);
component.sync();
origin.getPowerTypes().forEach(powerType -> component.getPower(powerType).onChosen(hadOriginBefore));
if(component.hasAllOrigins() && !hadAllOrigins) {
component.getOrigins().values().forEach(o -> {
o.getPowerTypes().forEach(powerType -> component.getPower(powerType).onChosen(hadOriginBefore));
});
}
Origins.LOGGER.info("Player " + player.getDisplayName().asString() + " chose Origin: " + originId + ", for layer: " + layerId);
} else {
Origins.LOGGER.info("Player " + player.getDisplayName().asString() + " tried to choose unchoosable Origin for layer " + layerId + ": " + originId + ".");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/apace100/origins/origin/Origin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gson.JsonParseException;
import io.github.apace100.origins.Origins;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.power.PowerTypes;
import io.github.apace100.origins.registry.ModComponents;
import io.github.apace100.origins.registry.ModRegistries;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -34,7 +35,7 @@ public class Origin {
public static final Origin EMPTY;

static {
EMPTY = register(new Origin(new Identifier(Origins.MODID, "empty"), Items.AIR, Impact.NONE, -1, Integer.MAX_VALUE).setUnchoosable());
EMPTY = register(new Origin(new Identifier(Origins.MODID, "empty"), Items.AIR, Impact.NONE, -1, Integer.MAX_VALUE).add(PowerTypes.INVULNERABILITY).setUnchoosable());
}

public static void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package io.github.apace100.origins.power;

import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;

import java.util.function.Predicate;

public class InvulnerablePower extends Power {

public InvulnerablePower(PowerType<?> type, PlayerEntity player) {
super(type, player);
}
private final Predicate<DamageSource> damageSources;

@Override
public void onAdded() {
player.setInvulnerable(true);
public InvulnerablePower(PowerType<?> type, PlayerEntity player, Predicate<DamageSource> damageSourcePredicate) {
super(type, player);
this.damageSources = damageSourcePredicate;
}

@Override
public void onRemoved() {
player.setInvulnerable(player.isCreative() || player.isSpectator());
public boolean doesApply(DamageSource source) {
return damageSources.test(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.Optional;

public class NetherSpawnPower extends Power {

public NetherSpawnPower(PowerType<?> type, PlayerEntity player) {
Expand All @@ -27,7 +29,7 @@ public void onChosen(boolean isOrbOfOrigin) {
Pair<ServerWorld, BlockPos> spawn = getSpawn(false);
if(spawn != null) {
if(!isOrbOfOrigin) {
Vec3d tpPos = Dismounting.method_30769(EntityType.PLAYER, spawn.getLeft(), spawn.getRight(), false);
Vec3d tpPos = Dismounting.method_30769(EntityType.PLAYER, spawn.getLeft(), spawn.getRight(), true);
if(tpPos != null) {
serverPlayer.teleport(spawn.getLeft(), tpPos.x, tpPos.y, tpPos.z, player.pitch, player.yaw);
} else {
Expand Down Expand Up @@ -58,20 +60,20 @@ public Pair<ServerWorld, BlockPos> getSpawn(boolean isSpawnObstructed) {
int center = nether.getDimensionHeight() / 2;
BlockPos.Mutable mutable = spawnToNetherPos.mutableCopy();
mutable.setY(center);
Vec3d tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, false);
Vec3d tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, true);
int range = 64;
for(int dx = -range; dx <= range && tpPos == null; dx++) {
for(int dz = -range; dz <= range && tpPos == null; dz++) {
for(int i = 1; i < iterations; i++) {
mutable.setX(spawnToNetherPos.getX() + dx);
mutable.setZ(spawnToNetherPos.getZ() + dz);
mutable.setY(center + i);
tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, false);
tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, true);
if(tpPos != null) {
break;
}
mutable.setY(center - i);
tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, false);
tpPos = Dismounting.method_30769(EntityType.PLAYER, nether, mutable, true);
if(tpPos != null) {
break;
}
Expand All @@ -89,4 +91,9 @@ public Pair<ServerWorld, BlockPos> getSpawn(boolean isSpawnObstructed) {
}
return null;
}

private Optional<Vec3d> getValidPosition(World world, BlockPos pos) {
Vec3d p = Dismounting.method_30769(EntityType.PLAYER, world, pos, false);
return Optional.of(p);
}
}
10 changes: 5 additions & 5 deletions src/main/java/io/github/apace100/origins/power/PowerTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PowerTypes {
public static final PowerType<PreventItemUsePower> CARNIVORE;
public static final PowerType<SetEntityGroupPower> ARTHROPOD;

public static final PowerType<Power> FIRE_IMMUNITY;
public static final PowerType<InvulnerablePower> FIRE_IMMUNITY;
public static final PowerType<NetherSpawnPower> NETHER_SPAWN;
public static final PowerType<ModifyDamageDealtPower> BURNING_WRATH;
public static final PowerType<WaterVulnerabilityPower> WATER_VULNERABILITY;
Expand All @@ -59,7 +59,7 @@ public class PowerTypes {
public static final PowerType<TogglePower> BURN_IN_DAYLIGHT;
public static final PowerType<ModelTranslucencyPower> TRANSLUCENT;

public static final PowerType<Power> FALL_IMMUNITY;
public static final PowerType<InvulnerablePower> FALL_IMMUNITY;
public static final PowerType<Power> SPRINT_JUMP;
public static final PowerType<Power> WEAK_ARMS;
public static final PowerType<Power> SCARE_CREEPERS;
Expand Down Expand Up @@ -89,7 +89,7 @@ public class PowerTypes {
public static final PowerType<PreventItemUsePower> NO_RANGED_WEAPONS;

static {
INVULNERABILITY = register("invulnerability", new PowerType<>(InvulnerablePower::new));
INVULNERABILITY = register("invulnerability", new PowerType<>((type, player) -> new InvulnerablePower(type, player, ds -> true)));

WATER_BREATHING = register("water_breathing", new PowerType<>(Power::new));
AQUA_AFFINITY = register("aqua_affinity", new PowerType<>(Power::new));
Expand All @@ -105,7 +105,7 @@ public class PowerTypes {
CARNIVORE = register("carnivore", new PowerType<>((type, player) -> new PreventItemUsePower(type, player, (stack -> stack.isFood() && !(stack.getItem().getFoodComponent().isMeat() || stack.getItem().isIn(ModTags.MEAT))))));
ARTHROPOD = register("arthropod", new PowerType<>((type, player) -> new SetEntityGroupPower(type, player, EntityGroup.ARTHROPOD)).setHidden());

FIRE_IMMUNITY = register("fire_immunity", new PowerType<>(Power::new));
FIRE_IMMUNITY = register("fire_immunity", new PowerType<>((type, player) -> new InvulnerablePower(type, player, DamageSource::isFire)));
NETHER_SPAWN = register("nether_spawn", new PowerType<>(NetherSpawnPower::new));
BURNING_WRATH = register("burning_wrath", new PowerType<>((type, player) -> new ModifyDamageDealtPower(type, player, (p, s) -> p.isOnFire(), dmg -> dmg + 3.0F)));
WATER_VULNERABILITY = register("water_vulnerability", new PowerType<>((type, player) -> new WaterVulnerabilityPower(type, player, 20, 0,20)));
Expand All @@ -123,7 +123,7 @@ public class PowerTypes {
BURN_IN_DAYLIGHT = register("burn_in_daylight", new PowerType<>((type, player) -> new TogglePower(type, player, true)));
TRANSLUCENT = register("translucent", new PowerType<>((type, player) -> new ModelTranslucencyPower(type, player, 0.5F)));

FALL_IMMUNITY = register("fall_immunity", new PowerType<>(Power::new));
FALL_IMMUNITY = register("fall_immunity", new PowerType<>((type, player) -> new InvulnerablePower(type, player, ds -> ds == DamageSource.FALL)));
SPRINT_JUMP = register("sprint_jump", new PowerType<>(Power::new));
WEAK_ARMS = register("weak_arms", new PowerType<>(Power::new));
SCARE_CREEPERS = register("scare_creepers", new PowerType<>(Power::new));
Expand Down

0 comments on commit d862913

Please sign in to comment.