generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
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
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...ain/java/com/portingdeadmods/nautec/content/blockentities/EnergyConverterBlockEntity.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,92 @@ | ||
package com.portingdeadmods.nautec.content.blockentities; | ||
|
||
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity; | ||
import com.portingdeadmods.nautec.capabilities.IOActions; | ||
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes; | ||
import it.unimi.dsi.fastutil.Pair; | ||
import it.unimi.dsi.fastutil.objects.ObjectSet; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.neoforged.neoforge.capabilities.BlockCapability; | ||
import net.neoforged.neoforge.energy.IEnergyStorage; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
public class EnergyConverterBlockEntity extends LaserBlockEntity implements IEnergyStorage { | ||
private static final int FE_CONVERSION_RATE = 100; | ||
private int feStored = 0; | ||
private static final int MAX_FE = 100000; | ||
|
||
public EnergyConverterBlockEntity(BlockPos blockPos, BlockState blockState) { | ||
super(NTBlockEntityTypes.ENERGY_CONVERTER.get(), blockPos, blockState); | ||
} | ||
|
||
@Override | ||
public ObjectSet<Direction> getLaserInputs() { | ||
return ObjectSet.of(); | ||
} | ||
|
||
@Override | ||
public ObjectSet<Direction> getLaserOutputs() { | ||
return ObjectSet.of(Direction.values()); | ||
} | ||
|
||
@Override | ||
public <T> Map<Direction, Pair<IOActions, int[]>> getSidedInteractions(BlockCapability<T, @Nullable Direction> capability) { | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public void commonTick() { | ||
if (!level.isClientSide) { | ||
Direction[] directions = Direction.values(); | ||
for (Direction direction : directions) { | ||
BlockPos pos = worldPosition.relative(direction); | ||
if (level.getBlockEntity(pos) instanceof LaserBlockEntity laserBlockEntity) { | ||
if (laserBlockEntity.getLaserInputs().contains(direction.getOpposite())) { | ||
int energyToConvert = Math.min(FE_CONVERSION_RATE, feStored); | ||
if (energyToConvert > 0) { | ||
transmitPower(energyToConvert); | ||
feStored -= energyToConvert; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@Override | ||
public int receiveEnergy(int maxReceive, boolean simulate) { | ||
int energyReceived = Math.min(MAX_FE - feStored, maxReceive); | ||
if (!simulate) { | ||
feStored += energyReceived; | ||
} | ||
return energyReceived; | ||
} | ||
|
||
@Override | ||
public int extractEnergy(int maxExtract, boolean simulate) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getEnergyStored() { | ||
return feStored; | ||
} | ||
|
||
@Override | ||
public int getMaxEnergyStored() { | ||
return MAX_FE; | ||
} | ||
|
||
@Override | ||
public boolean canExtract() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canReceive() { | ||
return true; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/portingdeadmods/nautec/content/blocks/EnergyConverterBlock.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.portingdeadmods.nautec.content.blocks; | ||
|
||
import com.portingdeadmods.nautec.content.blockentities.EnergyConverterBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
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.state.BlockState; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EnergyConverterBlock extends Block implements EntityBlock { | ||
public EnergyConverterBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) { | ||
return new EnergyConverterBlockEntity(pos,state); | ||
} | ||
} |
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