Skip to content

Commit

Permalink
Implemented the thermoregulator. Closes #805, #726
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 7, 2024
1 parent 8a92d2b commit 86c5527
Show file tree
Hide file tree
Showing 22 changed files with 919 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
public class TANContainerTypes
{
public static MenuType<?> WATER_PURIFIER;
public static MenuType<?> THERMOREGULATOR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
******************************************************************************/
package toughasnails.api.temperature;

import net.minecraft.core.BlockPos;

import java.util.Set;

public interface ITemperature
{
/**
Expand Down Expand Up @@ -54,6 +58,18 @@ public interface ITemperature
*/
int getLastHyperthermiaTicks();

/**
* Get the last positions of nearby thermoregulators.
* @return nearby thermoregulators.
*/
Set<BlockPos> getLastNearbyThermoregulators();

/**
* Get the positions of nearby thermoregulators.
* @return nearby thermoregulators.
*/
Set<BlockPos> getNearbyThermoregulators();

/**
* Set the temperature level.
* @param level temperature level
Expand Down Expand Up @@ -101,4 +117,16 @@ public interface ITemperature
* @param ticks number of ticks.
*/
void setLastHyperthermiaTicks(int ticks);

/**
* Set the last nearby thermoregulators.
* @param values nearby thermoregulators.
*/
void setLastNearbyThermoregulators(Set<BlockPos> values);

/**
* Set the nearby thermoregulators.
* @param values nearby thermoregulators.
*/
void setNearbyThermoregulators(Set<BlockPos> values);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static int getTicksHyperthermic(Player player)
* @param state the state to check.
* @return is heating.
*/
public static boolean isHeating(BlockState state)
public static boolean isHeatingBlock(BlockState state)
{
return Impl.INSTANCE.isHeating(state);
}
Expand All @@ -106,7 +106,7 @@ public static boolean isHeating(BlockState state)
* @param state the state to check.
* @return is cooling.
*/
public static boolean isCooling(BlockState state)
public static boolean isCoolingBlock(BlockState state)
{
return Impl.INSTANCE.isCooling(state);
}
Expand Down
35 changes: 21 additions & 14 deletions common/src/main/java/toughasnails/block/ThermoregulatorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
Expand All @@ -17,6 +20,7 @@
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import toughasnails.api.blockentity.TANBlockEntityTypes;
import toughasnails.block.entity.ThermoregulatorBlockEntity;
import toughasnails.block.entity.WaterPurifierBlockEntity;
Expand All @@ -43,6 +47,20 @@ protected MapCodec<? extends BaseEntityBlock> codec()
return CODEC;
}

@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit)
{
if (worldIn.isClientSide)
{
return InteractionResult.SUCCESS;
}
else
{
player.openMenu(state.getMenuProvider(worldIn, pos));
return InteractionResult.CONSUME;
}
}

@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
{
Expand Down Expand Up @@ -87,20 +105,9 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(FACING, COOLING, HEATING);
}

public static Effect getEffect(BlockState state)
{
boolean heating = state.getValue(HEATING);
boolean cooling = state.getValue(COOLING);

if (heating && cooling) return Effect.NEUTRALIZING;
else if (heating) return Effect.HEATING;
else return Effect.COOLING;
}

public enum Effect
@Override
public RenderShape getRenderShape(BlockState state)
{
HEATING,
COOLING,
NEUTRALIZING
return RenderShape.MODEL;
}
}
Loading

0 comments on commit 86c5527

Please sign in to comment.