Skip to content

Commit

Permalink
。。。
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Oct 17, 2024
1 parent a6d425b commit 29867aa
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,13 @@ public boolean keyPressed(int key, int b, int c) {
public void containerTick() {
super.containerTick();
for(int i=0;i<5;i++){
selects.get(i).setMessage(Component.literal(slots.get(7 + i).getItem().getDisplayName().getString()));
selects.get(i).visible = slots.get(7 + i).hasItem();
}
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 7), 44, 29, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 8), 44, 56, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 9), 44, 83, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 10), 44, 110, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 11), 44, 137, -1, false);
guiGraphics.drawString(this.font, Status.execute(world, pos), 233, 26, -1, false);
guiGraphics.drawString(this.font, Lefttime.execute(world, pos), 238, 65, -1, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,13 @@ public boolean keyPressed(int key, int b, int c) {
public void containerTick() {
super.containerTick();
for(int i=0;i<5;i++){
selects.get(i).setMessage(Component.literal(slots.get(7 + i).getItem().getDisplayName().getString()));
selects.get(i).visible = slots.get(7 + i).hasItem();
}
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 7), 44, 29, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 8), 44, 56, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 9), 44, 83, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 10), 44, 110, -1, false);
guiGraphics.drawString(this.font, TargetsText.get(world, pos, 11), 44, 137, -1, false);
guiGraphics.drawString(this.font, Status.execute(world, pos), 233, 26, -1, false);
guiGraphics.drawString(this.font, Lefttime.execute(world, pos), 238, 65, -1, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand All @@ -34,7 +35,9 @@
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.CookingRangeEntity;
import org.hiedacamellia.mystiasizakaya.content.inventory.CookingRangeUiMenu;
import org.hiedacamellia.mystiasizakaya.core.cooking.Main;
import org.hiedacamellia.mystiasizakaya.core.debug.Debug;
import org.hiedacamellia.mystiasizakaya.util.SetSlotItem;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -81,8 +84,9 @@ public void onPlace(BlockState blockstate, Level world, BlockPos pos, BlockState
@Override
public void tick(BlockState blockstate, ServerLevel world, BlockPos pos, RandomSource random) {
super.tick(blockstate, world, pos, random);
//blockstate.tick(world, pos, random);
Main.execute(world, pos, blockstate);
if(world.getBlockEntity(pos)instanceof CookingRangeEntity cookingRangeEntity){
cookingRangeEntity.tick(world);
}
world.scheduleTick(pos, this, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -33,6 +35,7 @@
import org.hiedacamellia.mystiasizakaya.core.cooking.Main;
import org.hiedacamellia.mystiasizakaya.core.debug.Debug;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class Kitchenwares extends RotatedPillarBlock implements EntityBlock {
public Kitchenwares() {
Expand All @@ -42,7 +45,6 @@ public Kitchenwares() {

@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
Debug.getLogger().debug("Create Block:{}", state.getBlock().getDescriptionId());

return switch (state.getBlock().getDescriptionId()) {
case "block.mystias_izakaya.cutting_board" -> new CuttingBoard(pos, state);
Expand Down Expand Up @@ -96,7 +98,10 @@ public void onRemove(BlockState state, Level world, BlockPos pos, BlockState new
@Override
public void tick(BlockState blockstate, ServerLevel world, BlockPos pos, RandomSource random) {
super.tick(blockstate, world, pos, random);
Main.execute(world, pos,blockstate);
//Debug.getLogger().error("Tick Block:{}", blockstate.getBlock().getDescriptionId());
if (world.getBlockEntity(pos) instanceof KitchenwaresEntity kitchenwaresEntity) {
kitchenwaresEntity.tick(world);
}
world.scheduleTick(pos, this, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.WorldlyContainer;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.hiedacamellia.mystiasizakaya.content.inventory.CookingRangeUiMenu;
import org.hiedacamellia.mystiasizakaya.core.cooking.Main;
import org.hiedacamellia.mystiasizakaya.registries.MIBlockEntitiy;
import org.jetbrains.annotations.Nullable;

Expand All @@ -36,9 +38,26 @@ public CookingRangeEntity(BlockPos position, BlockState state) {
totalTime = 0;
}

public void tick(ServerLevel world){
Main.execute(world, this.worldPosition);
if(timeLeft>1)
timeLeft--;
if(timeLeft==1){
timeLeft=0;
stacks.set(6,stacks.get(12));
stacks.set(12,ItemStack.EMPTY);
}
}



@Override
public void load(CompoundTag compound) {
super.load(compound);
timeLeft = compound.getInt("timeLeft");
page = compound.getInt("page");
targets = compound.getInt("targets");
totalTime = compound.getInt("totalTime");
if (!this.tryLoadLootTable(compound))
this.stacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
ContainerHelper.loadAllItems(compound, this.stacks);
Expand All @@ -47,6 +66,10 @@ public void load(CompoundTag compound) {
@Override
public void saveAdditional(CompoundTag compound) {
super.saveAdditional(compound);
compound.putInt("timeLeft", timeLeft);
compound.putInt("page", page);
compound.putInt("targets", targets);
compound.putInt("totalTime", totalTime);
if (!this.trySaveLootTable(compound)) {
ContainerHelper.saveAllItems(compound, this.stacks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.WorldlyContainer;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -17,6 +18,7 @@
import net.minecraft.world.level.block.state.BlockState;

import org.hiedacamellia.mystiasizakaya.content.inventory.KitchenwaresUiMenu;
import org.hiedacamellia.mystiasizakaya.core.cooking.Main;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -38,9 +40,24 @@ public KitchenwaresEntity(BlockEntityType<?> type, BlockPos position, BlockState
totalTime = 0;
}

public void tick(ServerLevel world){
Main.execute(world, this.worldPosition);
if(timeLeft>1)
timeLeft--;
if(timeLeft==1){
timeLeft=0;
stacks.set(6,stacks.get(12));
stacks.set(12,ItemStack.EMPTY);
}
}

@Override
public void load(CompoundTag compound) {
super.load(compound);
timeLeft = compound.getInt("timeLeft");
page = compound.getInt("page");
targets = compound.getInt("targets");
totalTime = compound.getInt("totalTime");
if (!this.tryLoadLootTable(compound))
this.stacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
ContainerHelper.loadAllItems(compound, this.stacks);
Expand All @@ -49,6 +66,10 @@ public void load(CompoundTag compound) {
@Override
public void saveAdditional(CompoundTag compound) {
super.saveAdditional(compound);
compound.putInt("timeLeft", timeLeft);
compound.putInt("page", page);
compound.putInt("targets", targets);
compound.putInt("totalTime", totalTime);
if (!this.trySaveLootTable(compound)) {
ContainerHelper.saveAllItems(compound, this.stacks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public KitchenwaresUiMenu(int id, Inventory inv, BlockPos pos ) {
this(id, inv, pos, new SimpleContainer(12));
}
public KitchenwaresUiMenu(int id, Inventory inv, BlockPos pos, Container inventory ) {
super(MIMenu.COOKING_RANGE_UI, id);
super(MIMenu.KITCHENWARES_UI, id);
this.entity = inv.player;
this.world = inv.player.level();
access = ContainerLevelAccess.create(world, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class Confirm {
public static void execute(LevelAccessor world, BlockPos pos) {
double time = 0;

Debug.getLogger().error("conform");

BlockEntity blockEntity = world.getBlockEntity(pos);
Debug.getLogger().error(blockEntity.toString());
if(blockEntity instanceof CookingRangeEntity cookingRangeEntity)
time = cookingRangeEntity.timeLeft;
if(blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
Expand All @@ -26,8 +29,9 @@ public static void execute(LevelAccessor world, BlockPos pos) {
ItemStack target;

if(ItemStack.EMPTY == GetItemStack.getItemStack(world, pos, 1)){
return;
//return;
}
Debug.getLogger().error(GetItemStack.getItemStack(world, pos, 12).getDescriptionId());

if ((ItemStack.EMPTY.getItem() == GetItemStack.getItemStack(world, pos, 6).getItem())
&& !(ItemStack.EMPTY.getItem() == GetItemStack.getItemStack(world, pos, 12).getItem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.CookingRangeEntity;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.KitchenwaresEntity;
import org.hiedacamellia.mystiasizakaya.core.cooking.get.GetTargets;
import org.hiedacamellia.mystiasizakaya.core.debug.Debug;
import org.hiedacamellia.mystiasizakaya.registries.MIItem;
import org.hiedacamellia.mystiasizakaya.util.GetItemStack;
import org.hiedacamellia.mystiasizakaya.util.SetSlotItem;
Expand All @@ -22,79 +24,31 @@
import java.util.Objects;

public class Main {
public static void execute(LevelAccessor world, BlockPos pos, BlockState blockState) {
double time=0;
public static void execute(LevelAccessor world, BlockPos pos) {
ItemStack util;
ItemStack target;
BlockEntity be = world.getBlockEntity(pos);
if(be instanceof CookingRangeEntity cookingRangeEntity)
time = cookingRangeEntity.timeLeft;
if(be instanceof KitchenwaresEntity kitchenwaresEntity)
time = kitchenwaresEntity.timeLeft;
//Debug.getLogger().error("execute");
{
util = GetItemStack.getItemStack(world, pos, 0);

//time = GetValue.getDouble(world, pos, "timeleft");
if (time > 1) {
if (!world.isClientSide()) {
BlockEntity _blockEntity = world.getBlockEntity(pos);
BlockState _bs = world.getBlockState(pos);
if (_blockEntity != null) {
if (be instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.timeLeft = (int) (time - 1);
if (be instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.timeLeft = (int) (time - 1);
//Debug.getLogger().error(util.getDescriptionId());
if (ItemStack.isSameItem(util,ItemStack.EMPTY)||util.isEmpty()) {
if(ItemStack.isSameItem(util,MIItem.CUTTING_BOARD.getDefaultInstance())){
util = MIItem.CUTTING_BOARD.getDefaultInstance();
}
//_blockEntity.getPersistentData().putDouble("timeleft", (time - 1));
if (world instanceof Level _level)
_level.sendBlockUpdated(pos, _bs, _bs, 3);
}
} else if (time == 1) {
if (!world.isClientSide()) {
BlockEntity _blockEntity = world.getBlockEntity(pos);
BlockState _bs = world.getBlockState(pos);
if (_blockEntity != null) {
if (be instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.timeLeft = 0;
if (be instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.timeLeft = 0;
if(ItemStack.isSameItem(util,MIItem.BOILING_POT.getDefaultInstance())){
util = MIItem.BOILING_POT.getDefaultInstance();
}
if (world instanceof Level _level)
_level.sendBlockUpdated(pos, _bs, _bs, 3);
}
target = GetItemStack.getItemStack(world, pos, 12);
SetSlotItem.setSlotItem(world, pos, target, 6, 1);

// MITags miTags = GetItemStack.getItemStack(world,pos, 12).get(MIDatacomponet.MI_TAGS.get());
// target.set(MIDatacomponet.MI_TAGS.get(), miTags);

SetSlotItem.setEmptySlot(world, pos, 12);
} else {


util = GetItemStack.getItemStack(world, pos, 0);


if (util == ItemStack.EMPTY) {
Block utilblcok = world.getBlockState(pos).getBlock();
//Debug.send(utilblcok.getDescriptionId());
switch (utilblcok.getDescriptionId()) {
case "block.mystias_izakaya.cutting_board":
util = MIItem.CUTTING_BOARD.getDefaultInstance();
break;
case "block.mystias_izakaya.boiling_pot":
util = MIItem.BOILING_POT.getDefaultInstance();
break;
case "block.mystias_izakaya.frying_pan":
util = MIItem.FRYING_PAN.getDefaultInstance();
break;
case "block.mystias_izakaya.steamer":
util = MIItem.STEAMER.getDefaultInstance();
break;
case "block.mystias_izakaya.grill":
util = new ItemStack(MIItem.GRILL);
break;
if(ItemStack.isSameItem(util,MIItem.FRYING_PAN.getDefaultInstance())){
util = MIItem.FRYING_PAN.getDefaultInstance();
}
if(ItemStack.isSameItem(util,MIItem.STEAMER.getDefaultInstance())){
util = MIItem.STEAMER.getDefaultInstance();
}
if(ItemStack.isSameItem(util,new ItemStack(MIItem.GRILL))){
util = new ItemStack(MIItem.GRILL);
}
}
//Debug.send(util.getDescriptionId());
//Debug.getLogger().error(util.getDescriptionId());

List<String> raws = new ArrayList<>();
List<ItemStack> ingredients = new ArrayList<>();
Expand All @@ -109,7 +63,7 @@ public static void execute(LevelAccessor world, BlockPos pos, BlockState blockSt
}

List<String> targets = GetTargets.getTargets(raws, util);

// Debug.getLogger().error(targets.toString());
if (!world.isClientSide()) {
BlockPos _bp = pos;
BlockEntity _blockEntity = world.getBlockEntity(_bp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public static String execute(LevelAccessor world, BlockPos pos) {
return Component.translatable("status.mystias_izakaya.outputblocked").getString();
return Component.translatable("status.mystias_izakaya.free").getString();
}
public static String execute(int time,boolean blocked) {
if (time != 0) {
return Component.translatable("status.mystias_izakaya.working").getString();
}
if (blocked)
return Component.translatable("status.mystias_izakaya.outputblocked").getString();
return Component.translatable("status.mystias_izakaya.free").getString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static CookingRangeUiButton decode(FriendlyByteBuf buffer) {

public static void handleButtonAction(Player entity, int buttonID, BlockPos pos) {
Level world = entity.level();
Debug.getLogger().debug("Button{}",buttonID);
Debug.getLogger().error("Button{}",buttonID);

if (buttonID == 0) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class MIBlock {

public static final Block COOKING_RANGE = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(MystiasIzakaya.MODID, "cooking_range"), new CookingRange());
public static final CookingRange COOKING_RANGE = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(MystiasIzakaya.MODID, "cooking_range"), new CookingRange());
public static final Block DONATION = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(MystiasIzakaya.MODID, "donation"), new Donation());

public static final Kitchenwares CUTTING_BOARD = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(MystiasIzakaya.MODID, "cutting_board"), new Kitchenwares());
Expand Down
Loading

0 comments on commit 29867aa

Please sign in to comment.