generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
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
ellieisjelly
committed
Jan 6, 2024
1 parent
5c22839
commit 7c32cad
Showing
10 changed files
with
186 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
package me.ellieis.Sabotage; | ||
|
||
import me.ellieis.Sabotage.game.config.SabotageConfig; | ||
import me.ellieis.Sabotage.game.custom.SabotageBlocks; | ||
import me.ellieis.Sabotage.game.custom.SabotageItems; | ||
import me.ellieis.Sabotage.game.phase.SabotageActive; | ||
import me.ellieis.Sabotage.game.phase.SabotageWaiting; | ||
import net.fabricmc.api.ModInitializer; | ||
|
||
import net.minecraft.util.Identifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import xyz.nucleoid.plasmid.game.GameType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Sabotage implements ModInitializer { | ||
public static final String MOD_ID = "sabotage"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
private static final Identifier SABOTAGE_ID = new Identifier(MOD_ID, "sabotage"); | ||
public static final Identifier SABOTAGE_ID = new Identifier(MOD_ID, "sabotage"); | ||
public static final GameType GAME_TYPE = GameType.register(SABOTAGE_ID, SabotageConfig.CODEC, SabotageWaiting::Open); | ||
public static final List<SabotageActive> activeGames = new ArrayList<>(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
SabotageBlocks.register(); | ||
SabotageItems.register(); | ||
} | ||
|
||
public static Identifier identifier(String value) { | ||
return new Identifier(MOD_ID, value); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/me/ellieis/Sabotage/game/custom/SabotageBlocks.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,68 @@ | ||
package me.ellieis.Sabotage.game.custom; | ||
|
||
import eu.pb4.polymer.core.api.block.PolymerBlockUtils; | ||
import me.ellieis.Sabotage.Sabotage; | ||
import me.ellieis.Sabotage.game.custom.blocks.SabotageChest; | ||
import me.ellieis.Sabotage.game.custom.blocks.SabotageChestBlockEntity; | ||
import me.ellieis.Sabotage.game.phase.SabotageActive; | ||
import net.fabricmc.fabric.api.event.player.UseBlockCallback; | ||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.world.World; | ||
|
||
|
||
public class SabotageBlocks { | ||
public static final Block SABOTAGE_CHEST = new SabotageChest(AbstractBlock.Settings.copy(Blocks.CHEST).dropsNothing(), Blocks.CHEST); | ||
|
||
public static final BlockEntityType<SabotageChestBlockEntity> SABOTAGE_CHEST_ENTITY = FabricBlockEntityTypeBuilder.create(SabotageChestBlockEntity::new, SABOTAGE_CHEST).build(null); | ||
public static void register() { | ||
register("sabotage_chest", SABOTAGE_CHEST); | ||
|
||
registerBlockEntity("sabotage_chest_block_entity", SABOTAGE_CHEST_ENTITY); | ||
|
||
UseBlockCallback.EVENT.register(SabotageBlocks::onBlockUse); | ||
} | ||
|
||
private static ActionResult onBlockUse(PlayerEntity plr, World world, Hand hand, BlockHitResult blockHitResult) { | ||
boolean isInGame = false; | ||
|
||
for (SabotageActive game : Sabotage.activeGames) { | ||
if (game.getWorld().equals(world)) { | ||
isInGame = true; | ||
break; | ||
} | ||
} | ||
if (isInGame) { | ||
if (blockHitResult != null) { | ||
Block block = world.getBlockState(blockHitResult.getBlockPos()).getBlock(); | ||
if (block instanceof SabotageChest) { | ||
plr.playSound(SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 1, 1.2f); | ||
world.setBlockState(blockHitResult.getBlockPos(), Blocks.AIR.getDefaultState()); | ||
return ActionResult.FAIL; | ||
} | ||
} | ||
} | ||
return ActionResult.PASS; | ||
} | ||
|
||
private static <T extends Block> T register(String id, T block) { | ||
return Registry.register(Registries.BLOCK, Sabotage.identifier(id), block); | ||
} | ||
private static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(String id, BlockEntityType<T> type) { | ||
Registry.register(Registries.BLOCK_ENTITY_TYPE, Sabotage.identifier(id), type); | ||
PolymerBlockUtils.registerBlockEntity(SABOTAGE_CHEST_ENTITY); | ||
return type; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/me/ellieis/Sabotage/game/custom/SabotageItems.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,19 @@ | ||
package me.ellieis.Sabotage.game.custom; | ||
|
||
import me.ellieis.Sabotage.Sabotage; | ||
import me.ellieis.Sabotage.game.custom.items.SabotageChest; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public class SabotageItems { | ||
public static final Item SABOTAGE_CHEST = new SabotageChest(SabotageBlocks.SABOTAGE_CHEST, new Item.Settings(), Items.CHEST); | ||
|
||
public static void register() { | ||
register("sabotage_chest", SABOTAGE_CHEST); | ||
} | ||
private static <T extends Item> T register(String id, T item) { | ||
return Registry.register(Registries.ITEM, Sabotage.identifier(id), item); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChest.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,29 @@ | ||
package me.ellieis.Sabotage.game.custom.blocks; | ||
|
||
import eu.pb4.polymer.core.api.block.PolymerBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockEntityProvider; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SabotageChest extends Block implements BlockEntityProvider, PolymerBlock { | ||
private final Block virtualBlock; | ||
|
||
public SabotageChest(Settings settings, Block virtualBlock) { | ||
super(settings); | ||
|
||
this.virtualBlock = virtualBlock; | ||
} | ||
|
||
@Override | ||
public Block getPolymerBlock(BlockState state) { | ||
return this.virtualBlock; | ||
} | ||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new SabotageChestBlockEntity(pos, state); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChestBlockEntity.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,13 @@ | ||
package me.ellieis.Sabotage.game.custom.blocks; | ||
|
||
import me.ellieis.Sabotage.game.custom.SabotageBlocks; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class SabotageChestBlockEntity extends BlockEntity { | ||
|
||
public SabotageChestBlockEntity(BlockPos pos, BlockState state) { | ||
super(SabotageBlocks.SABOTAGE_CHEST_ENTITY, pos, state); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/me/ellieis/Sabotage/game/custom/items/SabotageChest.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,11 @@ | ||
package me.ellieis.Sabotage.game.custom.items; | ||
|
||
import eu.pb4.polymer.core.api.item.PolymerBlockItem; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.Item; | ||
|
||
public class SabotageChest extends PolymerBlockItem { | ||
public SabotageChest(Block block, Settings settings, Item virtualItem) { | ||
super(block, settings, virtualItem); | ||
} | ||
} |
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