Skip to content

Commit

Permalink
add blood diffuser block
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Nov 8, 2023
1 parent b3ef984 commit c119ca0
Show file tree
Hide file tree
Showing 28 changed files with 563 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "vampirism:block/fog_diffuser_normal"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "vampirism:block/fog_diffuser",
"render_type": "minecraft:cutout"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "vampirism:block/fog_diffuser"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"vampirism:garlic_diffuser_weak",
"vampirism:garlic_diffuser_normal",
"vampirism:garlic_diffuser_improved",
"vampirism:fog_diffuser",
"vampirism:chandelier",
"vampirism:candelabra",
"vampirism:candelabra_wall",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"vampirism:garlic_diffuser_weak",
"vampirism:garlic_diffuser_normal",
"vampirism:garlic_diffuser_improved",
"vampirism:fog_diffuser",
"#vampirism:totem_top_crafted"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_cursed_plank": {
"conditions": {
"items": [
{
"items": [
"vampirism:cursed_spruce_planks"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_diamond": {
"conditions": {
"items": [
{
"tag": "forge:gems/diamond"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_mother_core": {
"conditions": {
"items": [
{
"items": [
"vampirism:mother_core"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "vampirism:vampire/fog_diffuser"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_diamond",
"has_cursed_plank",
"has_mother_core",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"vampirism:vampire/fog_diffuser"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "vampirism:fog_diffuser"
}
],
"rolls": 1.0
}
],
"random_sequence": "vampirism:blocks/fog_diffuser"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"O": {
"tag": "forge:obsidian"
},
"X": {
"item": "vampirism:cursed_spruce_planks"
},
"Y": {
"tag": "forge:gems/diamond"
},
"Z": {
"item": "vampirism:mother_core"
}
},
"pattern": [
"XYX",
"YZY",
"OOO"
],
"result": {
"item": "vampirism:fog_diffuser"
},
"show_notification": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package de.teamlapen.vampirism.blockentity;

import de.teamlapen.vampirism.core.ModTags;
import de.teamlapen.vampirism.core.ModTiles;
import de.teamlapen.vampirism.world.VampirismWorld;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;


public class FogDiffuserBlockEntity extends BlockEntity {

@NotNull
private State state = State.IDLE;
private boolean activated = false;
private float bootProgress = 0;

public FogDiffuserBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(ModTiles.FOG_DIFFUSER.get(), pPos, pBlockState);
}

@Override
protected void saveAdditional(@NotNull CompoundTag pTag) {
super.saveAdditional(pTag);
pTag.putString("state", this.state.name());
pTag.putFloat("bootProgress", this.bootProgress);
pTag.putBoolean("activated", this.activated);
}

@Override
public void load(@NotNull CompoundTag pTag) {
super.load(pTag);
this.state = State.valueOf(pTag.getString("state"));
this.bootProgress = pTag.getFloat("bootProgress");
this.activated = pTag.getBoolean("activated");
}

protected int getRange() {
return (int) (2.5 * 16);
}

public @NotNull State getState() {
return state;
}

public float getBootProgress() {
return bootProgress;
}

protected AABB getArea() {
return getArea(this.getRange());
}

protected AABB getArea(int range) {
return new AABB(this.worldPosition.offset(-range, -range, -range), this.worldPosition.offset(range, range, range));
}

public static void tick(Level level, BlockPos pos, BlockState state, FogDiffuserBlockEntity blockEntity) {
switch (blockEntity.state) {
case IDLE -> {
if (blockEntity.activated) {
blockEntity.state = State.BOOTING;
blockEntity.bootProgress = 0;
}
}
case BOOTING -> {
if (level.getGameTime() % 128 == 0) {
blockEntity.bootProgress += 0.1;
if (blockEntity.bootProgress >= 1) {
blockEntity.state = State.ACTIVE;
}
blockEntity.updateFogArea(level);
}
}
case ACTIVE -> {
}
}
}

public void updateFogArea(Level level) {
VampirismWorld.getOpt(level).ifPresent(w -> w.updateTemporaryArtificialFog(this.worldPosition, switch (this.state) {
case BOOTING -> getArea((int) (this.getRange() * this.bootProgress));
case ACTIVE -> getArea();
default -> null;
}));
}

public void interact(ItemStack itemInHand) {
if (!this.activated && itemInHand.is(ModTags.Items.PURE_BLOOD)) {
this.activated = true;
itemInHand.shrink(1);
}
}

public enum State {
IDLE,
BOOTING,
ACTIVE
}
}
90 changes: 90 additions & 0 deletions src/main/java/de/teamlapen/vampirism/blocks/FogDiffuserBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package de.teamlapen.vampirism.blocks;

import de.teamlapen.vampirism.VampirismMod;
import de.teamlapen.vampirism.blockentity.FogDiffuserBlockEntity;
import de.teamlapen.vampirism.core.ModTiles;
import de.teamlapen.vampirism.world.VampirismWorld;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class FogDiffuserBlock extends VampirismBlockContainer {

private static final VoxelShape shape = makeShape();

private static @NotNull VoxelShape makeShape() {
VoxelShape a = Block.box(1, 0, 1, 15, 2, 15);
VoxelShape b = Block.box(3, 2, 3, 13, 12, 13);
return Shapes.or(a, b);
}

public FogDiffuserBlock(@NotNull Properties properties) {
super(properties);
}

@Override
public @NotNull InteractionResult use(@NotNull BlockState pState, @NotNull Level pLevel, @NotNull BlockPos pPos, @NotNull Player pPlayer, @NotNull InteractionHand pHand, @NotNull BlockHitResult pHit) {
ItemStack itemInHand = pPlayer.getItemInHand(pHand);
getBlockEntity(pLevel, pPos).ifPresent(blockEntity -> {
blockEntity.interact(itemInHand);
VampirismMod.proxy.displayFogDiffuserScreen(blockEntity, getName());
});
return InteractionResult.sidedSuccess(pLevel.isClientSide);
}

@NotNull
protected Optional<FogDiffuserBlockEntity> getBlockEntity(@NotNull Level level, BlockPos pos) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof FogDiffuserBlockEntity) {
return Optional.of((FogDiffuserBlockEntity) blockEntity);
}
return Optional.empty();
}

@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) {
return new FogDiffuserBlockEntity(pPos, pState);
}

@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) {
return RenderShape.MODEL;
}

@NotNull
@Override
public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, @NotNull CollisionContext context) {
return shape;
}

@Override
public void onRemove(@NotNull BlockState state, @NotNull Level worldIn, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) {
super.onRemove(state, worldIn, pos, newState, isMoving);
VampirismWorld.getOpt(worldIn).ifPresent(vampirismWorld -> vampirismWorld.updateTemporaryArtificialFog(pos, null));
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level pLevel, @NotNull BlockState pState, @NotNull BlockEntityType<T> pBlockEntityType) {
return createTickerHelper(pBlockEntityType, ModTiles.FOG_DIFFUSER.get(), FogDiffuserBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GarlicDiffuserBlock extends VampirismBlockContainer {
private final Type type;

public GarlicDiffuserBlock(Type type) {
super(Properties.of().mapColor(MapColor.STONE).strength(3f).sound(SoundType.STONE).noOcclusion());
super(Properties.of().mapColor(MapColor.STONE).strength(40.0F, 1200.0F).sound(SoundType.STONE).noOcclusion());
this.type = type;
this.registerDefaultState(this.getStateDefinition().any().setValue(FACING, Direction.NORTH));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static void registerBlockEntityRenderers(EntityRenderersEvent.@NotNull RegisterR
event.registerBlockEntityRenderer(ModTiles.GARLIC_DIFFUSER.get(), GarlicDiffuserBESR::new);
event.registerBlockEntityRenderer(ModTiles.BAT_CAGE.get(), BatCageBESR::new);
event.registerBlockEntityRenderer(ModTiles.MOTHER_TROPHY.get(), MotherTrophyBESR::new);
event.registerBlockEntityRenderer(ModTiles.FOG_DIFFUSER.get(), FogDiffuserBESR::new);
}

private static void registerRenderType() {
Expand Down
Loading

0 comments on commit c119ca0

Please sign in to comment.