Skip to content

Commit

Permalink
initial builders stone
Browse files Browse the repository at this point in the history
  • Loading branch information
unix-supremacist committed Jun 13, 2024
1 parent 5312448 commit 645460f
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/main/generated/assets/alchemist/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"block.alchemist.transmutation_circle": "Transmutation Circle",
"item.alchemist.aeternalis_fuel": "Aeternalis Fuel",
"item.alchemist.alchemical_coal": "Alchemical Coal",
"item.alchemist.builders_stone": "Builders Stone",
"item.alchemist.catalytic_lens": "Catalytic Lens",
"item.alchemist.chalk": "Chalk",
"item.alchemist.coal_coke": "Coal Coke",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import eu.pb4.factorytools.api.item.ModeledItem;
import io.github.unix_supremacist.Alchemist;
import io.github.unix_supremacist.item.AlchemistBlockItem;
import io.github.unix_supremacist.item.DestructionItem;
import io.github.unix_supremacist.item.GaleItem;
import io.github.unix_supremacist.item.PhilosophersStoneItem;
import io.github.unix_supremacist.item.*;
import lombok.Getter;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.registry.FuelRegistry;
Expand All @@ -23,6 +20,7 @@ public enum AlchemistItems {
aeternalis_fuel(1638400, Items.NETHERITE_SCRAP),
//archangels_smite,
//black_hole_band,
builders_stone(new BuildersStone(new Properties().stacksTo(1).durability(16),4,4)),
catalytic_lens(new DestructionItem(new Properties().stacksTo(1).durability(30), 3, 10, 5, Items.GOLD_NUGGET)),
chalk(new AlchemistBlockItem(AlchemistBlocks.transmutation_circle.getBlock(), new Properties().durability(64), Items.STICK)),
coal_coke(3200, Items.COOKED_BEEF),
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/io/github/unix_supremacist/interfaces/AreaBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,38 @@ default ArrayList<BlockPos> getAreaFromFacing(Direction dir, BlockPos anchor, in
return null;
}
}

default ArrayList<BlockPos> getAreaFromFacing(Direction dir, Direction playerDir, BlockPos anchor, int width, int height, int depth){
switch(dir) {
case SOUTH:
return getArea(dir, anchor, new BlockPos(-width, -height, -depth), new BlockPos(width, height, 0));
case NORTH:
return getArea(dir, anchor, new BlockPos(-width, -height, 0), new BlockPos(width, height, depth));
case EAST:
return getArea(dir, anchor, new BlockPos(-depth, -height, -width), new BlockPos(0, height, width));
case WEST:
return getArea(dir, anchor, new BlockPos(0, -height, -width), new BlockPos(depth, height, width));
case UP:
switch (playerDir){
case SOUTH:
case NORTH:
return getArea(dir, anchor, new BlockPos(-width, -depth, -height), new BlockPos(width, 0, height));
case EAST:
case WEST:
return getArea(dir, anchor, new BlockPos(-height, -depth, -width), new BlockPos(height, 0, width));
}
case DOWN:
switch (playerDir){
case SOUTH:
case NORTH:
return getArea(dir, anchor, new BlockPos(-width, 0, -height), new BlockPos(width, depth, height));
case EAST:
case WEST:
return getArea(dir, anchor, new BlockPos(-height, 0, -width), new BlockPos(height, depth, width));
}
default:
Alchemist.LOGGER.error("HOW DID YOU CLICK A DIRECTION THAT ISN'T NORTH SOUTH EAST WEST TOP OR BOTTOM");
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package io.github.unix_supremacist.item;

import eu.pb4.factorytools.api.item.AutoModeledPolymerItem;
import eu.pb4.factorytools.api.item.FactoryBlockItem;
import io.github.unix_supremacist.block.TransmutionCircleBlock;
import io.github.unix_supremacist.content.AlchemistItems;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.BlockItem;
Expand All @@ -19,8 +12,6 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.phys.Vec3;

public class AlchemistBlockItem extends BlockItem implements AutoModeledPolymerItem {
@Getter Item polymerItem;
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/io/github/unix_supremacist/item/BuildersStone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.unix_supremacist.item;

import io.github.unix_supremacist.interfaces.AreaBox;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;

import java.util.ArrayList;

public class BuildersStone extends AbstractEmpowerableItem implements AreaBox {
protected final int[] MODES;
private final int maxWidth;
private final int maxHeight;

public BuildersStone(Properties properties, int maxWidth, int maxHeight) {
super(properties, maxWidth * maxHeight, Items.GOLDEN_CARROT);
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;

MODES = new int[maxWidth * maxHeight * 2];
for (int i = 0; i < maxPower; i++) {
MODES[i * 2] = i % maxWidth;
MODES[i * 2 + 1] = i / maxWidth;
}
}

@Override
public void empower(ItemStack item, Player p){
super.empower(item, p);
p.displayClientMessage(Component.literal("Width: "+((maxWidth-1)*2-MODES[getPower(item)*2]*2+1)+" and Height: "+((maxHeight-1)*2-MODES[getPower(item)*2+1]*2+1)), true);
}

@Override
public InteractionResult useOn(UseOnContext context) {
InteractionResult result = super.useOn(context);
if (context.getPlayer().isShiftKeyDown() == false){
ArrayList<BlockPos> againstBlocks = getAreaFromFacing(context.getClickedFace(), context.getPlayer().getDirection(), context.getClickedPos(), maxWidth-1-MODES[getPower(context.getItemInHand())*2], (maxHeight-1-MODES[getPower(context.getItemInHand())*2+1]), 0);
ArrayList<BlockPos> blocks = getAreaFromFacing(context.getClickedFace(), context.getPlayer().getDirection(), context.getClickedPos().relative(context.getClickedFace()), maxWidth-1-MODES[getPower(context.getItemInHand())*2], (maxHeight-1-MODES[getPower(context.getItemInHand())*2+1]), 0);

if(!blocks.isEmpty()){
if (!context.getLevel().isClientSide()) for (int i = 0; i < againstBlocks.size(); i++){
BlockState state = context.getLevel().getBlockState(againstBlocks.get(i));

Block block = context.getLevel().getBlockState(blocks.get(i)).getBlock();
if (block.equals(Blocks.AIR) && state.equals(context.getLevel().getBlockState(context.getClickedPos()))) {
context.getLevel().setBlock(blocks.get(i), state, 3);
ItemStack stack = context.getPlayer().getItemInHand(context.getHand()).copy();
context.getPlayer().setItemInHand(context.getHand(), stack);
result = InteractionResult.SUCCESS;
}
}
}
}

return result;
}

}
3 changes: 2 additions & 1 deletion src/main/java/io/github/unix_supremacist/item/GaleItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.unix_supremacist.item;

import dev.emi.trinkets.api.*;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketItem;
import eu.pb4.factorytools.api.item.AutoModeledPolymerItem;
import io.github.ladysnake.pal.AbilitySource;
import io.github.ladysnake.pal.Pal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "alchemist:item/builders_stone"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/spritesheet.ase
Binary file not shown.

0 comments on commit 645460f

Please sign in to comment.