Skip to content

Commit

Permalink
修了一点东西
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Sep 28, 2024
1 parent f0c32ae commit e718452
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import org.hiedacamellia.mystiasizakaya.content.common.inventory.CookingRangeUiMenu;
import org.hiedacamellia.mystiasizakaya.content.inventory.CookingRangeUiMenu;
import org.hiedacamellia.mystiasizakaya.registries.MIBlockEntitiy;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.util.stream.IntStream;

public class CookingRangeEntity extends RandomizableContainerBlockEntity implements WorldlyContainer {
private NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(13, ItemStack.EMPTY);
private final LazyOptional<? extends IItemHandler>[] handlers = SidedInvWrapper.create(this, Direction.values());
public NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(13, ItemStack.EMPTY);
public int timeLeft ;
public int page ;
public int targets ;
public int totalTime;

public CookingRangeEntity(BlockPos position, BlockState state) {
super(MIBlockEntitiy.COOKING_RANGE.get(), position, state);
super(MIBlockEntitiy.COOKING_RANGE, position, state);
timeLeft = 0;
page = 0;
targets = 0;
totalTime = 0;
}

@Override
Expand Down Expand Up @@ -134,17 +136,8 @@ public boolean canTakeItemThroughFace(int index, ItemStack stack, Direction dire
return index == 6;
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
if (!this.remove && facing != null && capability == ForgeCapabilities.ITEM_HANDLER)
return handlers[facing.ordinal()].cast();
return super.getCapability(capability, facing);
}

@Override
public void setRemoved() {
super.setRemoved();
for (LazyOptional<? extends IItemHandler> handler : handlers)
handler.invalidate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import org.hiedacamellia.mystiasizakaya.content.common.inventory.KitchenwaresUiMenu;

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


import javax.annotation.Nullable;
import java.util.stream.IntStream;

public abstract class KitchenwaresEntity extends RandomizableContainerBlockEntity implements WorldlyContainer {
private NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(13, ItemStack.EMPTY);
private final LazyOptional<? extends IItemHandler>[] handlers = SidedInvWrapper.create(this, Direction.values());
public NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(13, ItemStack.EMPTY);
public int timeLeft ;
public int page ;
public int targets ;
public int totalTime;

public KitchenwaresEntity(BlockEntityType<?> type, BlockPos position, BlockState state) {
super(type, position, state);
timeLeft = 0;
page = 0;
targets = 0;
totalTime = 0;
}

@Override
Expand Down Expand Up @@ -124,17 +128,9 @@ public boolean canTakeItemThroughFace(int index, @NotNull ItemStack stack, @NotN
}


@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
if (!this.remove && facing != null && capability == ForgeCapabilities.ITEM_HANDLER)
return handlers[facing.ordinal()].cast();
return super.getCapability(capability, facing);
}

@Override
public void setRemoved() {
super.setRemoved();
for (LazyOptional<? extends IItemHandler> handler : handlers)
handler.invalidate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
import net.minecraft.world.level.LevelAccessor;
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.debug.Debug;
import org.hiedacamellia.mystiasizakaya.registries.MIBlock;
import org.hiedacamellia.mystiasizakaya.util.GetItemStack;
import org.hiedacamellia.mystiasizakaya.util.GetValue;
import org.hiedacamellia.mystiasizakaya.util.SetSlotItem;

public class Confirm {
public static void execute(LevelAccessor world, BlockPos pos) {
double time;
time = GetValue.getDouble(world, pos, "timeleft");
double time = 0;

BlockEntity blockEntity = world.getBlockEntity(pos);
if(blockEntity instanceof CookingRangeEntity cookingRangeEntity)
time = cookingRangeEntity.timeLeft;
if(blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
time = kitchenwaresEntity.timeLeft;

ItemStack target;

if(ItemStack.EMPTY == GetItemStack.getItemStack(world, pos, 1)){
Expand Down Expand Up @@ -44,14 +51,23 @@ public static void execute(LevelAccessor world, BlockPos pos) {
int cooktime = target.getOrCreateTag().getInt("cooktime");
Debug.debug("Getted cooktime", cooktime);

if(_bs.getBlock()== MIBlock.COOKING_RANGE.get()||_bsb.getBlock()== MIBlock.COOKING_RANGE.get()){
if(_bs.getBlock()== MIBlock.COOKING_RANGE||_bsb.getBlock()== MIBlock.COOKING_RANGE){
cooktime = (int) (cooktime * 0.6);
}

if (_blockEntity != null) {
_blockEntity.getPersistentData().putDouble("totaltime", cooktime);
_blockEntity.getPersistentData().putDouble("timeleft", cooktime);
Debug.debug("Getted cooktime", _blockEntity.getPersistentData().getDouble("totaltime"));
if(_blockEntity instanceof CookingRangeEntity cookingRangeEntity) {
cookingRangeEntity.totalTime = cooktime;
cookingRangeEntity.timeLeft = cooktime;
}
if(_blockEntity instanceof KitchenwaresEntity kitchenwaresEntity) {
kitchenwaresEntity.totalTime = cooktime;
kitchenwaresEntity.timeLeft = cooktime;
}
//
// _blockEntity.getPersistentData().putDouble("totaltime", cooktime);
// _blockEntity.getPersistentData().putDouble("timeleft", cooktime);
// Debug.debug("Getted cooktime", _blockEntity.getPersistentData().getDouble("totaltime"));
}


Expand All @@ -67,7 +83,12 @@ public static void execute(LevelAccessor world, BlockPos pos) {
BlockEntity _blockEntity = world.getBlockEntity(pos);
BlockState _bs = world.getBlockState(pos);
if (_blockEntity != null) {
_blockEntity.getPersistentData().putInt("page", 0);
if(_blockEntity instanceof CookingRangeEntity cookingRangeEntity) {
cookingRangeEntity.page = 0;
}
if(_blockEntity instanceof KitchenwaresEntity kitchenwaresEntity) {
kitchenwaresEntity.page = 0;
}
}
if (world instanceof Level _level) _level.sendBlockUpdated(pos, _bs, _bs, 3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries;
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.integration.youkaihomecoming.IngredientsCompact;
import org.hiedacamellia.mystiasizakaya.registries.MIItem;
import org.hiedacamellia.mystiasizakaya.util.GetItemStack;
import org.hiedacamellia.mystiasizakaya.util.GetValue;
import org.hiedacamellia.mystiasizakaya.util.SetSlotItem;

import java.util.ArrayList;
Expand All @@ -24,25 +24,40 @@

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

//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)
_blockEntity.getPersistentData().putDouble("timeleft", (time - 1));
if (_blockEntity != null) {
if (be instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.timeLeft = (int) (time - 1);
if (be instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.timeLeft = (int) (time - 1);
}
//_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)
_blockEntity.getPersistentData().putDouble("timeleft", 0);
if (_blockEntity != null) {
if (be instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.timeLeft = 0;
if (be instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.timeLeft = 0;
}
if (world instanceof Level _level)
_level.sendBlockUpdated(pos, _bs, _bs, 3);
}
Expand Down Expand Up @@ -100,19 +115,19 @@ public static void execute(LevelAccessor world, BlockPos pos, BlockState blockSt
//Debug.send(utilblcok.getDescriptionId());
switch (utilblcok.getDescriptionId()) {
case "block.mystias_izakaya.cutting_board":
util = MIItem.CUTTING_BOARD.get().getDefaultInstance();
util = MIItem.CUTTING_BOARD.getDefaultInstance();
break;
case "block.mystias_izakaya.boiling_pot":
util = MIItem.BOILING_POT.get().getDefaultInstance();
util = MIItem.BOILING_POT.getDefaultInstance();
break;
case "block.mystias_izakaya.frying_pan":
util = MIItem.FRYING_PAN.get().getDefaultInstance();
util = MIItem.FRYING_PAN.getDefaultInstance();
break;
case "block.mystias_izakaya.steamer":
util = MIItem.STEAMER.get().getDefaultInstance();
util = MIItem.STEAMER.getDefaultInstance();
break;
case "block.mystias_izakaya.grill":
util = new ItemStack(MIItem.GRILL.get());
util = new ItemStack(MIItem.GRILL);
break;
}
}
Expand All @@ -125,7 +140,7 @@ public static void execute(LevelAccessor world, BlockPos pos, BlockState blockSt
ItemStack raw = GetItemStack.getItemStack(world, pos, i);
raw = IngredientsCompact.execute(raw);
ingredients.add(raw);
raws.add((Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(raw.getItem())).toString()));
raws.add((Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(raw.getItem())).toString()));
} else {
ingredients.add(ItemStack.EMPTY);
}
Expand All @@ -138,16 +153,25 @@ public static void execute(LevelAccessor world, BlockPos pos, BlockState blockSt
BlockEntity _blockEntity = world.getBlockEntity(_bp);
BlockState _bs = world.getBlockState(_bp);
if (_blockEntity != null) {
_blockEntity.getPersistentData().putDouble("targets", targets.size());
if (_blockEntity instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.targets = targets.size();
if (_blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.targets = targets.size();
}
if (world instanceof Level _level)
_level.sendBlockUpdated(_bp, _bs, _bs, 3);
}
int page = GetValue.getInt(world, pos, "page");
int page =0;

BlockEntity _blockEntity = world.getBlockEntity(pos);
if (_blockEntity instanceof CookingRangeEntity cookingRangeEntity)
page = cookingRangeEntity.page;
if (_blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
page = kitchenwaresEntity.page;

for (int i = 0; i < 5; i++) {
if (i < targets.size()) {
ItemStack taget = new ItemStack(Objects.requireNonNull(ForgeRegistries.ITEMS.getValue(new ResourceLocation(((targets.get(i + page))).toLowerCase(Locale.ENGLISH)))));
ItemStack taget = new ItemStack(Objects.requireNonNull(BuiltInRegistries.ITEM.get(new ResourceLocation(((targets.get(i + page))).toLowerCase(Locale.ENGLISH)))));
SetSlotItem.setSlotItem(world, pos, BuildTags.execute(taget, util, ingredients), 7 + i, 1);
} else {
SetSlotItem.setEmptySlot(world, pos, 7 + i);
Expand All @@ -162,7 +186,10 @@ private static void resetpage(LevelAccessor world, BlockPos ps) {
BlockEntity _blockEntity = world.getBlockEntity(ps);
BlockState _bs = world.getBlockState(ps);
if (_blockEntity != null) {
_blockEntity.getPersistentData().putInt("page", 0);
if (_blockEntity instanceof CookingRangeEntity cookingRangeEntity)
cookingRangeEntity.page = 0;
if (_blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
kitchenwaresEntity.page = 0;
}
if (world instanceof Level _level)
_level.sendBlockUpdated(ps, _bs, _bs, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import org.hiedacamellia.mystiasizakaya.util.GetValue;
import org.hiedacamellia.mystiasizakaya.util.cross.Pos;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.CookingRangeEntity;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.KitchenwaresEntity;

public class Lefttime {
public static String execute(LevelAccessor world, BlockPos pos) {
if (GetValue.getDouble(world, pos, "timeleft") != 0) {
return new java.text.DecimalFormat("#.#")
.format((GetValue.getDouble(world, pos, "timeleft")) / 20) + "s";
}
BlockEntity blockEntity = world.getBlockEntity(pos);
if(blockEntity instanceof CookingRangeEntity cookingRangeEntity)
return new java.text.DecimalFormat("#.#").format((cookingRangeEntity.timeLeft) / 20) + "s";
if(blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
return new java.text.DecimalFormat("#.#").format((kitchenwaresEntity.timeLeft) / 20) + "s";
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.CookingRangeEntity;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.KitchenwaresEntity;
import org.hiedacamellia.mystiasizakaya.util.GetItemStack;
import org.hiedacamellia.mystiasizakaya.util.GetValue;
import org.hiedacamellia.mystiasizakaya.util.cross.Pos;

public class Status {
public static String execute(LevelAccessor world, BlockPos pos) {
if (GetValue.getDouble(world, pos, "timeleft") != 0) {
BlockEntity blockEntity = world.getBlockEntity(pos);
int time=0;
if(blockEntity instanceof CookingRangeEntity cookingRangeEntity)
time = cookingRangeEntity.timeLeft;
if(blockEntity instanceof KitchenwaresEntity kitchenwaresEntity)
time = kitchenwaresEntity.timeLeft;
if (time != 0) {
return Component.translatable("status.mystias_izakaya.working").getString();
}
if (!GetItemStack.getItemStack(world, pos, 6).isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.*;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.registries.ForgeRegistries;
import org.hiedacamellia.mystiasizakaya.MystiasIzakaya;
import org.hiedacamellia.mystiasizakaya.content.common.block.entities.TableEntity;
import org.hiedacamellia.mystiasizakaya.content.orders.Addorder;
import org.hiedacamellia.mystiasizakaya.content.orders.Deleteorder;
Expand All @@ -43,7 +29,7 @@
import java.util.*;
import java.util.function.Supplier;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)

public class MIPlayerEvent {

public static double getBalance(Player player) {
Expand Down
Loading

0 comments on commit e718452

Please sign in to comment.