Skip to content

Commit

Permalink
More code yippie
Browse files Browse the repository at this point in the history
This might be my last commit for a lil bit, Im working on a possible vanilla-like solution to our networking. On my pc I'm down to 230 Project Errors, but that doesnt mean we are finishing it up soon, far from it.

Signed-off-by: Siuolplex <[email protected]>
  • Loading branch information
Siuolplex committed Jul 12, 2024
1 parent a18cbcd commit 10d2e76
Show file tree
Hide file tree
Showing 29 changed files with 220 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void registerItemColorHandlers(ZAddItemColorHandlers event) {
DyeablesRegistry dyeables = z.dyeables;

ClampedItemPropertyFunction isDyed = (stack, level, entity, i) -> dyeables.isDyed(stack) ? 1 : 0;
ItemColor color = (stack, layer) -> layer == 0 ? dyeables.getColor(stack) : 0xFF_FF_FF;
ItemColor color = (stack, layer) -> layer == 0 ? dyeables.getColor(stack).rgb() : 0xFF_FF_FF;
//apparently ItemPropertyFunctions are weird and can only be assigned to the minecraft: namespace
ResourceLocation isDyedId = ResourceLocation.withDefaultNamespace( z.modid + "_dyed");

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/violetmoon/zeta/client/ClientTicker.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.violetmoon.zeta.client;

import org.violetmoon.zeta.client.event.play.ZClientTick;
import org.violetmoon.zeta.client.event.play.ZRenderTick;
import org.violetmoon.zeta.client.event.play.ZRenderFrame;
import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.bus.ZPhase;

Expand All @@ -15,7 +15,7 @@ public final class ClientTicker {
public float total = 0;

@PlayEvent
public void onRenderTick(ZRenderTick event) {
public void onRenderTick(ZRenderFrame event) {
if(event.isStartPhase())
partialTicks = event.getRenderTickTime();
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.neoforged.neoforge.client.ClientHooks;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import org.violetmoon.zeta.client.event.play.ZRenderTick;
import org.violetmoon.zeta.client.event.play.ZRenderFrame;
import org.violetmoon.zeta.event.bus.PlayEvent;

import java.util.List;
Expand All @@ -24,7 +24,7 @@ public class TopLayerTooltipHandler {
private int tooltipX, tooltipY;

@PlayEvent
public void renderTick(ZRenderTick event) {
public void renderTick(ZRenderFrame event) {
if(tooltip != null && event.isEndPhase()) {
Minecraft mc = Minecraft.getInstance();
Screen screen = mc.screen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.client.model.geometry.IGeometryLoader;
import org.violetmoon.zeta.event.bus.IZetaLoadEvent;
Expand All @@ -11,21 +12,21 @@

public interface ZModel extends IZetaLoadEvent {
interface ModifyBakingResult extends ZModel {
Map<ResourceLocation, BakedModel> getModels();
Map<ModelResourceLocation, BakedModel> getModels();
ModelBakery getModelBakery();
}

interface BakingCompleted extends ZModel {
ModelManager getModelManager();
Map<ResourceLocation, BakedModel> getModels();
Map<ModelResourceLocation, BakedModel> getModels();
ModelBakery getModelBakery();
}

interface RegisterAdditional extends ZModel {
void register(ResourceLocation model);
void register(ModelResourceLocation model);
}

interface RegisterGeometryLoaders extends ZModel {
void register(String name, IGeometryLoader<?> loader);
void register(ResourceLocation id, IGeometryLoader<?> loader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* will not work, Use {@link ZEarlyRender } instead.
* </p>
*/
public interface ZRenderTick extends IZetaPlayEvent {
public interface ZRenderFrame extends IZetaPlayEvent {
float getRenderTickTime();
boolean isEndPhase();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.violetmoon.zeta.client.event.play;

import net.minecraft.client.DeltaTracker;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

import com.mojang.blaze3d.platform.Window;
Expand All @@ -9,7 +10,7 @@
public interface ZRenderGuiOverlay extends IZetaPlayEvent {
Window getWindow();
GuiGraphics getGuiGraphics();
float getPartialTick();
DeltaTracker getPartialTick();

boolean shouldDrawSurvivalElements();
int getLeftHeight(); //weird ForgeGui stuff
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.violetmoon.zeta.event.play.entity.player;

import net.neoforged.neoforge.common.util.TriState;
import org.violetmoon.zeta.event.bus.Cancellable;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;
import org.violetmoon.zeta.event.bus.Resultable;
Expand All @@ -22,7 +23,7 @@ public interface ZRightClickBlock extends IZetaPlayEvent, Cancellable, Resultabl
BlockHitResult getHitVec();
Direction getFace();

ZResult getUseBlock();
TriState getUseBlock();

void setCancellationResult(InteractionResult result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.function.Consumer;

import net.minecraft.world.item.*;
import net.minecraft.world.item.enchantment.Enchantments;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -74,6 +75,7 @@ default int getEnchantmentLevelZeta(ItemStack stack, Enchantment enchantment) {
}

default Map<Enchantment, Integer> getAllEnchantmentsZeta(ItemStack stack) {
Enchantments
return EnchantmentHelper.deserializeEnchantments(stack.getEnchantmentTags());
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/violetmoon/zeta/mod/ZetaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZCommonSetup;
import org.violetmoon.zeta.network.ZetaModInternalNetwork;
import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher;

public class ZetaMod {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class ZetaMessageSerializer {
private final HashMap<Class<?>, Field[]> fieldCache = new HashMap<>();

{
this.<Byte>mapFunctions(byte.class, FriendlyByteBuf::readByte, FriendlyByteBuf::writeByte);
this.mapFunctions(byte.class, FriendlyByteBuf::readByte, FriendlyByteBuf::writeByte);
this.<Short>mapFunctions(short.class, FriendlyByteBuf::readShort, FriendlyByteBuf::writeShort);
mapFunctions(int.class, FriendlyByteBuf::readInt, FriendlyByteBuf::writeInt);
mapFunctions(long.class, FriendlyByteBuf::readLong, FriendlyByteBuf::writeLong);
Expand Down Expand Up @@ -186,11 +186,11 @@ private static void writeString(FriendlyByteBuf buf, String string) {
// Functional interfaces
// ================================================================

public static interface Reader<T> {
public T read(FriendlyByteBuf buf, Field field);
public interface Reader<T> {
T read(FriendlyByteBuf buf, Field field);
}

public static interface Writer<T> {
public void write(FriendlyByteBuf buf, Field field, T t);
public interface Writer<T> {
void write(FriendlyByteBuf buf, Field field, T t);
}
}
56 changes: 25 additions & 31 deletions src/main/java/org/violetmoon/zeta/registry/BrewingRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.function.Supplier;

import net.minecraft.core.Holder;
import net.minecraft.world.item.Item;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.recipe.FlagIngredient;
Expand All @@ -24,6 +25,8 @@
* @author WireSegal
* Created at 3:34 PM on 9/23/19.
*/

//Todo: This NEEDS a rewrite, I feel its been butchered in 1.21
public abstract class BrewingRegistry {

protected final Zeta zeta;
Expand All @@ -32,22 +35,22 @@ public BrewingRegistry(Zeta zeta) {
this.zeta = zeta;
}

public void addPotionMix(String flag, Supplier<Ingredient> reagent, MobEffect effect) {
public void addPotionMix(String flag, Item reagent, MobEffect effect) {
addPotionMix(flag, reagent, effect, null);
}

public void addPotionMix(String flag, Supplier<Ingredient> reagent, MobEffect effect,
public void addPotionMix(String flag, Item reagent, MobEffect effect,
int normalTime, int longTime, int strongTime) {
addPotionMix(flag, reagent, effect, null, normalTime, longTime, strongTime);
}

public void addPotionMix(String flag, Supplier<Ingredient> reagent, MobEffect effect,
@Nullable MobEffect negation) {
public void addPotionMix(String flag, Item reagent, MobEffect effect,
@Nullable MobEffect negation) {
addPotionMix(flag, reagent, effect, negation, 3600, 9600, 1800);
}


public void addPotionMix(String flag, Supplier<Ingredient> reagent, MobEffect effect,
public void addPotionMix(String flag, Item reagent, MobEffect effect,
@Nullable MobEffect negation, int normalTime, int longTime, int strongTime) {
ResourceLocation loc = zeta.registry.getRegistryName(effect, BuiltInRegistries.MOB_EFFECT);

Expand Down Expand Up @@ -79,44 +82,47 @@ public void addPotionMix(String flag, Supplier<Ingredient> reagent, MobEffect ef

}

public void addPotionMix(String flag, Supplier<Ingredient> reagent, Potion normalType, Potion longType, @Nullable Potion strongType) {
public void addPotionMix(String flag, Item reagent, Potion normalType, Potion longType, @Nullable Potion strongType) {
boolean hasStrong = strongType != null;

addFlaggedRecipe(flag, Potions.AWKWARD.value(), reagent, normalType);
addFlaggedRecipe(flag, Potions.WATER.value(), reagent, Potions.MUNDANE.value());

if (hasStrong)
addFlaggedRecipe(flag, normalType, BrewingRegistry::glowstone, strongType);
addFlaggedRecipe(flag, normalType, BrewingRegistry::redstone, longType);
addFlaggedRecipe(flag, normalType, Items.GLOWSTONE, strongType);
addFlaggedRecipe(flag, normalType, Items.REDSTONE, longType);
}

public void addNegation(String flag, Potion normalType, Potion longType, @Nullable Potion strongType,
Potion normalNegatedType, Potion longNegatedType, @Nullable Potion strongNegatedType) {
addFlaggedRecipe(flag, normalType, BrewingRegistry::spiderEye, normalNegatedType);
addFlaggedRecipe(flag, normalType, Items.FERMENTED_SPIDER_EYE, normalNegatedType);

boolean hasStrong = strongType != null && strongNegatedType != null;

if (hasStrong) {
addFlaggedRecipe(flag, strongType, BrewingRegistry::spiderEye, strongNegatedType);
addFlaggedRecipe(flag, normalNegatedType, BrewingRegistry::glowstone, strongNegatedType);
addFlaggedRecipe(flag, strongType, Items.FERMENTED_SPIDER_EYE, strongNegatedType);
addFlaggedRecipe(flag, normalNegatedType, Items.GLOWSTONE_DUST, strongNegatedType);
}
addFlaggedRecipe(flag, longType, BrewingRegistry::spiderEye, longNegatedType);
addFlaggedRecipe(flag, normalNegatedType, BrewingRegistry::redstone, longNegatedType);
addFlaggedRecipe(flag, longType, Items.FERMENTED_SPIDER_EYE, longNegatedType);
addFlaggedRecipe(flag, normalNegatedType, Items.REDSTONE, longNegatedType);

}

protected final Map<Potion, String> flaggedPotions = Maps.newHashMap();

protected void addFlaggedRecipe(String flag, Potion potion, Supplier<Ingredient> reagent, Potion to) {
protected void addFlaggedRecipe(String flag, Potion potion, Item reagent, Potion to) {
flaggedPotions.put(to, flag);
Supplier<Ingredient> flagIngredientSupplier = () -> new FlagIngredient(
reagent.get(),
/*Supplier<Ingredient> flagIngredientSupplier = () -> new FlagIngredient(
reagent,
flag,
zeta.configManager.getConfigFlagManager(),
zeta.configManager.getConfigFlagManager().flagIngredientSerializer
);
);*/
//todo: Chat checkup on this
if (zeta.configManager.getConfigFlagManager().getFlag(flag)) {
addBrewingRecipe(potion, reagent, to);
};

addBrewingRecipe(potion, flagIngredientSupplier, to);
}

protected Potion registerPotion(MobEffectInstance eff, String baseName, String name) {
Expand All @@ -132,17 +138,5 @@ public boolean isEnabled(Potion potion) {
return zeta.configManager.getConfigFlagManager().getFlag(flaggedPotions.get(potion));
}

public static Ingredient redstone() {
return Ingredient.of(Items.REDSTONE);
}

public static Ingredient glowstone() {
return Ingredient.of(Items.GLOWSTONE_DUST);
}

public static Ingredient spiderEye() {
return Ingredient.of(Items.FERMENTED_SPIDER_EYE);
}

protected abstract void addBrewingRecipe(Potion potion, Supplier<Ingredient> reagent, Potion result);
protected abstract void addBrewingRecipe(Potion input, Item reagentSupplier, Potion output);
}
Loading

0 comments on commit 10d2e76

Please sign in to comment.