Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "cryptoworld:block/miner_block"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "cryptoworld:block/miner_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "cryptoworld:block/miner_block"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "cryptoworld:miner_block"
}
],
"rolls": 1.0
}
],
"random_sequence": "cryptoworld:blocks/miner_block"
}
15 changes: 15 additions & 0 deletions src/generated/resources/data/cryptoworld/recipes/miner_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"IGI",
"RFR",
"III"
],
"key": {
"I": { "item": "minecraft:iron_ingot" },
"G": { "item": "cryptoworld:gtx_1080" },
"R": { "item": "cryptoworld:ram" },
"F": { "item": "cryptoworld:silicium_hypercharged" }
},
"result": { "item": "cryptoworld:miner_block" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"cryptoworld:cryptonium_block",
"cryptoworld:server_block",
"cryptoworld:silicium_ore",
"cryptoworld:silicium_block"
"cryptoworld:silicium_block",
"cryptoworld:miner_block"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"values": [
"cryptoworld:silicium_ore",
"cryptoworld:server_block"
"cryptoworld:server_block",
"cryptoworld:miner_block"
]
}
7 changes: 7 additions & 0 deletions src/main/java/fr/jachou/cryptoworld/CryptoWorld.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package fr.jachou.cryptoworld;

import fr.jachou.cryptoworld.block.ModBlocks;
import fr.jachou.cryptoworld.blockentity.ModBlockEntities;
import fr.jachou.cryptoworld.menu.ModMenuTypes;
import fr.jachou.cryptoworld.screen.MinerScreen;
import net.minecraft.client.gui.screens.MenuScreens;
import fr.jachou.cryptoworld.datagen.DataGenerators;
import fr.jachou.cryptoworld.item.ModCreativeModTabs;
import fr.jachou.cryptoworld.item.ModItems;
Expand All @@ -24,6 +28,8 @@ public CryptoWorld() {
ModCreativeModTabs.register(bus);
ModItems.register(bus);
ModBlocks.register(bus);
ModBlockEntities.register(bus);
ModMenuTypes.register(bus);

bus.addListener(this::setup);
MinecraftForge.EVENT_BUS.register(this);
Expand All @@ -43,5 +49,6 @@ private void setup(final FMLCommonSetupEvent event) {
}

private void doClientStuff(final FMLClientSetupEvent event) {
MenuScreens.register(ModMenuTypes.MINER_MENU.get(), MinerScreen::new);
}
}
51 changes: 51 additions & 0 deletions src/main/java/fr/jachou/cryptoworld/block/MinerBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fr.jachou.cryptoworld.block;

import fr.jachou.cryptoworld.blockentity.MinerBlockEntity;
import fr.jachou.cryptoworld.blockentity.ModBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

public class MinerBlock extends Block implements EntityBlock {
public MinerBlock(Properties properties) {
super(properties);
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player,
InteractionHand hand, BlockHitResult hit) {
if (!level.isClientSide) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof MinerBlockEntity) {
NetworkHooks.openScreen((ServerPlayer) player, (MinerBlockEntity) blockEntity, pos);
} else {
throw new IllegalStateException("Missing miner block entity!");
}
}
return InteractionResult.sidedSuccess(level.isClientSide);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new MinerBlockEntity(pos, state);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return level.isClientSide ? null : createTickerHelper(type, ModBlockEntities.MINER_BLOCK_ENTITY.get(), MinerBlockEntity::tick);
}
}
4 changes: 4 additions & 0 deletions src/main/java/fr/jachou/cryptoworld/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.jachou.cryptoworld.block;

import fr.jachou.cryptoworld.CryptoWorld;
import fr.jachou.cryptoworld.block.MinerBlock;
import fr.jachou.cryptoworld.item.ModItems;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.item.BlockItem;
Expand All @@ -21,6 +22,9 @@ public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS =
DeferredRegister.create(ForgeRegistries.BLOCKS, CryptoWorld.MODID);

public static final RegistryObject<Block> MINER_BLOCK = registerBlock("miner_block",
() -> new MinerBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK)));

public static final RegistryObject<Block> SERVER_BLOCK = registerBlock("server_block",
() -> new Block(BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK)));

Expand Down
119 changes: 119 additions & 0 deletions src/main/java/fr/jachou/cryptoworld/blockentity/MinerBlockEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package fr.jachou.cryptoworld.blockentity;

import fr.jachou.cryptoworld.item.ModItems;
import fr.jachou.cryptoworld.menu.MinerMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MinerBlockEntity extends BlockEntity implements net.minecraft.world.MenuProvider {
private final ItemStackHandler itemHandler = new ItemStackHandler(4) {
@Override
protected void onContentsChanged(int slot) {
setChanged();
}

@Override
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
return switch (slot) {
case 0 -> stack.is(ModItems.GTX_1080.get()) || stack.is(ModItems.RTX_2080.get());
case 1 -> stack.is(ModItems.RAM.get());
case 2 -> stack.is(ModItems.SILICIUM_HYPERCHARGED.get());
case 3 -> stack.is(ModItems.BITCOIN.get()) || stack.is(ModItems.ETHEREUM.get());
default -> super.isItemValid(slot, stack);
};
}
};

private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();

public MinerBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.MINER_BLOCK_ENTITY.get(), pos, state);
}

@Override
public void onLoad() {
super.onLoad();
lazyItemHandler = LazyOptional.of(() -> itemHandler);
}

@Override
public void invalidateCaps() {
super.invalidateCaps();
lazyItemHandler.invalidate();
}

@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable net.minecraft.core.Direction side) {
if (cap == ForgeCapabilities.ITEM_HANDLER) {
return lazyItemHandler.cast();
}
return super.getCapability(cap, side);
}

@Override
protected void saveAdditional(CompoundTag tag) {
tag.put("inventory", itemHandler.serializeNBT());
super.saveAdditional(tag);
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
itemHandler.deserializeNBT(tag.getCompound("inventory"));
}

@Override
public Component getDisplayName() {
return Component.translatable("block.cryptoworld.miner_block");
}

@Nullable
@Override
public AbstractContainerMenu createMenu(int id, net.minecraft.world.entity.player.Inventory inventory, Player player) {
return new MinerMenu(id, inventory, this);
}

public ItemStackHandler getItemHandler() {
return itemHandler;
}

public static void tick(Level level, BlockPos pos, BlockState state, MinerBlockEntity entity) {
if (level.isClientSide) {
return;
}

ItemStack gpu = entity.itemHandler.getStackInSlot(0);
ItemStack ram = entity.itemHandler.getStackInSlot(1);
ItemStack fuel = entity.itemHandler.getStackInSlot(2);
ItemStack output = entity.itemHandler.getStackInSlot(3);

if (!gpu.isEmpty() && !ram.isEmpty() && fuel.is(ModItems.SILICIUM_HYPERCHARGED.get())) {
Item coinItem = level.random.nextBoolean() ? ModItems.BITCOIN.get() : ModItems.ETHEREUM.get();
if (output.isEmpty()) {
entity.itemHandler.setStackInSlot(3, new ItemStack(coinItem));
fuel.shrink(1);
setChanged(level, pos, state);
} else if (output.is(coinItem) && output.getCount() < output.getMaxStackSize()) {
output.grow(1);
fuel.shrink(1);
setChanged(level, pos, state);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fr.jachou.cryptoworld.blockentity;

import fr.jachou.cryptoworld.CryptoWorld;
import fr.jachou.cryptoworld.block.ModBlocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModBlockEntities {
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, CryptoWorld.MODID);

public static final RegistryObject<BlockEntityType<MinerBlockEntity>> MINER_BLOCK_ENTITY = BLOCK_ENTITIES.register("miner_block_entity",
() -> BlockEntityType.Builder.of(MinerBlockEntity::new, ModBlocks.MINER_BLOCK.get()).build(null));

public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected void registerStatesAndModels() {
blockWithItem(ModBlocks.SILICIUM_ORE);
blockWithItem(ModBlocks.SILICIUM_BLOCK);
blockWithItem(ModBlocks.SERVER_BLOCK);
blockWithItem(ModBlocks.MINER_BLOCK);
}

private void blockWithItem(RegistryObject<Block> blockRegistryObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ protected void addTags(HolderLookup.Provider provider) {
ModBlocks.CRYPTONIUM_BLOCK.get(),
ModBlocks.SERVER_BLOCK.get(),
ModBlocks.SILICIUM_ORE.get(),
ModBlocks.SILICIUM_BLOCK.get());
ModBlocks.SILICIUM_BLOCK.get(),
ModBlocks.MINER_BLOCK.get());

this.tag(BlockTags.NEEDS_DIAMOND_TOOL)
.add(ModBlocks.CRYPTONIUM_ORE.get()).add(ModBlocks.CRYPTONIUM_BLOCK.get());

this.tag(BlockTags.NEEDS_IRON_TOOL)
.add(ModBlocks.SILICIUM_ORE.get()).add(ModBlocks.SERVER_BLOCK.get());
.add(ModBlocks.SILICIUM_ORE.get())
.add(ModBlocks.SERVER_BLOCK.get())
.add(ModBlocks.MINER_BLOCK.get());
}
}
11 changes: 11 additions & 0 deletions src/main/java/fr/jachou/cryptoworld/datagen/ModRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ protected void buildRecipes(RecipeOutput recipeOutput) {
.save(recipeOutput);


ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.MINER_BLOCK.get())
.pattern("IGI")
.pattern("RFR")
.pattern("III")
.define('I', Items.IRON_INGOT)
.define('G', ModItems.GTX_1080.get())
.define('R', ModItems.RAM.get())
.define('F', ModItems.SILICIUM_HYPERCHARGED.get())
.unlockedBy(getHasName(ModItems.GTX_1080.get()), has(ModItems.GTX_1080.get()))
.save(recipeOutput);

}

protected static <T extends AbstractCookingRecipe> void oreCooking(RecipeOutput pRecipeOutput, RecipeSerializer<T> pCookingSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected void generate() {
this.dropSelf(ModBlocks.CRYPTONIUM_ORE.get());
this.dropSelf(ModBlocks.SERVER_BLOCK.get());
this.dropSelf(ModBlocks.SILICIUM_ORE.get());
this.dropSelf(ModBlocks.MINER_BLOCK.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ModCreativeModTabs {
pOutput.accept(ModBlocks.SILICIUM_ORE.get());
pOutput.accept(ModBlocks.CRYPTONIUM_BLOCK.get());
pOutput.accept(ModBlocks.SILICIUM_BLOCK.get());
pOutput.accept(ModBlocks.MINER_BLOCK.get());
})
.build());

Expand Down
Loading
Loading