-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.20.1' into 1.20.1
- Loading branch information
Showing
225 changed files
with
4,404 additions
and
1,563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fusionflux/portalcubed/advancements/PortalCubedAdvancements.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.fusionflux.portalcubed.advancements; | ||
|
||
import com.fusionflux.portalcubed.advancements.conditions.PortalCubedConditions; | ||
import com.fusionflux.portalcubed.advancements.predicates.PortalCubedPredicates; | ||
import com.fusionflux.portalcubed.advancements.triggers.PortalCubedTriggers; | ||
|
||
public class PortalCubedAdvancements { | ||
public static void register() { | ||
PortalCubedConditions.register(); | ||
PortalCubedPredicates.register(); | ||
PortalCubedTriggers.register(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/fusionflux/portalcubed/advancements/conditions/FunnelCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.fusionflux.portalcubed.advancements.conditions; | ||
|
||
import com.fusionflux.portalcubed.accessor.EntityExt; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSerializationContext; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam; | ||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
|
||
public class FunnelCondition implements LootItemCondition { | ||
private final Boolean inFunnel; | ||
private final Boolean inCfg; | ||
|
||
public FunnelCondition(Boolean inFunnel, Boolean inCfg) { | ||
this.inFunnel = inFunnel; | ||
this.inCfg = inCfg; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public LootItemConditionType getType() { | ||
return PortalCubedConditions.FUNNEL; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Set<LootContextParam<?>> getReferencedContextParams() { | ||
return ImmutableSet.of(LootContextParams.THIS_ENTITY); | ||
} | ||
|
||
@Override | ||
public boolean test(LootContext lootContext) { | ||
if (inFunnel != null && ((EntityExt)lootContext.getParam(LootContextParams.THIS_ENTITY)).isInFunnel() != inFunnel) { | ||
return false; | ||
} | ||
//noinspection RedundantIfStatement | ||
if (inCfg != null && ((EntityExt)lootContext.getParam(LootContextParams.THIS_ENTITY)).cfg() != inCfg) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer<FunnelCondition> { | ||
@Override | ||
public void serialize(JsonObject json, FunnelCondition value, JsonSerializationContext serializationContext) { | ||
if (value.inFunnel != null) { | ||
json.addProperty("in_funnel", value.inFunnel); | ||
} | ||
if (value.inCfg != null) { | ||
json.addProperty("in_cfg", value.inCfg); | ||
} | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public FunnelCondition deserialize(JsonObject json, JsonDeserializationContext serializationContext) { | ||
return new FunnelCondition( | ||
getAsOptionalBoolean(json, "in_funnel"), | ||
getAsOptionalBoolean(json, "in_cfg") | ||
); | ||
} | ||
|
||
private static Boolean getAsOptionalBoolean(JsonObject json, String name) { | ||
return json.has(name) ? GsonHelper.convertToBoolean(json.get(name), name) : null; | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/fusionflux/portalcubed/advancements/conditions/LauncherCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.fusionflux.portalcubed.advancements.conditions; | ||
|
||
import com.fusionflux.portalcubed.util.PortalCubedComponents; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSerializationContext; | ||
import net.minecraft.advancements.critereon.DistancePredicate; | ||
import net.minecraft.advancements.critereon.LocationPredicate; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam; | ||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
|
||
public class LauncherCondition implements LootItemCondition { | ||
private final LocationPredicate location; | ||
private final DistancePredicate distance; | ||
|
||
public LauncherCondition(LocationPredicate location, DistancePredicate distance) { | ||
this.location = location; | ||
this.distance = distance; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public LootItemConditionType getType() { | ||
return PortalCubedConditions.LAUNCHER; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Set<LootContextParam<?>> getReferencedContextParams() { | ||
return ImmutableSet.of(LootContextParams.THIS_ENTITY); | ||
} | ||
|
||
@Override | ||
public boolean test(LootContext lootContext) { | ||
final Entity thisEntity = lootContext.getParam(LootContextParams.THIS_ENTITY); | ||
final BlockPos launcher = PortalCubedComponents.ENTITY_COMPONENT.get(thisEntity).getLauncher(); | ||
if (launcher == null) { | ||
return false; | ||
} | ||
if (!location.matches((ServerLevel)thisEntity.level(), launcher.getX() + 0.5, launcher.getY() + 0.5, launcher.getZ() + 0.5)) { | ||
return false; | ||
} | ||
//noinspection RedundantIfStatement | ||
if (!distance.matches( | ||
thisEntity.getX(), thisEntity.getY(), thisEntity.getZ(), | ||
launcher.getX() + 0.5, launcher.getY() + 0.5, launcher.getZ() + 0.5 | ||
)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer<LauncherCondition> { | ||
@Override | ||
public void serialize(JsonObject json, LauncherCondition value, JsonSerializationContext serializationContext) { | ||
if (value.location != LocationPredicate.ANY) { | ||
json.add("location", value.location.serializeToJson()); | ||
} | ||
if (value.distance != DistancePredicate.ANY) { | ||
json.add("distance", value.distance.serializeToJson()); | ||
} | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public LauncherCondition deserialize(JsonObject json, JsonDeserializationContext serializationContext) { | ||
return new LauncherCondition( | ||
LocationPredicate.fromJson(json.get("location")), | ||
DistancePredicate.fromJson(json.get("distance")) | ||
); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/fusionflux/portalcubed/advancements/conditions/PortalCubedConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.fusionflux.portalcubed.advancements.conditions; | ||
|
||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; | ||
|
||
import static com.fusionflux.portalcubed.PortalCubed.id; | ||
|
||
public class PortalCubedConditions { | ||
public static final LootItemConditionType FUNNEL = new LootItemConditionType(new FunnelCondition.Serializer()); | ||
public static final LootItemConditionType LAUNCHER = new LootItemConditionType(new LauncherCondition.Serializer()); | ||
|
||
public static void register() { | ||
Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, id("funnel"), FUNNEL); | ||
Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, id("launcher"), LAUNCHER); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/fusionflux/portalcubed/advancements/predicates/EnergyPelletPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.fusionflux.portalcubed.advancements.predicates; | ||
|
||
import com.fusionflux.portalcubed.entity.EnergyPellet; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.critereon.EntityPredicate; | ||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
import net.minecraft.advancements.critereon.MinMaxBounds; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EnergyPelletPredicate implements EntitySubPredicate { | ||
private final MinMaxBounds.Ints startingLife; | ||
private final MinMaxBounds.Ints life; | ||
private final MinMaxBounds.Ints bounces; | ||
private final EntityPredicate thrower; | ||
|
||
public EnergyPelletPredicate(MinMaxBounds.Ints startingLife, MinMaxBounds.Ints life, MinMaxBounds.Ints bounces, EntityPredicate thrower) { | ||
this.startingLife = startingLife; | ||
this.life = life; | ||
this.bounces = bounces; | ||
this.thrower = thrower; | ||
} | ||
|
||
public static EnergyPelletPredicate fromJson(JsonObject json) { | ||
return new EnergyPelletPredicate( | ||
MinMaxBounds.Ints.fromJson(json.get("starting_life")), | ||
MinMaxBounds.Ints.fromJson(json.get("life")), | ||
MinMaxBounds.Ints.fromJson(json.get("bounces")), | ||
EntityPredicate.fromJson(json.get("thrower")) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean matches(Entity entity, ServerLevel level, @Nullable Vec3 pos) { | ||
if (!(entity instanceof EnergyPellet energyPellet)) { | ||
return false; | ||
} | ||
if (!startingLife.matches(energyPellet.getStartingLife())) { | ||
return false; | ||
} | ||
if (!life.matches(energyPellet.getLife())) { | ||
return false; | ||
} | ||
if (!bounces.matches(energyPellet.getBounces())) { | ||
return false; | ||
} | ||
//noinspection RedundantIfStatement | ||
if (!thrower.matches(level, pos, energyPellet.getThrower())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public JsonObject serializeCustomData() { | ||
final JsonObject result = new JsonObject(); | ||
if (!startingLife.isAny()) { | ||
result.add("starting_life", bounces.serializeToJson()); | ||
} | ||
if (!life.isAny()) { | ||
result.add("life", bounces.serializeToJson()); | ||
} | ||
if (!bounces.isAny()) { | ||
result.add("bounces", bounces.serializeToJson()); | ||
} | ||
if (thrower != EntityPredicate.ANY) { | ||
result.add("thrower", thrower.serializeToJson()); | ||
} | ||
return result; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Type type() { | ||
return PortalCubedPredicates.ENERGY_PELLET; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/fusionflux/portalcubed/advancements/predicates/PortalCubedPredicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.fusionflux.portalcubed.advancements.predicates; | ||
|
||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
|
||
public class PortalCubedPredicates { | ||
public static final EntitySubPredicate.Type ENERGY_PELLET = EnergyPelletPredicate::fromJson; | ||
|
||
public static void register() { | ||
EntitySubPredicate.Types.TYPES.put("portalcubed:energy_pellet", ENERGY_PELLET); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/fusionflux/portalcubed/advancements/triggers/BounceTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.fusionflux.portalcubed.advancements.triggers; | ||
|
||
import com.fusionflux.portalcubed.entity.EnergyPellet; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.critereon.*; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static com.fusionflux.portalcubed.PortalCubed.id; | ||
|
||
public class BounceTrigger extends SimpleCriterionTrigger<BounceTrigger.TriggerInstance> { | ||
public static final ResourceLocation ID = id("bounce"); | ||
|
||
@NotNull | ||
@Override | ||
public ResourceLocation getId() { | ||
return ID; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected TriggerInstance createInstance(JsonObject json, ContextAwarePredicate predicate, DeserializationContext deserializationContext) { | ||
return new TriggerInstance(predicate, EntityPredicate.fromJson(json.get("pellet"))); | ||
} | ||
|
||
public void trigger(ServerPlayer player, EnergyPellet pellet) { | ||
trigger(player, conditions -> conditions.matches(player.serverLevel(), player.position(), pellet)); | ||
} | ||
|
||
public static class TriggerInstance extends AbstractCriterionTriggerInstance { | ||
private final EntityPredicate pellet; | ||
|
||
public TriggerInstance(ContextAwarePredicate player, EntityPredicate pellet) { | ||
super(ID, player); | ||
this.pellet = pellet; | ||
} | ||
|
||
public boolean matches(ServerLevel level, @Nullable Vec3 position, EnergyPellet pellet) { | ||
return this.pellet.matches(level, position, pellet); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public JsonObject serializeToJson(SerializationContext context) { | ||
final JsonObject result = super.serializeToJson(context); | ||
if (pellet != EntityPredicate.ANY) { | ||
result.add("pellet", pellet.serializeToJson()); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.