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 =
|
||||
Criteria.register(new PortalDestroyedTrigger());
|
||||
|
||||
public static void register() {}
|
||||
public static void register() {
|
||||
// classload trigger
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
package net.Chipperfluff.chipi.advancement;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancement.AdvancementCriterion;
|
||||
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.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 =
|
||||
new Identifier(ChipiMod.MOD_ID, "portal_activated");
|
||||
new Identifier("chipi", "portal_activated");
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
@ -19,21 +20,21 @@ public class PortalActivatedTrigger extends AbstractCriterion<PortalActivatedTri
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Conditions conditionsFromJson(
|
||||
JsonObject obj,
|
||||
net.minecraft.advancement.criterion.CriterionConditionsParser parser
|
||||
public Conditions conditionsFromJson(
|
||||
JsonObject json,
|
||||
LootContextPredicate player,
|
||||
AdvancementEntityPredicateDeserializer deserializer
|
||||
) {
|
||||
return new Conditions();
|
||||
return new Conditions(player);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayerEntity player) {
|
||||
this.trigger(player, conditions -> true);
|
||||
}
|
||||
|
||||
// ================= CONDITIONS =================
|
||||
public static class Conditions extends CriterionConditions {
|
||||
public Conditions() {
|
||||
super(ID, null);
|
||||
public static class Conditions extends AbstractCriterionConditions {
|
||||
public Conditions(LootContextPredicate player) {
|
||||
super(ID, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,19 @@
|
||||
package net.Chipperfluff.chipi.advancement;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancement.AdvancementCriterion;
|
||||
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.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 =
|
||||
new Identifier(ChipiMod.MOD_ID, "portal_destroyed");
|
||||
new Identifier("chipi", "portal_destroyed");
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
@ -19,21 +21,21 @@ public class PortalDestroyedTrigger extends AbstractCriterion<PortalDestroyedTri
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Conditions conditionsFromJson(
|
||||
JsonObject obj,
|
||||
net.minecraft.advancement.criterion.CriterionConditionsParser parser
|
||||
public Conditions conditionsFromJson(
|
||||
JsonObject json,
|
||||
LootContextPredicate player,
|
||||
AdvancementEntityPredicateDeserializer deserializer
|
||||
) {
|
||||
return new Conditions();
|
||||
return new Conditions(player);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayerEntity player) {
|
||||
this.trigger(player, conditions -> true);
|
||||
}
|
||||
|
||||
// ================= CONDITIONS =================
|
||||
public static class Conditions extends CriterionConditions {
|
||||
public Conditions() {
|
||||
super(ID, null);
|
||||
public static class Conditions extends AbstractCriterionConditions {
|
||||
public Conditions(LootContextPredicate player) {
|
||||
super(ID, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,13 +4,11 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.PillarBlock;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.Chipperfluff.chipi.advancement.ModCriteria;
|
||||
|
||||
public class ChipperFrameBlock extends PillarBlock {
|
||||
|
||||
@ -19,20 +17,13 @@ public class ChipperFrameBlock extends PillarBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(
|
||||
BlockState state,
|
||||
public void onPlaced(
|
||||
World world,
|
||||
BlockPos pos,
|
||||
PlayerEntity player,
|
||||
Hand hand,
|
||||
BlockHitResult hit
|
||||
BlockState state,
|
||||
LivingEntity placer,
|
||||
ItemStack stack
|
||||
) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state,
|
||||
LivingEntity placer, ItemStack stack) {
|
||||
if (!world.isClient) {
|
||||
ChipperPortalShape.tryCreate(world, pos);
|
||||
}
|
||||
@ -46,9 +37,19 @@ public class ChipperFrameBlock extends PillarBlock {
|
||||
BlockState newState,
|
||||
boolean moved
|
||||
) {
|
||||
if (!world.isClient) {
|
||||
if (!world.isClient && state.getBlock() != newState.getBlock()) {
|
||||
// destroy portal
|
||||
ChipperPortalShape.destroyNearby(world, pos);
|
||||
}
|
||||
super.onBroken(world, pos, state);
|
||||
|
||||
// advancement trigger
|
||||
if (world.getClosestPlayer(
|
||||
pos.getX(), pos.getY(), pos.getZ(),
|
||||
10, false
|
||||
) instanceof ServerPlayerEntity serverPlayer) {
|
||||
ModCriteria.PORTAL_DESTROYED.trigger(serverPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
super.onStateReplaced(state, world, pos, newState, moved);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||
import java.util.EnumSet;
|
||||
import net.Chipperfluff.chipi.advancement.ModCriteria;
|
||||
|
||||
public class ChipperPortalBlock extends Block {
|
||||
|
||||
@ -78,7 +77,6 @@ public class ChipperPortalBlock extends Block {
|
||||
if (!player.isCreative()) {
|
||||
return 0.0F; // impossible to break
|
||||
}
|
||||
ModCriteria.PORTAL_DESTROYED.trigger(player);
|
||||
return super.calcBlockBreakingDelta(state, player, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,13 +20,24 @@ public class ChipperPortalShape {
|
||||
}
|
||||
|
||||
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}) {
|
||||
ChipperPortalShape shape = new ChipperPortalShape(world, placedPos, axis);
|
||||
if (shape.isValid()) {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@ -34,6 +45,7 @@ public class ChipperPortalShape {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean isValid() {
|
||||
// find bottom-left corner
|
||||
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": {
|
||||
"icon": { "item": "chipi:chipper_portal" },
|
||||
"title": "You Were Warned",
|
||||
"description": "Destroy the Portal",
|
||||
"frame": "challenge",
|
||||
"hidden": true
|
||||
"icon": { "item": "chipi:chipper_frame" },
|
||||
"title": "It Begins",
|
||||
"description": "Construct the portal frame",
|
||||
"frame": "task"
|
||||
},
|
||||
"criteria": {
|
||||
"destroyed": {
|
||||
"trigger": "chipi:portal_destroyed"
|
||||
"place_frame": {
|
||||
"trigger": "minecraft:placed_block",
|
||||
"conditions": {
|
||||
"block": "chipi:chipper_frame"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user