generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5312448
commit 645460f
Showing
9 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/github/unix_supremacist/item/BuildersStone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/alchemist/models/item/builders_stone.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "alchemist:item/builders_stone" | ||
} | ||
} |
Binary file added
BIN
+240 Bytes
src/main/resources/assets/alchemist/textures/item/builders_stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.