Skip to content

Commit

Permalink
Advancements!
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Apr 18, 2024
1 parent 6a1946c commit 5d5ff77
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 16 deletions.
3 changes: 2 additions & 1 deletion changelog-next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@
- Fixed items not dropping when breaking Steam Engine.
- Fixed hopper interactions with Steam Engine.
- Fixed center element of Cable model being offset upwards.
- Fixed specific setups causing server to crash.
- Fixed specific setups causing server to crash.
- Fixed Hologram Projector's display (internal) offset being reset when it shouldn't.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface FactoryTriggers {
Identifier TATER_16 = id("tater_16");
Identifier TATER_128 = id("tater_128");
Identifier TATER_1024 = id("tater_1024");
Identifier ARITHMETIC_OPERATOR = id("arithmetic_operator");
Identifier DATA_MEMORY= id("data_memory");
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package eu.pb4.polyfactory.block.data.io;

import com.google.common.collect.ImmutableList;
import eu.pb4.factorytools.api.advancement.TriggerCriterion;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
import eu.pb4.polyfactory.block.data.DoubleInputTransformerBlock;
import eu.pb4.polyfactory.block.data.DoubleInputTransformerBlockEntity;
import eu.pb4.polyfactory.data.*;
import eu.pb4.polyfactory.item.wrench.WrenchAction;
import eu.pb4.polyfactory.util.FactoryUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
Expand Down Expand Up @@ -53,6 +58,10 @@ protected DataContainer transformData(DataContainer input1, DataContainer input2
var action = selfState.get(OPERATION);
var mode = selfState.get(MODE);

if (FactoryUtil.getClosestPlayer(world, selfPos, 16) instanceof ServerPlayerEntity player) {
TriggerCriterion.trigger(player, FactoryTriggers.ARITHMETIC_OPERATOR);
}

return switch (action) {
case ADDITION -> switch (mode) {
case INTEGER -> new LongData(input1.asLong() + input2.asLong());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package eu.pb4.polyfactory.block.data.io;

import com.kneelawk.graphlib.api.graph.user.BlockNode;
import eu.pb4.factorytools.api.advancement.TriggerCriterion;
import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
import eu.pb4.polyfactory.advancement.FactoryTriggers;
import eu.pb4.polyfactory.block.data.DataReceiver;
import eu.pb4.polyfactory.block.data.providers.DataProviderBlock;
import eu.pb4.polyfactory.block.data.util.ChanneledDataCache;
Expand All @@ -13,12 +15,15 @@
import eu.pb4.polyfactory.nodes.data.ChannelProviderDirectionNode;
import eu.pb4.polyfactory.nodes.data.ChannelReceiverDirectionNode;
import eu.pb4.polyfactory.nodes.data.DataReceiverNode;
import eu.pb4.polyfactory.util.FactoryUtil;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenTexts;
Expand Down Expand Up @@ -110,6 +115,15 @@ public void appendTooltip(ItemStack stack, @Nullable BlockView world, List<Text>
}
}

@Override
public void afterBreak(World world, PlayerEntity player1, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
if (blockEntity instanceof DataCache cache && cache.getCachedData() != null && !cache.getCachedData().isEmpty()
&& player1 instanceof ServerPlayerEntity player) {
TriggerCriterion.trigger(player, FactoryTriggers.DATA_MEMORY);
}
super.afterBreak(world, player1, pos, state, blockEntity, tool);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ public void setData(DataContainer data) {
}
this.lastData = data;

this.extraScale = 1;
this.customCenter = 0;
this.extraOffset = 0;
DisplayElement newDisplay = null;
DisplayElement newDisplayExtra = null;
if (data instanceof ItemStackData stackData && !this.forceText) {
Expand All @@ -352,6 +349,9 @@ public void setData(DataContainer data) {
e.tick();
return;
}
this.extraScale = 1;
this.customCenter = 0;
this.extraOffset = 0;
var i = new ItemDisplayElement(stackData.stack());
i.setModelTransformation(ModelTransformationMode.GUI);
newDisplay = i;
Expand All @@ -369,6 +369,9 @@ public void setData(DataContainer data) {
this.extraScale = 2;
return;
}
this.extraScale = 1;
this.customCenter = 0;
this.extraOffset = 0;
if (asItem) {
var i = new ItemDisplayElement(LodItemDisplayElement.getModel(blockStateData.state().getBlock().asItem()));
i.setModelTransformation(ModelTransformationMode.FIXED);
Expand All @@ -394,7 +397,7 @@ public void setData(DataContainer data) {
space = i;
}

if (DefaultFonts.VANILLA.getTextWidth(string.substring(start, i + 1), 8) > 70) {
if (DefaultFonts.VANILLA.getTextWidth(string.substring(start, i + 1), 8) > 100) {
if (space != -1) {
list.add(string.substring(start, space));
start = space + 1;
Expand All @@ -418,18 +421,18 @@ public void setData(DataContainer data) {
displayExtra.tick();
return;
}

this.extraScale = 1;
var t = new TextDisplayElement(text);
t.setBackground(0);
t.setShadow(true);
t.setLineWidth(90);
t.setLineWidth(120);
newDisplay = t;
t = new TextDisplayElement(text);
t.setBackground(0);
t.setShadow(true);
t.setLineWidth(90);
t.setLineWidth(120);
newDisplayExtra = t;
this.extraOffset = list.size() / 4f;
this.extraOffset = -list.size() / 4f;
this.customCenter = list.size() / 8f;
}

Expand Down Expand Up @@ -475,13 +478,11 @@ private void applyDynamicTransformation(DisplayElement display, int id) {
mat.rotateZ((this.facing.getDirection() == Direction.AxisDirection.POSITIVE ? 0 : MathHelper.PI));

mat.translate(0, this.offset + this.scale / 2 , 0);
if (display instanceof TextDisplayElement t) {
mat.translate(0, -t.getText().getString().lines().count() * this.scale * (7 / 16f), 0);
}

mat.scale(new Vector3f(this.scale, this.scale, display instanceof TextDisplayElement ? 1f : 0.01f).mul(this.extraScale));
//if (display instanceof TextDisplayElement t) {
// mat.translate(0, -t.getText().getString().lines().count() * (6 / 16f), 0);
//}
mat.translate(0, this.extraOffset, 0);

mat.translate(0, this.customCenter, 0);
mat.rotateXYZ(this.pitch, this.yaw, this.roll);
if (display instanceof BlockDisplayElement) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/eu/pb4/polyfactory/datagen/AdvancementsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,36 @@ private void base(AdvancementEntry root, Consumer<AdvancementEntry> exporter) {
.criterion("use", TriggerCriterion.of(FactoryTriggers.ITEM_READER))
.build(exporter, "polyfactory:main/base/item_reader");

var aritheticOperator = Advancement.Builder.create()
.parent(cable)
.display(
FactoryItems.ARITHMETIC_OPERATOR,
Text.translatable("advancements.polyfactory.arithmetic_operator.title"),
Text.translatable("advancements.polyfactory.arithmetic_operator.description"),
null,
AdvancementFrame.TASK,
true,
true,
false
)
.criterion("use", TriggerCriterion.of(FactoryTriggers.ARITHMETIC_OPERATOR))
.build(exporter, "polyfactory:main/base/arithmetic_operator");

var dataMemory = Advancement.Builder.create()
.parent(aritheticOperator)
.display(
FactoryItems.DATA_MEMORY,
Text.translatable("advancements.polyfactory.data_memory.title"),
Text.translatable("advancements.polyfactory.data_memory.description"),
null,
AdvancementFrame.TASK,
true,
true,
false
)
.criterion("use", TriggerCriterion.of(FactoryTriggers.DATA_MEMORY))
.build(exporter, "polyfactory:main/base/data_memory");

var nixieTubes = Advancement.Builder.create()
.parent(cable)
.display(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/polyfactory/datagen/LootTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void generate() {
this.addDrop(FactoryBlocks.DATA_MEMORY, LootTable.builder().pool(LootPool.builder()
.conditionally(SurvivesExplosionLootCondition.builder())
.rolls(ConstantLootNumberProvider.create(1.0F))
.with(ItemEntry.builder(FactoryBlocks.DATA_MEMORY)
.with(ItemEntry.builder(FactoryItems.DATA_MEMORY)
.apply(() -> CopyCachedDataLootFunction.INSTANCE)
.apply(() -> CopyReadOnlyLootFunction.INSTANCE)
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LootFunctionType getType() {
@Override
public ItemStack apply(ItemStack stack, LootContext lootContext) {
if (lootContext.hasParameter(LootContextParameters.BLOCK_ENTITY)) {
if (lootContext.get(LootContextParameters.BLOCK_ENTITY) instanceof DataCache provider && provider.getCachedData() != null) {
if (lootContext.get(LootContextParameters.BLOCK_ENTITY) instanceof DataCache provider && provider.getCachedData() != null && !provider.getCachedData().isEmpty()) {
stack.getOrCreateNbt().put("cached_data", provider.getCachedData().createNbt());
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/polyfactory/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@
"advancements.polyfactory.wrench.title": "Configured",
"advancements.polyfactory.wrench.description": "Use Wrench to change properties of a machine.",

"advancements.polyfactory.arithmetic_operator.title": "It just adds up!",
"advancements.polyfactory.arithmetic_operator.description": "Use Arithmetic Operator to apply any operation on data!",

"advancements.polyfactory.data_memory.title": "The storage device can now be safely removed from your computer.",
"advancements.polyfactory.data_memory.description": "Store some data in Data Memory Block and then take it with you!",

"advancements.polyfactory.tater_16.title": "Potato Beginner",
"advancements.polyfactory.tater_16.description": "Click Potato on a Spring 16 times...",
"advancements.polyfactory.tater_128.title": "2 stacks of taters",
Expand Down

0 comments on commit 5d5ff77

Please sign in to comment.