basic advancements done
This commit is contained in:
parent
9f315227ad
commit
a503d51fc8
@ -10,5 +10,7 @@ public class ModCriteria {
|
|||||||
public static final PortalDestroyedTrigger PORTAL_DESTROYED =
|
public static final PortalDestroyedTrigger PORTAL_DESTROYED =
|
||||||
Criteria.register(new PortalDestroyedTrigger());
|
Criteria.register(new PortalDestroyedTrigger());
|
||||||
|
|
||||||
public static void register() {}
|
public static void register() {
|
||||||
|
// classload trigger
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
package net.Chipperfluff.chipi.advancement;
|
package net.Chipperfluff.chipi.advancement;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minecraft.advancement.AdvancementCriterion;
|
|
||||||
import net.minecraft.advancement.criterion.AbstractCriterion;
|
import net.minecraft.advancement.criterion.AbstractCriterion;
|
||||||
import net.minecraft.advancement.criterion.CriterionConditions;
|
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
|
||||||
|
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
|
||||||
|
import net.minecraft.predicate.entity.LootContextPredicate;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.Chipperfluff.chipi.ChipiMod;
|
|
||||||
|
|
||||||
public class PortalActivatedTrigger extends AbstractCriterion<PortalActivatedTrigger.Conditions> {
|
public class PortalActivatedTrigger
|
||||||
|
extends AbstractCriterion<PortalActivatedTrigger.Conditions> {
|
||||||
|
|
||||||
public static final Identifier ID =
|
public static final Identifier ID =
|
||||||
new Identifier(ChipiMod.MOD_ID, "portal_activated");
|
new Identifier("chipi", "portal_activated");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getId() {
|
public Identifier getId() {
|
||||||
@ -19,21 +20,21 @@ public class PortalActivatedTrigger extends AbstractCriterion<PortalActivatedTri
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Conditions conditionsFromJson(
|
public Conditions conditionsFromJson(
|
||||||
JsonObject obj,
|
JsonObject json,
|
||||||
net.minecraft.advancement.criterion.CriterionConditionsParser parser
|
LootContextPredicate player,
|
||||||
|
AdvancementEntityPredicateDeserializer deserializer
|
||||||
) {
|
) {
|
||||||
return new Conditions();
|
return new Conditions(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(ServerPlayerEntity player) {
|
public void trigger(ServerPlayerEntity player) {
|
||||||
this.trigger(player, conditions -> true);
|
this.trigger(player, conditions -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= CONDITIONS =================
|
public static class Conditions extends AbstractCriterionConditions {
|
||||||
public static class Conditions extends CriterionConditions {
|
public Conditions(LootContextPredicate player) {
|
||||||
public Conditions() {
|
super(ID, player);
|
||||||
super(ID, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
package net.Chipperfluff.chipi.advancement;
|
package net.Chipperfluff.chipi.advancement;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minecraft.advancement.AdvancementCriterion;
|
|
||||||
import net.minecraft.advancement.criterion.AbstractCriterion;
|
import net.minecraft.advancement.criterion.AbstractCriterion;
|
||||||
import net.minecraft.advancement.criterion.CriterionConditions;
|
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
|
||||||
|
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
|
||||||
|
import net.minecraft.predicate.entity.LootContextPredicate;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.Chipperfluff.chipi.ChipiMod;
|
import net.minecraft.world.BlockView;
|
||||||
|
|
||||||
public class PortalDestroyedTrigger extends AbstractCriterion<PortalDestroyedTrigger.Conditions> {
|
public class PortalDestroyedTrigger
|
||||||
|
extends AbstractCriterion<PortalDestroyedTrigger.Conditions> {
|
||||||
|
|
||||||
public static final Identifier ID =
|
public static final Identifier ID =
|
||||||
new Identifier(ChipiMod.MOD_ID, "portal_destroyed");
|
new Identifier("chipi", "portal_destroyed");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getId() {
|
public Identifier getId() {
|
||||||
@ -19,21 +21,21 @@ public class PortalDestroyedTrigger extends AbstractCriterion<PortalDestroyedTri
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Conditions conditionsFromJson(
|
public Conditions conditionsFromJson(
|
||||||
JsonObject obj,
|
JsonObject json,
|
||||||
net.minecraft.advancement.criterion.CriterionConditionsParser parser
|
LootContextPredicate player,
|
||||||
|
AdvancementEntityPredicateDeserializer deserializer
|
||||||
) {
|
) {
|
||||||
return new Conditions();
|
return new Conditions(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(ServerPlayerEntity player) {
|
public void trigger(ServerPlayerEntity player) {
|
||||||
this.trigger(player, conditions -> true);
|
this.trigger(player, conditions -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= CONDITIONS =================
|
public static class Conditions extends AbstractCriterionConditions {
|
||||||
public static class Conditions extends CriterionConditions {
|
public Conditions(LootContextPredicate player) {
|
||||||
public Conditions() {
|
super(ID, player);
|
||||||
super(ID, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,13 +4,11 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.PillarBlock;
|
import net.minecraft.block.PillarBlock;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.Chipperfluff.chipi.advancement.ModCriteria;
|
||||||
|
|
||||||
public class ChipperFrameBlock extends PillarBlock {
|
public class ChipperFrameBlock extends PillarBlock {
|
||||||
|
|
||||||
@ -19,20 +17,13 @@ public class ChipperFrameBlock extends PillarBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult onUse(
|
public void onPlaced(
|
||||||
BlockState state,
|
|
||||||
World world,
|
World world,
|
||||||
BlockPos pos,
|
BlockPos pos,
|
||||||
PlayerEntity player,
|
BlockState state,
|
||||||
Hand hand,
|
LivingEntity placer,
|
||||||
BlockHitResult hit
|
ItemStack stack
|
||||||
) {
|
) {
|
||||||
return ActionResult.PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlaced(World world, BlockPos pos, BlockState state,
|
|
||||||
LivingEntity placer, ItemStack stack) {
|
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
ChipperPortalShape.tryCreate(world, pos);
|
ChipperPortalShape.tryCreate(world, pos);
|
||||||
}
|
}
|
||||||
@ -46,9 +37,19 @@ public class ChipperFrameBlock extends PillarBlock {
|
|||||||
BlockState newState,
|
BlockState newState,
|
||||||
boolean moved
|
boolean moved
|
||||||
) {
|
) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient && state.getBlock() != newState.getBlock()) {
|
||||||
|
// destroy portal
|
||||||
ChipperPortalShape.destroyNearby(world, pos);
|
ChipperPortalShape.destroyNearby(world, pos);
|
||||||
|
|
||||||
|
// advancement trigger
|
||||||
|
if (world.getClosestPlayer(
|
||||||
|
pos.getX(), pos.getY(), pos.getZ(),
|
||||||
|
10, false
|
||||||
|
) instanceof ServerPlayerEntity serverPlayer) {
|
||||||
|
ModCriteria.PORTAL_DESTROYED.trigger(serverPlayer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onBroken(world, pos, state);
|
|
||||||
|
super.onStateReplaced(state, world, pos, newState, moved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraft.world.TeleportTarget;
|
import net.minecraft.world.TeleportTarget;
|
||||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import net.Chipperfluff.chipi.advancement.ModCriteria;
|
|
||||||
|
|
||||||
public class ChipperPortalBlock extends Block {
|
public class ChipperPortalBlock extends Block {
|
||||||
|
|
||||||
@ -78,7 +77,6 @@ public class ChipperPortalBlock extends Block {
|
|||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
return 0.0F; // impossible to break
|
return 0.0F; // impossible to break
|
||||||
}
|
}
|
||||||
ModCriteria.PORTAL_DESTROYED.trigger(player);
|
|
||||||
return super.calcBlockBreakingDelta(state, player, world, pos);
|
return super.calcBlockBreakingDelta(state, player, world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,24 @@ public class ChipperPortalShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean tryCreate(World world, BlockPos placedPos) {
|
public static boolean tryCreate(World world, BlockPos placedPos) {
|
||||||
if (!(world instanceof ServerWorld)) return false;
|
if (!(world instanceof ServerWorld serverWorld)) return false;
|
||||||
|
|
||||||
for (Direction.Axis axis : new Direction.Axis[]{Direction.Axis.X, Direction.Axis.Z}) {
|
for (Direction.Axis axis : new Direction.Axis[]{Direction.Axis.X, Direction.Axis.Z}) {
|
||||||
ChipperPortalShape shape = new ChipperPortalShape(world, placedPos, axis);
|
ChipperPortalShape shape = new ChipperPortalShape(world, placedPos, axis);
|
||||||
if (shape.isValid()) {
|
if (shape.isValid()) {
|
||||||
shape.placePortal();
|
shape.placePortal();
|
||||||
ModCriteria.PORTAL_ACTIVATED.trigger(player);
|
|
||||||
|
// 🔥 PORTAL CREATED TRIGGER
|
||||||
|
if (serverWorld.getClosestPlayer(
|
||||||
|
placedPos.getX(),
|
||||||
|
placedPos.getY(),
|
||||||
|
placedPos.getZ(),
|
||||||
|
10,
|
||||||
|
false
|
||||||
|
) instanceof net.minecraft.server.network.ServerPlayerEntity serverPlayer) {
|
||||||
|
ModCriteria.PORTAL_ACTIVATED.trigger(serverPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("[CHIPI] portal created at " + placedPos + " axis=" + axis);
|
System.out.println("[CHIPI] portal created at " + placedPos + " axis=" + axis);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -34,6 +45,7 @@ public class ChipperPortalShape {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isValid() {
|
private boolean isValid() {
|
||||||
// find bottom-left corner
|
// find bottom-left corner
|
||||||
BlockPos base = findBottomLeft();
|
BlockPos base = findBottomLeft();
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"parent": "chipi:root",
|
||||||
|
"display": {
|
||||||
|
"icon": { "item": "chipi:chipper_frame" },
|
||||||
|
"title": "No Turning Back",
|
||||||
|
"description": "Destroy the portal",
|
||||||
|
"frame": "challenge",
|
||||||
|
"hidden": true,
|
||||||
|
"show_toast": true,
|
||||||
|
"announce_to_chat": true
|
||||||
|
},
|
||||||
|
"criteria": {
|
||||||
|
"destroy_portal": {
|
||||||
|
"trigger": "chipi:portal_destroyed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"parent": "chipi:root",
|
||||||
|
"display": {
|
||||||
|
"icon": { "item": "chipi:chipper_portal" },
|
||||||
|
"title": "Do Not Enter",
|
||||||
|
"description": "Activate the portal",
|
||||||
|
"frame": "challenge",
|
||||||
|
"hidden": true,
|
||||||
|
"show_toast": true,
|
||||||
|
"announce_to_chat": true
|
||||||
|
},
|
||||||
|
"criteria": {
|
||||||
|
"activate_portal": {
|
||||||
|
"trigger": "chipi:portal_activated"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
"parent": "chipi:progression/activate_portal",
|
"parent": "chipi:root",
|
||||||
"display": {
|
"display": {
|
||||||
"icon": { "item": "chipi:chipper_portal" },
|
"icon": { "item": "chipi:chipper_frame" },
|
||||||
"title": "You Were Warned",
|
"title": "It Begins",
|
||||||
"description": "Destroy the Portal",
|
"description": "Construct the portal frame",
|
||||||
"frame": "challenge",
|
"frame": "task"
|
||||||
"hidden": true
|
|
||||||
},
|
},
|
||||||
"criteria": {
|
"criteria": {
|
||||||
"destroyed": {
|
"place_frame": {
|
||||||
"trigger": "chipi:portal_destroyed"
|
"trigger": "minecraft:placed_block",
|
||||||
|
"conditions": {
|
||||||
|
"block": "chipi:chipper_frame"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user