Skip to content

Commit

Permalink
the Grand (spell) update
Browse files Browse the repository at this point in the history
  • Loading branch information
walksanatora committed May 5, 2023
1 parent 3f24833 commit 069984c
Show file tree
Hide file tree
Showing 28 changed files with 706 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .architectury-transformer/debug.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[Architectury Transformer DEBUG] Closed File Systems for /home/walksanator/git/mods/HexTweaks/common/build/libs/hextweaks-1.0.0.jar
[Architectury Transformer DEBUG] Closed File Systems for /home/walksanator/git/mods/HexTweaks/common/build/libs/hextweaks-2.2.1.jar
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ subprojects {
silentMojangMappingsLicense()
}

repositories {
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
}
}

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.17.1:2021.09.05@zip")
}// The following line declares the yarn mappings you may select this one as well.
// mappings "net.fabricmc:yarn:1.19.2+build.3:v2"
}
}
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ repositories {
dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
Expand Down
28 changes: 17 additions & 11 deletions common/src/main/java/net/walksanator/hextweaks/HexTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.spell.iota.ListIota;
import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registries;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.walksanator.hextweaks.blocks.BlockRegister;
import net.walksanator.hextweaks.iotas.DictionaryIota;
import net.walksanator.hextweaks.iotas.HextweaksIotaType;
import net.walksanator.hextweaks.items.ItemRegister;
import net.walksanator.hextweaks.patterns.PatternRegister;

import org.apache.logging.log4j.LogManager;
Expand All @@ -21,27 +28,24 @@ public class HexTweaks {
public static final String MOD_ID = "hextweaks";

public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
// We can use this if we don't want to use DeferredRegister
public static final Supplier<Registries> REGISTRIES = Suppliers.memoize(() -> Registries.get(MOD_ID));
// Registering a new creative tab
//public static final CreativeModeTab EXAMPLE_TAB = CreativeTabRegistry.create(new ResourceLocation(MOD_ID, "example_tab"), () ->
// new ItemStack(HexTweaks.EXAMPLE_ITEM.get()));

//public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(MOD_ID, Registry.ITEM_REGISTRY);
//public static final RegistrySupplier<Item> EXAMPLE_ITEM = ITEMS.register("example_item", () ->
// new Item(new Item.Properties().tab(HexTweaks.EXAMPLE_TAB)));

//these act as registries/configs...
public static final List<Class<? extends Iota>> cannotBeDictKey = new ArrayList<>();
public static final List<ResourceLocation> GrandSpells = new ArrayList<>();
public static int MaxKeysInDictIota = 32;

//initial setup of some values
static {
//cannot be keys
cannotBeDictKey.add(DictionaryIota.class);
cannotBeDictKey.add(ListIota.class);

//Grand spells
GrandSpells.add(new ResourceLocation("hextweaks","grand/reroll"));
}

public static int MaxKeysInDictIota = 32;

public static void init() {
//ITEMS.register();
try {
PatternRegister.registerPatterns();
} catch (PatternRegistry.RegisterPatternException e) {
Expand All @@ -50,5 +54,7 @@ public static void init() {

HextweaksIotaType.registerTypes();

BlockRegister.register();
ItemRegister.register();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.walksanator.hextweaks.blocks;

import at.petrak.hexcasting.xplat.IXplatAbstractions;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.Registry;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.walksanator.hextweaks.HexTweaks;

public class BlockRegister {
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(HexTweaks.MOD_ID, Registry.BLOCK_REGISTRY);
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(HexTweaks.MOD_ID,Registry.ITEM_REGISTRY);
public static final RegistrySupplier<Block> CRYSTALLIZED_SCROLL_BLOCK = BLOCKS.register("crystallizedbookblock",
() -> new CrystalizedScrollBlock(BlockBehaviour.Properties.of(Material.AMETHYST)));

public static void register() {
BLOCKS.register();

for (RegistrySupplier<Block> block : BLOCKS) {
ITEMS.register(block.getId(),
() -> new BlockItem(block.get(), new Item.Properties().tab(IXplatAbstractions.INSTANCE.getTab())));
}
ITEMS.register();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.walksanator.hextweaks.blocks;

import at.petrak.hexcasting.api.PatternRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.walksanator.hextweaks.HexTweaks;
import net.walksanator.hextweaks.items.CrystallizedScroll;
import net.walksanator.hextweaks.items.ItemRegister;
import org.jetbrains.annotations.NotNull;

import java.util.Random;

import static net.walksanator.hextweaks.patterns.PatternRegister.lookupPatternIllegal;

public class CrystalizedScrollBlock extends Block {

public CrystalizedScrollBlock(Properties properties) {
super(properties);
}

@Override
@SuppressWarnings("deprecation")
public void onPlace(@NotNull BlockState newState, Level level, @NotNull BlockPos position, @NotNull BlockState OldState, boolean movedByPiston) {
if (!level.isClientSide) {
Random rand = new Random();
//create the item
ItemStack scroll = new ItemStack(ItemRegister.CRYSTALLIZED_SCROLL.get());

//create the data
CompoundTag ctag = new CompoundTag();

ResourceLocation target = HexTweaks.GrandSpells.get(
rand.nextInt(HexTweaks.GrandSpells.size())
);

PatternRegistry.PatternEntry entry = lookupPatternIllegal( //use the illegal lookup method since Grand spells can have Illegal signatures
target
);

ctag.put(CrystallizedScroll.TAG_PATTERN,
entry.prototype().serializeToNBT()
);
ctag.put(CrystallizedScroll.TAG_OP_ID,StringTag.valueOf(target.toString()));

scroll.setTag(ctag);

//turn the item into an entity
ItemEntity scroll_ent = new ItemEntity(level,position.getX(),position.getY(),position.getZ(),scroll);

//spawn
level.addFreshEntity(scroll_ent);
level.setBlockAndUpdate(position,Blocks.AIR.defaultBlockState());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.walksanator.hextweaks.items;

import at.petrak.hexcasting.api.item.IotaHolderItem;
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.common.items.ItemScroll;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CrystallizedScroll extends ItemScroll implements IotaHolderItem {
public CrystallizedScroll(Properties properties) {
super(properties,1);
}

@Override
public boolean canWrite(ItemStack stack, @Nullable Iota iota) {
return false;
}

@Override
public void writeDatum(ItemStack stack, @Nullable Iota iota) {}//you cannot write to it


@Override
public boolean isFoil(@NotNull ItemStack stack) {return true;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.walksanator.hextweaks.items;

import at.petrak.hexcasting.xplat.IXplatAbstractions;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.Registry;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Rarity;
import net.walksanator.hextweaks.HexTweaks;

public class ItemRegister {
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(HexTweaks.MOD_ID, Registry.ITEM_REGISTRY);
public static final RegistrySupplier<Item> CRYSTALLIZED_SCROLL = ITEMS.register("crystallized_scroll",
() -> new CrystallizedScroll(props().rarity(Rarity.EPIC)));
public static Item.Properties props() {
return new Item.Properties().tab(IXplatAbstractions.INSTANCE.getTab());
}

public static void register() {
ITEMS.register();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.walksanator.hextweaks.mixin;

import at.petrak.hexcasting.api.PatternRegistry;
import at.petrak.hexcasting.api.spell.Action;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.concurrent.ConcurrentMap;

@Mixin(PatternRegistry.class)
public interface MixinPatternRegistry {
@Accessor("actionLookup")
static ConcurrentMap<ResourceLocation, Action> getActionLookup() {
throw new AssertionError();
}

@Accessor("perWorldPatternLookup")
static ConcurrentMap<ResourceLocation,?> getPerWorldPatternLookup() {
throw new AssertionError();
}

@Accessor("regularPatternLookup")
static ConcurrentMap<String,?> getRegularPatternLookup() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.walksanator.hextweaks.mixin;

import at.petrak.hexcasting.api.spell.math.HexPattern;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(targets = "at.petrak.hexcasting.api.PatternRegistry$PerWorldEntry")
public interface MixinPerWorldEntry {
@Accessor
HexPattern getPrototype();

@Accessor
ResourceLocation getOpId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.walksanator.hextweaks.mixin;

import at.petrak.hexcasting.api.spell.math.HexDir;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(targets = "at.petrak.hexcasting.api.PatternRegistry$RegularEntry")
public interface MixinRegularEntry {
@Accessor
HexDir getPreferredStart();

@Accessor
ResourceLocation getOpId();
}
Loading

0 comments on commit 069984c

Please sign in to comment.