Compare commits

...

3 Commits

3 changed files with 103 additions and 14 deletions

View File

@ -4,16 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="9d600e86-9aa6-49ee-bbc5-e23128c6a4d1" name="Changes" comment="added toaster block hardness and tool requirement">
<change afterPath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/block/ToasterBlockEntity.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/assets/tastytoasters/models/block/toaster_filled.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules/tastytoasters.main.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules/tastytoasters.main.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules/tastytoasters.test.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules/tastytoasters.test.iml" afterDir="false" />
<list default="true" id="9d600e86-9aa6-49ee-bbc5-e23128c6a4d1" name="Changes" comment="commit so I don't loose progress">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/Tastytoasters.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/Tastytoasters.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/block/ToasterBlock.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/block/ToasterBlock.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/assets/tastytoasters/blockstates/toaster.json" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/assets/tastytoasters/blockstates/toaster.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/block/ToasterBlockEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/blackfur/tastytoasters/block/ToasterBlockEntity.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -240,7 +234,28 @@
<option name="project" value="LOCAL" />
<updated>1638615794540</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="so much fucking work!!!">
<created>1638638076796</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1638638076796</updated>
</task>
<task id="LOCAL-00005" summary="I did a thing and nothing broke OMG">
<created>1638722000773</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1638722000773</updated>
</task>
<task id="LOCAL-00006" summary="commit so I don't loose progress">
<created>1638725152334</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1638725152334</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -259,6 +274,9 @@
<MESSAGE value="Upgraded to 1.18" />
<MESSAGE value="uhm what?" />
<MESSAGE value="added toaster block hardness and tool requirement" />
<option name="LAST_COMMIT_MESSAGE" value="added toaster block hardness and tool requirement" />
<MESSAGE value="so much fucking work!!!" />
<MESSAGE value="I did a thing and nothing broke OMG" />
<MESSAGE value="commit so I don't loose progress" />
<option name="LAST_COMMIT_MESSAGE" value="commit so I don't loose progress" />
</component>
</project>

View File

@ -1,20 +1,29 @@
package blackfur.tastytoasters.block;
import blackfur.tastytoasters.Tastytoasters;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.Hand;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import org.jetbrains.annotations.Nullable;
import net.minecraft.world.World;
public class ToasterBlock extends HorizontalFacingBlock implements BlockEntityProvider {
public class ToasterBlock extends BlockWithEntity implements BlockEntityProvider {
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
public static final BooleanProperty TOASTING = BooleanProperty.of("toasting");
@ -24,6 +33,18 @@ public class ToasterBlock extends HorizontalFacingBlock implements BlockEntityPr
this.setDefaultState(this.stateManager.getDefaultState().with(TOASTING, false));
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.isSneaking() && world.getBlockEntity(pos) instanceof ToasterBlockEntity toasterBlockEntity) {
if (player.getStackInHand(hand).getItem() == Tastytoasters.RAW_TOAST_ITEM) {
world.setBlockState(pos, state.with(TOASTING, true));
toasterBlockEntity.handleUse();
}
return ActionResult.success(world.isClient());
}
return super.onUse(state, world, pos, player, hand, hit);
}
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
}
@ -72,9 +93,27 @@ public class ToasterBlock extends HorizontalFacingBlock implements BlockEntityPr
return null;
}
@Nullable
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return null;
return new ToasterBlockEntity(pos, state);
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return checkType(type, Tastytoasters.TOASTER_BLOCK_ENTITY, (world1, pos, state1, be) -> ToasterBlockEntity.tick(world1, pos, state1, be));
}
}

View File

@ -3,10 +3,42 @@ package blackfur.tastytoasters.block;
import blackfur.tastytoasters.Tastytoasters;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ToasterBlockEntity extends BlockEntity {
private int cookTicks;
public ToasterBlockEntity(BlockPos pos, BlockState state) {
super(Tastytoasters.TOASTER_BLOCK_ENTITY, pos, state);
}
public static void tick(World world, BlockPos pos, BlockState state, ToasterBlockEntity be) {
if (state.get(ToasterBlock.TOASTING)) {
if (be.cookTicks <= 0) {
world.setBlockState(pos, state.with(ToasterBlock.TOASTING, false));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY() + 0.5, pos.getZ(), Tastytoasters.TOAST_ITEM.getDefaultStack()));
}
be.cookTicks--;
}
}
public void handleUse() {
cookTicks = 90*20;
}
@Override
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
tag.putInt("cookTime", cookTicks);
}
@Override
public void readNbt(NbtCompound tag) {
super.readNbt(tag);
cookTicks = tag.getInt("cookTime");
}
}