generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
15 changed files
with
272 additions
and
81 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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlock.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,59 @@ | ||
package com.doublepi.taus_economy.blocks; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.block.*; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.block.state.properties.BlockStateProperties; | ||
import net.minecraft.world.level.block.state.properties.DirectionProperty; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class PlayerVaultBlock extends BaseEntityBlock { | ||
public static final MapCodec<PlayerVaultBlock> CODEC = simpleCodec(PlayerVaultBlock::new); | ||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | ||
|
||
public PlayerVaultBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
protected MapCodec<? extends BaseEntityBlock> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
protected RenderShape getRenderShape(BlockState pState) { | ||
return RenderShape.MODEL; | ||
} | ||
|
||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
} | ||
|
||
@Override | ||
public BlockState rotate(BlockState state, LevelAccessor level, BlockPos pos, Rotation direction) { | ||
return state.setValue(FACING, direction.rotate(state.getValue(FACING))); | ||
} | ||
|
||
@Override | ||
protected BlockState mirror(BlockState state, Mirror mirror) { | ||
return state.rotate(mirror.getRotation(state.getValue(FACING))); | ||
} | ||
|
||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext context) { | ||
return this.defaultBlockState() | ||
.setValue(FACING, context.getHorizontalDirection().getOpposite()); | ||
} | ||
|
||
@Override | ||
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { | ||
return new PlayerVaultBlockEntity(blockPos,blockState); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlockEntity.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,14 @@ | ||
package com.doublepi.taus_economy.blocks; | ||
|
||
import com.doublepi.taus_economy.registries.ModBlocks; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class PlayerVaultBlockEntity extends BlockEntity { | ||
public PlayerVaultBlockEntity(BlockPos pos, BlockState blockState) { | ||
super(ModBlocks.PLAYER_VAULT_BE.get(), pos, blockState); | ||
} | ||
|
||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/doublepi/taus_economy/registries/ModBlocks.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,61 @@ | ||
package com.doublepi.taus_economy.registries; | ||
|
||
import com.doublepi.taus_economy.TausEconomy; | ||
import com.doublepi.taus_economy.blocks.PlayerVaultBlock; | ||
import com.doublepi.taus_economy.blocks.PlayerVaultBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.BlockGetter; | ||
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.level.block.VaultBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; | ||
import net.minecraft.world.level.material.MapColor; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.registries.DeferredBlock; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ModBlocks { | ||
|
||
//Deferred Register | ||
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(TausEconomy.MOD_ID); | ||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = | ||
DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, TausEconomy.MOD_ID); | ||
|
||
//Player Vault | ||
public static final DeferredBlock<Block> PLAYER_VAULT = registerBlock("player_vault", | ||
()-> new PlayerVaultBlock(BlockBehaviour.Properties.of() | ||
.mapColor(MapColor.STONE).instrument(NoteBlockInstrument.BASEDRUM) | ||
.noOcclusion().sound(SoundType.VAULT).strength(50).lightLevel((blockState)->7) | ||
.isViewBlocking(ModBlocks::never))); | ||
|
||
public static final Supplier<BlockEntityType<PlayerVaultBlockEntity>> PLAYER_VAULT_BE = | ||
BLOCK_ENTITIES.register("player_vault_be", () -> BlockEntityType.Builder.of( | ||
PlayerVaultBlockEntity::new, ModBlocks.PLAYER_VAULT.get()).build(null)); | ||
|
||
private static boolean never(BlockState state, BlockGetter blockGetter, BlockPos pos) { | ||
return false; | ||
} | ||
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block){ | ||
DeferredBlock<T> toReturn = BLOCKS.register(name,block); | ||
registerBlockItem(name,toReturn); | ||
return toReturn; | ||
} | ||
private static <T extends Block> void registerBlockItem(String name, DeferredBlock<T> block){ | ||
ModItems.ITEMS.register(name, ()-> new BlockItem(block.get(), new Item.Properties())); | ||
} | ||
public static void register(IEventBus eventBus){ | ||
BLOCKS.register(eventBus); | ||
BLOCK_ENTITIES.register(eventBus); | ||
} | ||
} | ||
|
||
|
31 changes: 31 additions & 0 deletions
31
src/main/java/com/doublepi/taus_economy/registries/ModEvents.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,31 @@ | ||
package com.doublepi.taus_economy.registries; | ||
|
||
import com.doublepi.taus_economy.Config; | ||
import net.minecraft.advancements.Advancement; | ||
import net.minecraft.advancements.AdvancementType; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
import net.neoforged.neoforge.event.entity.player.AdvancementEvent; | ||
|
||
public class ModEvents { | ||
|
||
public static void register(){ | ||
NeoForge.EVENT_BUS.addListener(ModEvents::giveToken); | ||
} | ||
|
||
private static void giveToken(AdvancementEvent.AdvancementEarnEvent event){ | ||
Advancement advancement = event.getAdvancement().value(); | ||
Player player = event.getEntity(); | ||
AdvancementType type = advancement.display().get().getType(); | ||
|
||
if(type == AdvancementType.TASK) | ||
player.addItem(new ItemStack(ModItems.TOKEN.get(), Config.token_per_task)); | ||
if(type == AdvancementType.GOAL) | ||
player.addItem(new ItemStack(ModItems.TOKEN.get(),Config.token_per_goal)); | ||
if(type == AdvancementType.CHALLENGE) | ||
player.addItem(new ItemStack(ModItems.TOKEN.get(),Config.token_per_challenge)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/doublepi/taus_economy/registries/ModItems.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,20 @@ | ||
package com.doublepi.taus_economy.registries; | ||
|
||
import com.doublepi.taus_economy.TausEconomy; | ||
import net.minecraft.world.item.Item; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.registries.DeferredItem; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
|
||
public class ModItems { | ||
|
||
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(TausEconomy.MOD_ID); | ||
|
||
public static final DeferredItem<Item> TOKEN = ITEMS.register("token", | ||
()-> new Item(new Item.Properties())); | ||
|
||
|
||
public static void register(IEventBus eventBus) { | ||
ITEMS.register(eventBus); | ||
} | ||
} |
Oops, something went wrong.