Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ allprojects {
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType<JavaCompile> {
options.release = 17
options.encoding = "UTF-8"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void registerItems(ItemRegistryEvent event) {
testPickaxe = new ModdedPickaxeItem(NAMESPACE.id("test_pickaxe"), testMaterial); //8476
testNBTItem = new NBTItem(NAMESPACE.id("nbt_item")); //8477
testModelItem = new ModelItem(NAMESPACE.id("model_item")).setMaxCount(1);
ironOre = event.register(NAMESPACE.id("iron_ore"), new Item(ItemRegistry.AUTO_ID));
generatedItem = event.register(NAMESPACE.id("generated_item"), new Item(ItemRegistry.AUTO_ID));
ironOre = event.register(NAMESPACE.id("iron_ore"), new Item(ItemRegistry.AUTO_ID).setTranslationKey(NAMESPACE.id("iron_ore")));
generatedItem = event.register(NAMESPACE.id("generated_item"), new Item(ItemRegistry.AUTO_ID).setTranslationKey(NAMESPACE.id("generated_item")));
variationBlockIdle = new BlockStateItem(NAMESPACE.id("variation_block_idle"), Blocks.VARIATION_BLOCK.get().getDefaultState());
variationBlockPassive = new BlockStateItem(NAMESPACE.id("variation_block_passive"), Blocks.VARIATION_BLOCK.get().getDefaultState().with(VariationBlock.VARIANT, VariationBlock.Variant.PASSIVE));
variationBlockActive = new BlockStateItem(NAMESPACE.id("variation_block_active"), Blocks.VARIATION_BLOCK.get().getDefaultState().with(VariationBlock.VARIANT, VariationBlock.Variant.ACTIVE));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.modificationstation.sltest.render;

import com.mojang.datafixers.util.Pair;
import net.mine_diver.unsafeevents.listener.EventListener;
import net.modificationstation.sltest.SLTest;
import net.modificationstation.stationapi.api.client.event.render.model.BeforeModelLoaderInitEvent;
import net.modificationstation.stationapi.api.client.event.render.model.BlockStateReloadEvent;
import net.modificationstation.stationapi.api.client.event.render.model.ModelVariantMapOverrideEvent;
import net.modificationstation.stationapi.api.client.event.render.model.UnbakedModelLoadingFinishedEvent;
import net.modificationstation.stationapi.api.client.render.model.json.ModelVariantMap;
import net.modificationstation.stationapi.api.util.Identifier;

import java.io.BufferedReader;
import java.io.StringReader;

public class ModelLoadingListener {
@EventListener
public void modelsLoaded(UnbakedModelLoadingFinishedEvent event) {
SLTest.LOGGER.info(event.unbakedModels.size() + " models loaded");
}

String blockstateJson = ("""
{
"variants": {
"": {"model": "sltest:block/test_block"}
}
}"""
);

@EventListener
public void injectBlockState(BlockStateReloadEvent event) {
event.addBlockstateJsonString(Identifier.of("minecraft:sponge"), blockstateJson);
}

@EventListener
public void beforeLoader(BeforeModelLoaderInitEvent event) {
SLTest.LOGGER.info("Model Loader Init");
}

String blockstateVariantJson = ("""
{
"variants": {
"": {"model": "sltest:block/test_block"}
}
}"""
);

@EventListener
public void mineLdiver(ModelVariantMapOverrideEvent event) {
if (event.id.equals(Identifier.of("minecraft:note_block"))) {
BufferedReader reader = new BufferedReader(new StringReader(blockstateVariantJson));
event.addModelVariantMap(SLTest.NAMESPACE, ModelVariantMap.fromJson(event.deserializationContext, reader));
}

System.err.println(event.id);
for (Pair<String, ModelVariantMap> variantMap : event.variantMaps) {
System.err.println(" - " + variantMap.getFirst() + " | " + variantMap.getSecond().getVariantMap().toString());
}
}
}
3 changes: 2 additions & 1 deletion src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"net.modificationstation.sltest.option.OptionListener",
"net.modificationstation.sltest.keyboard.KeyboardListener",
"net.modificationstation.sltest.texture.TextureListener",
"net.modificationstation.sltest.render.entity.EntityRendererListener"
"net.modificationstation.sltest.render.entity.EntityRendererListener",
"net.modificationstation.sltest.render.ModelLoadingListener"
],
"main": [
"net.modificationstation.sltest.MainTest"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.modificationstation.stationapi.api.effect;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -10,16 +8,15 @@ public abstract class EntityEffect<THIS extends EntityEffect<THIS>> {
public static final int INFINITY_TICKS = -1;
protected Entity entity;
private int ticks;

private final String nameTranslationKey;
private final String descriptionTranslationKey;

protected EntityEffect(Entity entity, int ticks) {
this.entity = entity;
this.ticks = ticks;
var effectId = getType().registryEntry.registryKey().getValue();
nameTranslationKey = "gui.stationapi.effect." + effectId.namespace + "." + effectId.path + ".name";
descriptionTranslationKey = nameTranslationKey.substring(0, nameTranslationKey.length() - 4) + "desc";
this.nameTranslationKey = getType().getTranslationKey();
this.descriptionTranslationKey = getType().getDescriptionTranslationKey();
}

/**
Expand All @@ -29,58 +26,72 @@ protected EntityEffect(Entity entity, int ticks) {
* or synchronized from the server later.
*/
public abstract void onAdded(boolean appliedNow);

/**
* This method is called on each entity tick.
*/
public abstract void onTick();

/**
* This method is called immediately when the effect is removed.
*/
public abstract void onRemoved();

/**
* Allows to write any custom data to the tag storage.
*
* @param tag effect data root tag
*/
protected abstract void writeNbt(NbtCompound tag);

/**
* Allows to read any custom data from the tag storage.
*
* @param tag effect data root tag
*/
protected abstract void readNbt(NbtCompound tag);

public abstract EntityEffectType<THIS> getType();

/**
* Get remaining effect ticks.
*/
public final int getTicks() {
return ticks;
}

/**
* Check if effect is infinite.
*/
public final boolean isInfinite() {
return ticks == INFINITY_TICKS;
}

/**
* Get translated effect name, client side only.
* Get the translation key for the name of the effect.
*/
@Environment(EnvType.CLIENT)
public final String getName() {
public final String getTranslationKey() {
return this.nameTranslationKey;
}

/**
* Get the translation key for the description of the effect.
*/
public final String getDescriptionTranslationKey() {
return this.descriptionTranslationKey;
}

/**
* Get translated effect name.
*/
public final String getTranslatedName() {
return I18n.getTranslation(nameTranslationKey, nameTranslationKey);
}

/**
* Get translated effect description, client side only.
* Get translated effect description.
*/
@Environment(EnvType.CLIENT)
public final String getDescription() {
public final String getTranslatedDescription() {
return I18n.getTranslation(descriptionTranslationKey, descriptionTranslationKey);
}

Expand All @@ -93,12 +104,12 @@ public final void tick() {
}
}
}

public final void write(NbtCompound nbt) {
nbt.putInt("ticks", ticks);
writeNbt(nbt);
}

public final void read(NbtCompound nbt) {
ticks = nbt.getInt("ticks");
readNbt(nbt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.modificationstation.stationapi.api.effect;

import net.modificationstation.stationapi.api.registry.RegistryEntry;
import net.modificationstation.stationapi.api.util.Identifier;

/**
* Static reference of an effect. Since {@link EntityEffect} is initialized per-entity, a separate class is required
Expand All @@ -24,6 +25,29 @@ private EntityEffectType(Builder<EFFECT_INSTANCE> builder) {
factory = builder.factory;
}

/**
* Returns the identifier of the effect
*/
public Identifier getIdentifier() {
return registryEntry.registryKey().getValue();
}

/**
* Returns the translation key of the effect's name.
*/
public String getTranslationKey() {
Identifier identifier = registryEntry.registryKey().getValue();
return "gui.stationapi.effect." + identifier.namespace + "." + identifier.path + ".name";
}

/**
* Returns the translation key of the effect's description.
*/
public String getDescriptionTranslationKey() {
Identifier identifier = registryEntry.registryKey().getValue();
return "gui.stationapi.effect." + identifier.namespace + "." + identifier.path + ".desc";
}

/**
* @param factory the effect instance's factory which takes an {@link net.minecraft.entity.Entity} argument
* of the entity the effect's been applied to, and an int argument defining the duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void renderEffects(Minecraft minecraft, float delta, boolean extended) {
int py = 2;
for (EntityEffect<?> effect : renderEffects) {
if (extended) {
String name = effect.getName();
String desc = effect.getDescription();
String name = effect.getTranslatedName();
String desc = effect.getTranslatedDescription();
int width = Math.max(
textRenderer.getWidth(name),
textRenderer.getWidth(desc)
Expand Down Expand Up @@ -127,8 +127,8 @@ private void renderEffectBack(Minecraft minecraft, int y, int width) {

private int getEffectWidth(EntityEffect<?> effect) {
if (effect.isInfinite()) return 26;
String name = effect.getName();
String desc = effect.getDescription();
String name = effect.getTranslatedName();
String desc = effect.getTranslatedDescription();
return Math.max(
textRenderer.getWidth(name),
textRenderer.getWidth(desc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ static BlockPos create(double x, double y, double z) {
return new BlockPos(floor(x), floor(y), floor(z));
}

static BlockPos create(Vec3d pos) {
return create(pos.x, pos.y, pos.z);
}

static BlockPos create(Position pos) {
return create(pos.getX(), pos.getY(), pos.getZ());
}

static BlockPos create(Vec3d pos) {
return create(pos.x, pos.y, pos.z);
}

static BlockPos create(Vec3i pos) {
return new BlockPos(pos.getX(), pos.getY(), pos.getZ());
}
Expand Down Expand Up @@ -336,23 +336,55 @@ default long asLong() {
return asLong(getX(), getY(), getZ());
}

default BlockPos add(double d, double e, double f) {
default BlockPos add(double x, double y, double z) {
return Util.assertImpl();
}

default BlockPos add(int i, int j, int k) {
default BlockPos add(int x, int y, int z) {
return Util.assertImpl();
}

default BlockPos add(BlockPos blockPos) {
return add(blockPos.x, blockPos.y, blockPos.z);
}

default BlockPos add(Position position) {
return add(position.getX(), position.getY(), position.getZ());
}

default BlockPos add(Vec3d vec3d) {
return add(vec3d.x, vec3d.y, vec3d.z);
}

default BlockPos add(Vec3i vec3i) {
return add(vec3i.getX(), vec3i.getY(), vec3i.getZ());
}

default BlockPos subtract(double x, double y, double z) {
return add(-x, -y, -z);
}

default BlockPos subtract(int x, int y, int z) {
return add(-x, -y, -z);
}

default BlockPos subtract(BlockPos blockPos) {
return add(-blockPos.x, -blockPos.y, -blockPos.z);
}

default BlockPos subtract(Position position) {
return add(-position.getX(), -position.getY(), -position.getZ());
}

default BlockPos subtract(Vec3d vec3d) {
return add(-vec3d.x, -vec3d.y, -vec3d.z);
}

default BlockPos subtract(Vec3i vec3i) {
return add(-vec3i.getX(), -vec3i.getY(), -vec3i.getZ());
}

default BlockPos multiply(int i) {
default BlockPos multiply(int multiplier) {
return Util.assertImpl();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockPos.class)
public class TilePosMixin implements StationBlockPos {
public class BlockPosMixin implements StationBlockPos {
@Shadow @Final public int x;

@Shadow @Final public int y;
Expand Down Expand Up @@ -56,12 +56,12 @@ public BlockPos subtract(Vec3i vec3i) {
}

@Override
public BlockPos multiply(int i) {
return switch (i) {
public BlockPos multiply(int multiplier) {
return switch (multiplier) {
case 1 -> //noinspection DataFlowIssue
(BlockPos) (Object) this;
case 0 -> ORIGIN;
default -> new BlockPos(getX() * i, getY() * i, getZ() * i);
default -> new BlockPos(getX() * multiplier, getY() * multiplier, getZ() * multiplier);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"TilePosAccessor",
"TilePosMixin"
"BlockPosMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Loading