Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
apace100 committed Oct 22, 2020
2 parents 085e955 + 56722a7 commit ba0badb
Show file tree
Hide file tree
Showing 39 changed files with 1,116 additions and 90 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.9.3+build.207

# Mod Properties
mod_version = 1.16.3-0.4.0
mod_version = 0.4.1
maven_group = io.github.apace100.origins
archives_base_name = Origins
archives_base_name = Origins-1.16.3

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.20.2+build.402-1.16
cca_version=2.6.0
cca_version=2.7.1
reach_version=1.0.1
ffl_version=1.1.0
autoconfig_version=3.2.2
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/io/github/apace100/origins/Origins.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import io.github.apace100.origins.power.factory.condition.DamageConditions;
import io.github.apace100.origins.power.factory.condition.ItemConditions;
import io.github.apace100.origins.power.factory.condition.PlayerConditions;
import io.github.apace100.origins.power.factory.action.BlockActions;
import io.github.apace100.origins.power.factory.action.EntityActions;
import io.github.apace100.origins.power.factory.action.ItemActions;
import io.github.apace100.origins.registry.*;
import io.github.apace100.origins.util.ChoseOriginCriterion;
import io.github.apace100.origins.util.ElytraPowerFallFlying;
Expand All @@ -37,7 +40,6 @@ public class Origins implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("Origins is initializing. Have fun!");
ModComponents.register();
ModBlocks.register();
ModItems.register();
ModTags.register();
Expand All @@ -50,6 +52,9 @@ public void onInitialize() {
ItemConditions.register();
BlockConditions.register();
DamageConditions.register();
EntityActions.register();
ItemActions.register();
BlockActions.register();
Origin.init();
FallFlyingLib.registerAccessor((le) -> new ElytraPowerFallFlying(le));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.apace100.origins.component;

import com.google.common.collect.Lists;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import dev.onyxstudios.cca.api.v3.component.tick.ServerTickingComponent;
import io.github.apace100.origins.origin.Origin;
import io.github.apace100.origins.origin.OriginLayer;
import io.github.apace100.origins.power.Power;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.power.ValueModifyingPower;
import io.github.apace100.origins.registry.ModComponents;
import nerdhub.cardinal.components.api.util.sync.EntitySyncedComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -17,7 +18,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

public interface OriginComponent extends EntitySyncedComponent {
public interface OriginComponent extends AutoSyncedComponent, ServerTickingComponent {

boolean hasOrigin(OriginLayer layer);
boolean hasAllOrigins();
Expand All @@ -35,8 +36,10 @@ public interface OriginComponent extends EntitySyncedComponent {

void setOrigin(OriginLayer layer, Origin origin);

void sync();

static void sync(PlayerEntity player) {
ModComponents.ORIGIN.get(player).sync();
ModComponents.ORIGIN.sync(player);
}

static <T extends Power> List<T> getPowers(Entity entity, Class<T> powerClass) {
Expand Down Expand Up @@ -80,7 +83,7 @@ static <T extends ValueModifyingPower> double modify(Entity entity, Class<T> pow
currentValue += baseValue * modifier.getValue();
break;
case MULTIPLY_TOTAL:
currentValue *= modifier.getValue();
currentValue *= (1 + modifier.getValue());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import io.github.apace100.origins.origin.OriginLayer;
import io.github.apace100.origins.origin.OriginLayers;
import io.github.apace100.origins.origin.OriginRegistry;
import io.github.apace100.origins.power.Power;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.power.PowerTypeRegistry;
import io.github.apace100.origins.registry.ModComponents;
import nerdhub.cardinal.components.api.ComponentType;
import net.minecraft.entity.Entity;
import io.github.apace100.origins.power.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand Down Expand Up @@ -144,7 +139,24 @@ public void setOrigin(OriginLayer layer, Origin origin) {
}

@Override
public void fromTag(CompoundTag compoundTag) {
public void serverTick() {
this.getPowers(Power.class, true).stream().filter(p -> p.shouldTick() && (p.shouldTickWhenInactive() || p.isActive())).forEach(Power::tick);
/*this.getPowers(WaterVulnerabilityPower.class).forEach(waterCounter -> {
if(this.getFluidHeight(FluidTags.WATER) > 0 || this.isRainingAtPlayerPosition() || this.isSubmergedInWater()) {
//if(this.isWet()) {
waterCounter.inWater();
} else {
waterCounter.outOfWater();
}
});*/
if(this.player.age % 10 == 0) {
this.getPowers(SimpleStatusEffectPower.class).forEach(SimpleStatusEffectPower::applyEffects);
this.getPowers(StackingStatusEffectPower.class, true).forEach(StackingStatusEffectPower::tick);
}
}

@Override
public void readFromNbt(CompoundTag compoundTag) {
this.fromTag(compoundTag, true);
}

Expand Down Expand Up @@ -205,15 +217,20 @@ private void fromTag(CompoundTag compoundTag, boolean callPowerOnAdd) {
ListTag powerList = (ListTag)compoundTag.get("Powers");
for(int i = 0; i < powerList.size(); i++) {
CompoundTag powerTag = powerList.getCompound(i);
PowerType<?> type = PowerTypeRegistry.get(Identifier.tryParse(powerTag.getString("Type")));
if(hasPowerType(type)) {
Tag data = powerTag.get("Data");
Power power = type.create(player);
power.fromTag(data);
this.powers.put(type, power);
if(callPowerOnAdd) {
power.onAdded();
Identifier powerTypeId = Identifier.tryParse(powerTag.getString("Type"));
try {
PowerType<?> type = PowerTypeRegistry.get(powerTypeId);
if(hasPowerType(type)) {
Tag data = powerTag.get("Data");
Power power = type.create(player);
power.fromTag(data);
this.powers.put(type, power);
if(callPowerOnAdd) {
power.onAdded();
}
}
} catch(IllegalArgumentException e) {
Origins.LOGGER.warn("Power data of unregistered power \"" + powerTypeId + "\" found on player, skipping...");
}
}
this.getPowerTypes().forEach(pt -> {
Expand All @@ -225,7 +242,7 @@ private void fromTag(CompoundTag compoundTag, boolean callPowerOnAdd) {
}

@Override
public CompoundTag toTag(CompoundTag compoundTag) {
public void writeToNbt(CompoundTag compoundTag) {
ListTag originLayerList = new ListTag();
for(Map.Entry<OriginLayer, Origin> entry : origins.entrySet()) {
CompoundTag layerTag = new CompoundTag();
Expand All @@ -243,25 +260,19 @@ public CompoundTag toTag(CompoundTag compoundTag) {
powerList.add(powerTag);
}
compoundTag.put("Powers", powerList);
return compoundTag;
}

@Override
public void readFromPacket(PacketByteBuf buf) {
public void applySyncPacket(PacketByteBuf buf) {
CompoundTag compoundTag = buf.readCompoundTag();
if(compoundTag != null) {
this.fromTag(compoundTag, false);
}
}

@Override
public Entity getEntity() {
return this.player;
}

@Override
public ComponentType<?> getComponentType() {
return ModComponents.ORIGIN;
public void sync() {
OriginComponent.sync(this.player);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
Expand Down Expand Up @@ -37,6 +38,16 @@ private void modifyWalkableFluids(Fluid fluid, CallbackInfoReturnable<Boolean> i
//}
}

@Inject(method = "damage", at = @At("RETURN"))
private void invokeHitActions(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if(cir.getReturnValue()) {
OriginComponent.getPowers(this, SelfActionWhenHitPower.class).forEach(p -> p.whenHit(source, amount));
OriginComponent.getPowers(this, AttackerActionWhenHitPower.class).forEach(p -> p.whenHit(source, amount));
OriginComponent.getPowers(source.getAttacker(), SelfActionOnHitPower.class).forEach(p -> p.onHit((LivingEntity)(Object)this, source, amount));
OriginComponent.getPowers(source.getAttacker(), TargetActionOnHitPower.class).forEach(p -> p.onHit((LivingEntity)(Object)this, source, amount));
}
}

// ModifyLavaSpeedPower
@ModifyConstant(method = "travel", constant = {
@Constant(doubleValue = 0.5D, ordinal = 0),
Expand All @@ -55,7 +66,7 @@ public void getGroup(CallbackInfoReturnable<EntityGroup> info) {
List<SetEntityGroupPower> groups = component.getPowers(SetEntityGroupPower.class);
if(groups.size() > 0) {
if(groups.size() > 1) {
Origins.LOGGER.warn("Player " + this.getDisplayName().toString() + " had two instances of SetEntityGroupPower.");
Origins.LOGGER.warn("Player " + this.getDisplayName().toString() + " has two instances of SetEntityGroupPower.");
}
info.setReturnValue(groups.get(0).group);
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/io/github/apace100/origins/mixin/LoginMixin.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
package io.github.apace100.origins.mixin;

import dev.onyxstudios.cca.api.v3.component.ComponentProvider;
import io.github.apace100.origins.component.OriginComponent;
import io.github.apace100.origins.networking.ModPackets;
import io.github.apace100.origins.origin.Origin;
import io.github.apace100.origins.origin.OriginLayers;
import io.github.apace100.origins.origin.OriginRegistry;
import io.github.apace100.origins.power.NetherSpawnPower;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.power.PowerTypeRegistry;
import io.github.apace100.origins.power.factory.PowerFactory;
import io.github.apace100.origins.registry.ModComponents;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.entity.Dismounting;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Optional;

@Mixin(PlayerManager.class)
public abstract class LoginMixin {

@Shadow public abstract List<ServerPlayerEntity> getPlayerList();

@Shadow @Final private MinecraftServer server;

@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);
Expand Down Expand Up @@ -71,12 +85,23 @@ private void openOriginsGui(ClientConnection connection, ServerPlayerEntity play
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, ModPackets.LAYER_LIST, originLayerData);

List<ServerPlayerEntity> playerList = getPlayerList();
playerList.forEach(spe -> ModComponents.ORIGIN.get(spe).syncWith(player));
playerList.forEach(spe -> ModComponents.ORIGIN.syncWith(spe, ComponentProvider.fromEntity(player)));
OriginComponent.sync(player);
if(!component.hasAllOrigins()) {
PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
data.writeBoolean(true);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, ModPackets.OPEN_ORIGIN_SCREEN, data);
}
}

@Redirect(method = "respawnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;findRespawnPosition(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;FZZ)Ljava/util/Optional;"))
private Optional<Vec3d> retryObstructedSpawnpointIfFailed(ServerWorld world, BlockPos pos, float f, boolean bl, boolean bl2, ServerPlayerEntity player, boolean alive) {
Optional<Vec3d> original = PlayerEntity.findRespawnPosition(world, pos, f, bl, bl2);
if(!original.isPresent()) {
if(OriginComponent.hasPower(player, NetherSpawnPower.class)) {
return Optional.ofNullable(Dismounting.method_30769(EntityType.PLAYER, world, pos, bl));
}
}
return original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,9 @@ private void preventArmorDispensing(ItemStack stack, CallbackInfoReturnable<Bool
}
}

// HUNGER_OVER_TIME & BURN_IN_DAYLIGHT
// WATER_BREATHING & WATER_VULNERABILITY
// PARTICLES & EXHAUSTING_WATER_BREATHING
// WATER_BREATHING
@Inject(at = @At("TAIL"), method = "tick")
private void tick(CallbackInfo info) {
if(!world.isClient) {
OriginComponent component = ModComponents.ORIGIN.get(this);
component.getPowers(Power.class, true).stream().filter(p -> p.shouldTick() && (p.shouldTickWhenInactive() || p.isActive())).forEach(Power::tick);
/*component.getPowers(WaterVulnerabilityPower.class).forEach(waterCounter -> {
if(this.getFluidHeight(FluidTags.WATER) > 0 || this.isRainingAtPlayerPosition() || this.isSubmergedInWater()) {
//if(this.isWet()) {
waterCounter.inWater();
} else {
waterCounter.outOfWater();
}
});*/
if(this.age % 10 == 0) {
component.getPowers(SimpleStatusEffectPower.class).forEach(SimpleStatusEffectPower::applyEffects);
component.getPowers(StackingStatusEffectPower.class, true).forEach(StackingStatusEffectPower::tick);
}
}

if(PowerTypes.WATER_BREATHING.isActive(this)) {
if(!this.isSubmergedIn(FluidTags.WATER) && !this.hasStatusEffect(StatusEffects.WATER_BREATHING) && !this.hasStatusEffect(StatusEffects.CONDUIT_POWER)) {
if(!this.isRainingAtPlayerPosition()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void preventAvianSleep(BlockPos pos, CallbackInfoReturnable<Either<Player

@Inject(at = @At("HEAD"), method = "getSpawnPointDimension", cancellable = true)
private void modifyBlazebornSpawnDimension(CallbackInfoReturnable<RegistryKey<World>> info) {
if ((spawnPointPosition == null || hasObstructedSpawn()) && OriginComponent.getPowers(this, NetherSpawnPower.class).size() > 0) {
if ((spawnPointPosition == null || hasObstructedSpawn()) && OriginComponent.hasPower(this, NetherSpawnPower.class)) {
info.setReturnValue(World.NETHER);
}
}
Expand All @@ -90,7 +90,7 @@ private void modifyBlazebornSpawnPosition(CallbackInfoReturnable<BlockPos> info)

@Inject(at = @At("HEAD"), method = "isSpawnPointSet", cancellable = true)
private void modifyBlazebornSpawnPointSet(CallbackInfoReturnable<Boolean> info) {
if((spawnPointPosition == null || hasObstructedSpawn()) && OriginComponent.getPowers(this, NetherSpawnPower.class).size() > 0) {
if((spawnPointPosition == null || hasObstructedSpawn()) && OriginComponent.hasPower(this, NetherSpawnPower.class)) {
info.setReturnValue(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.apace100.origins.component.OriginComponent;
import io.github.apace100.origins.power.ModifyHarvestPower;
import net.minecraft.block.pattern.CachedBlockPosition;
import io.github.apace100.origins.util.SavedBlockPosition;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -19,20 +19,21 @@ public class ServerPlayerInteractionManagerMixin {

@Shadow public ServerWorld world;
@Shadow public ServerPlayerEntity player;
private CachedBlockPosition cachedBlockPosition;
private SavedBlockPosition savedBlockPosition;

@Inject(method = "tryBreakBlock", at = @At("HEAD"))
private void cacheBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
this.cachedBlockPosition = new CachedBlockPosition(world, pos, true);
this.savedBlockPosition = new SavedBlockPosition(world, pos);
}

@ModifyVariable(method = "tryBreakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;postMine(Lnet/minecraft/world/World;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;)V"), ordinal = 1)
private boolean modifyEffectiveTool(boolean original) {
for (ModifyHarvestPower mhp : OriginComponent.getPowers(player, ModifyHarvestPower.class)) {
if (mhp.doesApply(cachedBlockPosition)) {
if (mhp.doesApply(savedBlockPosition)) {
return mhp.isHarvestAllowed();
}
}
return original;
}

}
Loading

0 comments on commit ba0badb

Please sign in to comment.