Skip to content

Commit

Permalink
Merge pull request #51 from refinedmods/feat/GH-50/mc-port
Browse files Browse the repository at this point in the history
feat: port to minecraft 1.20.4
  • Loading branch information
raoulvdberge authored Jan 29, 2024
2 parents 5f16051 + 19ef6ae commit c8247be
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
types: [ opened, synchronize, reopened ]
jobs:
build:
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.11.3
with:
mutation-testing: false
sonarqube: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
type: string
jobs:
draft:
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.11.3
with:
release-type: ${{ inputs.release-type }}
version-number-override: ${{ inputs.version-number-override }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issue-for-unsupported-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on:
types: [ labeled, unlabeled, reopened ]
jobs:
unsupported-labeler:
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.11.3
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- closed
jobs:
publish-release:
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.11.3
secrets: inherit
with:
project-name: 'Ranged Pumps'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/resolved-issue-locking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on:
- cron: '0 0 * * *'
jobs:
lock:
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.11.3
2 changes: 1 addition & 1 deletion .github/workflows/validate-branch-name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Validate branch name
on: [ pull_request ]
jobs:
validate-branch-name:
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.11.3
2 changes: 1 addition & 1 deletion .github/workflows/validate-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ on:
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
jobs:
validate-changelog:
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.11.3
with:
validation-level: 'warn'
2 changes: 1 addition & 1 deletion .github/workflows/validate-commit-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Validate commit messages
on: [ pull_request ]
jobs:
validate-commit-messages:
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.7.1
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.11.3
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ eclipse/
.nb-gradle-properties
.project
*.launch
run/
runs/
*.iml
*.ipr
*.iws
Expand Down
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Ported to Minecraft 1.20.4.

## [1.1.0] - 2023-07-07

### Changed
Expand Down Expand Up @@ -65,7 +69,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Port to Minecraft 1.16.

## [0.7.1] - 2020-01-30
## [0.11.3] - 2020-01-30

### Added

Expand Down Expand Up @@ -156,9 +160,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[0.8.1]: https://github.com/refinedmods/rangedpumps/compare/v0.8.0...v0.8.1

[0.8.0]: https://github.com/refinedmods/rangedpumps/compare/v0.7.1...v0.8.0
[0.8.0]: https://github.com/refinedmods/rangedpumps/compare/v0.11.3...v0.8.0

[0.7.1]: https://github.com/refinedmods/rangedpumps/compare/v0.7.0...v0.7.1
[0.11.3]: https://github.com/refinedmods/rangedpumps/compare/v0.7.0...v0.11.3

[0.7.0]: https://github.com/refinedmods/rangedpumps/compare/v0.6.1...v0.7.0

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)

Copyright © 2016 - 2023 Refined Mods
Copyright © 2016 - 2024 Refined Mods

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply from: "https://raw.githubusercontent.com/refinedmods/refinedarchitect/v0.7.1/helper.gradle"
apply from: "https://raw.githubusercontent.com/refinedmods/refinedarchitect/v0.11.3/helper.gradle"

group = 'com.refinedmods'

Expand Down
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
61 changes: 40 additions & 21 deletions src/main/java/com/refinedmods/rangedpumps/RangedPumps.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,69 @@
import com.refinedmods.rangedpumps.block.PumpBlock;
import com.refinedmods.rangedpumps.blockentity.PumpBlockEntity;
import com.refinedmods.rangedpumps.config.ServerConfig;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.RegisterEvent;

@Mod(RangedPumps.ID)
public final class RangedPumps {
public static final String ID = "rangedpumps";

private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ID);
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ID);
private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ID);
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(BuiltInRegistries.ITEM, ID);
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(BuiltInRegistries.BLOCK, ID);
private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES =
DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, ID);

public static RegistryObject<PumpBlock> PUMP_BLOCK;
public static RegistryObject<BlockEntityType<PumpBlockEntity>> PUMP_BLOCK_ENTITY_TYPE;
public static DeferredHolder<Block, PumpBlock> PUMP_BLOCK = BLOCKS.register("pump", PumpBlock::new);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PumpBlockEntity>> PUMP_BLOCK_ENTITY_TYPE =
BLOCK_ENTITY_TYPES
.register("pump", () -> BlockEntityType.Builder.of(PumpBlockEntity::new, PUMP_BLOCK.get()).build(null));

public static final ServerConfig SERVER_CONFIG = new ServerConfig();

public RangedPumps() {
PUMP_BLOCK = BLOCKS.register("pump", PumpBlock::new);
public RangedPumps(final IEventBus eventBus) {
ITEMS.register("pump", () -> new BlockItem(PUMP_BLOCK.get(), new Item.Properties()));
PUMP_BLOCK_ENTITY_TYPE = BLOCK_ENTITY_TYPES.register("pump", () -> BlockEntityType.Builder.of(PumpBlockEntity::new, PUMP_BLOCK.get()).build(null));
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG.getSpec());
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
BLOCK_ENTITY_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
FMLJavaModLoadingContext.get().getModEventBus().addListener(RangedPumps::onRegister);
BLOCKS.register(eventBus);
ITEMS.register(eventBus);
BLOCK_ENTITY_TYPES.register(eventBus);
eventBus.addListener(RangedPumps::onRegister);
eventBus.addListener(RangedPumps::onRegisterCapabilities);
}

public static void onRegisterCapabilities(RegisterCapabilitiesEvent e) {
e.registerBlockEntity(
Capabilities.EnergyStorage.BLOCK,
PUMP_BLOCK_ENTITY_TYPE.get(),
(be, ctx) -> be.getEnergy()
);
e.registerBlockEntity(
Capabilities.FluidHandler.BLOCK,
PUMP_BLOCK_ENTITY_TYPE.get(),
(be, ctx) -> be.getTank()
);
}

public static void onRegister(RegisterEvent e) {
e.register(Registries.CREATIVE_MODE_TAB, helper -> {
helper.register("general", CreativeModeTab.builder()
helper.register(new ResourceLocation(RangedPumps.ID, "general"), CreativeModeTab.builder()
.title(Component.translatable("itemGroup.rangedpumps"))
.icon(() -> new ItemStack(RangedPumps.PUMP_BLOCK.get()))
.displayItems((params, output) -> {
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/com/refinedmods/rangedpumps/block/PumpBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.refinedmods.rangedpumps.RangedPumps;
import com.refinedmods.rangedpumps.blockentity.PumpBlockEntity;
import com.refinedmods.rangedpumps.blockentity.PumpState;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -17,21 +19,26 @@
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.common.capabilities.ForgeCapabilities;
import net.minecraftforge.energy.IEnergyStorage;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.energy.IEnergyStorage;

public class PumpBlock extends Block implements EntityBlock {
public PumpBlock() {
super(Block.Properties.of().strength(1.9F).sound(SoundType.STONE));
}

@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
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 PumpBlockEntity pump) {
IEnergyStorage energy = pump.getCapability(ForgeCapabilities.ENERGY).orElse(null);
IEnergyStorage energy = level.getCapability(
Capabilities.EnergyStorage.BLOCK,
pos,
Direction.NORTH
);
if (energy == null) {
return InteractionResult.SUCCESS;
}
Expand All @@ -43,9 +50,12 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
}

if (pump.getTank().getFluidAmount() == 0) {
player.sendSystemMessage(Component.translatable("block." + RangedPumps.ID + ".pump.state_empty", energy.getEnergyStored(), energy.getMaxEnergyStored()));
player.sendSystemMessage(Component.translatable("block." + RangedPumps.ID + ".pump.state_empty",
energy.getEnergyStored(), energy.getMaxEnergyStored()));
} else {
player.sendSystemMessage(Component.translatable("block." + RangedPumps.ID + ".pump.state", pump.getTank().getFluidAmount(), pump.getTank().getFluid().getDisplayName(), energy.getEnergyStored(), energy.getMaxEnergyStored()));
player.sendSystemMessage(Component.translatable("block." + RangedPumps.ID + ".pump.state",
pump.getTank().getFluidAmount(), pump.getTank().getFluid().getDisplayName(),
energy.getEnergyStored(), energy.getMaxEnergyStored()));
}
}
}
Expand All @@ -59,7 +69,9 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
}

@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return !level.isClientSide ? (levelTicker, pos, stateTicker, blockEntity) -> ((PumpBlockEntity) blockEntity).tick() : null;
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state,
BlockEntityType<T> type) {
return !level.isClientSide ?
(levelTicker, pos, stateTicker, blockEntity) -> ((PumpBlockEntity) blockEntity).tick() : null;
}
}
Loading

0 comments on commit c8247be

Please sign in to comment.