Skip to content

Commit

Permalink
top support
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Sep 20, 2024
1 parent 77783c9 commit b57e9d2
Show file tree
Hide file tree
Showing 32 changed files with 667 additions and 84 deletions.
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ repositories {
mavenLocal()
mavenCentral()
// maven { url "https://maven.shedaniel.me" }
maven {
url "https://www.khjxiaogu.com/maven"
}
//khjxiaogu public maven
maven { url "https://www.khjxiaogu.com/maven" }
exclusiveContent {
forRepository {
maven {
Expand All @@ -135,10 +134,9 @@ repositories {

//for patchouli books and jei
maven { url 'https://maven.blamejared.com' }
maven {
url "https://maven.architectury.dev/"
}

maven { url "https://maven.architectury.dev/" }
//for top
maven { url "https://maven.k-4u.nl" }
maven {
url "https://maven.saps.dev/minecraft"
content {
Expand All @@ -153,6 +151,7 @@ configurations {
dependencies {
//minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
implementation "net.neoforged:neoforge:${neo_version}"
implementation "mcjty.theoneprobe:theoneprobe:${top_version}"
//implementation fg.deobf("curse.maven:diet-443570:3758891")

//compileOnly fg.deobf("mezz.jei:jei-1.19.2-common-api:11.2.0.247")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.07.07
mc_version=1.21
minecraft_version=1.21.1
version_neogradle=7.0.161
top_version=1.21_neo-12.0.3-5

#mod info
mod_id=caupona
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/teammoeg/caupona/CPMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@

package com.teammoeg.caupona;

import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.teammoeg.caupona.client.CPParticles;
import com.teammoeg.caupona.compat.top.TOPRegister;
import com.teammoeg.caupona.network.PacketHandler;
import com.teammoeg.caupona.util.FuelType;
import com.teammoeg.caupona.util.Utils;

import mcjty.theoneprobe.api.ITheOneProbe;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.InterModComms;
import net.neoforged.fml.InterModComms.IMCMessage;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent;
import net.neoforged.neoforge.common.NeoForgeMod;
Expand Down Expand Up @@ -84,6 +91,7 @@ public CPMain(IEventBus mod) {

@SuppressWarnings("unused")
public void enqueueIMC(InterModEnqueueEvent event) {
InterModComms.sendTo("theoneprobe", "getTheOneProbe", ()->(Function<ITheOneProbe, ?>)TOPRegister::register);
// InterModComms.sendTo("treechop", "getTreeChopAPI", () -> (Consumer)TreechopCompat::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.teammoeg.caupona.network.CPBaseBlockEntity;
import com.teammoeg.caupona.util.IInfinitable;
import com.teammoeg.caupona.util.LazyTickWorker;
import com.teammoeg.caupona.util.RecipeHandler;
import com.teammoeg.caupona.util.SyncedFluidHandler;
import com.teammoeg.caupona.util.Utils;

Expand Down Expand Up @@ -77,7 +78,8 @@ public boolean isItemValid(int slot, ItemStack stack) {
@Override
protected void onContentsChanged(int slot) {
if(slot<5&&slot!=3)
recipeTested=false;
recipeHandler.onContainerChanged();
setChanged();
super.onContentsChanged(slot);
}

Expand All @@ -87,8 +89,9 @@ protected void onContentsChanged(int slot) {
@Override
protected void onContentsChanged() {
super.onContentsChanged();
recipeTested=false;
process = -1;
recipeHandler.onContainerChanged();
recipeHandler.resetProgress();
syncData();
}

};
Expand All @@ -114,12 +117,15 @@ private FluidStack tryAddSpice(FluidStack fs) {
return fs;

}
public int process;
public int processMax;
public LazyTickWorker contain;
boolean isInfinite = false;
ItemStack inner = ItemStack.EMPTY;
boolean recipeTested=false;
public final RecipeHandler<DoliumRecipe> recipeHandler=new RecipeHandler<>(()->{
RecipeHolder<DoliumRecipe> recipe = DoliumRecipe.testDolium(tank.getFluid(), inv);
if(recipe!=null) {
inner=recipe.value().handleDolium(tank.getFluid(), inv);
}
});
ResourceLocation lastRecipe;
public CounterDoliumBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
super(CPBlockEntityTypes.DOLIUM.get(), pWorldPosition, pBlockState);
Expand All @@ -142,8 +148,7 @@ public void handleMessage(short type, int data) {

@Override
public void readCustomNBT(CompoundTag nbt, boolean isClient,HolderLookup.Provider ra) {
process=nbt.getInt("process");
processMax=nbt.getInt("processMax");
recipeHandler.readCustomNBT(nbt, isClient);
tank.readFromNBT(ra,nbt.getCompound("tank"));
isInfinite = nbt.getBoolean("inf");
if (!isClient) {
Expand All @@ -159,8 +164,7 @@ public void readCustomNBT(CompoundTag nbt, boolean isClient,HolderLookup.Provide

@Override
public void writeCustomNBT(CompoundTag nbt, boolean isClient,HolderLookup.Provider ra) {
nbt.putInt("process",process);
nbt.putInt("processMax",processMax);
recipeHandler.writeCustomNBT(nbt, isClient);
nbt.put("tank", tank.writeToNBT(ra,new CompoundTag()));
nbt.putBoolean("inf", isInfinite);
if (!isClient) {
Expand All @@ -183,32 +187,12 @@ public void tick() {
this.setChanged();
return;
}
if(!recipeTested) {
if(recipeHandler.shouldTestRecipe()){
RecipeHolder<DoliumRecipe> recipe=DoliumRecipe.testDolium(tank.getFluid(), inv);
if (recipe!= null) {
if(!recipe.id().equals(lastRecipe)) {
process=processMax=recipe.value().time;
lastRecipe=recipe.id();
}
}else {
process=processMax=0;
lastRecipe=null;
}
recipeHandler.setRecipe(recipe);

recipeTested=true;
}
if (process > 0) {
process--;
if(process<=0) {
RecipeHolder<DoliumRecipe> recipe = DoliumRecipe.testDolium(tank.getFluid(), inv);
if(recipe!=null) {
inner=recipe.value().handleDolium(tank.getFluid(), inv);
}else {
process=processMax=0;
}
lastRecipe=null;
recipeTested=false;
}
if (recipeHandler.tickProcess(1)) {
updateNeeded=true;
}
}
Expand Down Expand Up @@ -381,4 +365,9 @@ public Object getCapability(BlockCapability<?, Direction> cap, Direction side) {
return null;
}

@Override
public boolean isInfinite() {
return isInfinite;
}

}
29 changes: 15 additions & 14 deletions src/main/java/com/teammoeg/caupona/blocks/foods/BowlBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -72,7 +73,7 @@ public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos,
@Override
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock() && worldIn.getBlockEntity(pos) instanceof BowlBlockEntity bowl) {
super.popResource(worldIn, pos, bowl.internal);
super.popResource(worldIn, pos, bowl.getInternal());
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
Expand All @@ -83,19 +84,19 @@ public InteractionResult useWithoutItem(BlockState state, Level worldIn, BlockPo
InteractionResult p = super.useWithoutItem(state, worldIn, pos, player, hit);
if (p.consumesAction())
return p;
if (worldIn.getBlockEntity(pos) instanceof BowlBlockEntity bowl&&bowl.internal != null && bowl.internal.getItem() instanceof StewItem
&& bowl.internal.getFoodProperties(player)!=null) {
FoodProperties fp = bowl.internal.getFoodProperties(player);
if (worldIn.getBlockEntity(pos) instanceof BowlBlockEntity bowl&&bowl.getInternal() != null && bowl.getInternal().getItem() instanceof StewItem
&& bowl.getInternal().getFoodProperties(player)!=null) {
FoodProperties fp = bowl.getInternal().getFoodProperties(player);
if (bowl.isInfinite) {
if (player.canEat(fp.canAlwaysEat())) {
player.eat(worldIn, bowl.internal.copy());
player.eat(worldIn, bowl.getInternal().copy());
bowl.syncData();
}
} else {
if (player.canEat(fp.canAlwaysEat())) {
ItemStack iout = player.eat(worldIn, bowl.internal);
bowl.internal = iout;
if(!bowl.internal.isEmpty()) {
ItemStack iout = player.eat(worldIn, bowl.getInternal());
bowl.setInternal(iout);
if(!bowl.getInternal().isEmpty()) {
bowl.syncData();
}else
worldIn.removeBlock(pos, false);
Expand All @@ -111,16 +112,16 @@ public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEn
super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack);
if (pLevel.getBlockEntity(pPos) instanceof BowlBlockEntity bowl) {
bowl.setComponents(DataComponentMap.EMPTY);
bowl.internal = pStack.copyWithCount(1);
bowl.setInternal(pStack.copyWithCount(1));
}
}

public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos,
Player player) {
if (level.getBlockEntity(pos) instanceof BowlBlockEntity bowl) {
if (bowl.internal == null)
if (bowl.getInternal() == null)
return ItemStack.EMPTY;
return bowl.internal.copy();
return bowl.getInternal().copy();
}
return this.getCloneItemStack(state, target, level, pos, player);
}
Expand All @@ -132,7 +133,7 @@ public boolean hasAnalogOutputSignal(BlockState pState) {

@Override
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
if (pLevel.getBlockEntity(pPos) instanceof BowlBlockEntity bowl&&bowl.internal != null && !bowl.internal.isEmpty() && bowl.internal.getFoodProperties(null)!=null) {
if (pLevel.getBlockEntity(pPos) instanceof BowlBlockEntity bowl&&bowl.getInternal() != null && !bowl.getInternal().isEmpty() && bowl.getInternal().getFoodProperties(null)!=null) {
return 15;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
import net.minecraft.world.level.block.state.BlockState;

public class BowlBlockEntity extends CPBaseBlockEntity implements IInfinitable,IFoodContainer {
public ItemStack internal=ItemStack.EMPTY;
private ItemStack internal=ItemStack.EMPTY;
public ItemStack getInternal() {
return internal;
}

boolean isInfinite = false;

public BowlBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
Expand Down Expand Up @@ -89,4 +93,12 @@ public boolean accepts(int num, ItemStack is) {
return is.getItem() instanceof StewItem||is.is(Items.BOWL);
}

public void setInternal(ItemStack internal) {
this.internal = internal;
this.syncData();
}
@Override
public boolean isInfinite() {
return isInfinite;
}
}
31 changes: 16 additions & 15 deletions src/main/java/com/teammoeg/caupona/blocks/foods/DishBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
Expand Down Expand Up @@ -88,7 +89,7 @@ public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState n
if (!(newState.getBlock() instanceof DishBlock)) {
if (worldIn.getBlockEntity(pos) instanceof DishBlockEntity dish) {

super.popResource(worldIn, pos, dish.internal);
super.popResource(worldIn, pos, dish.getInternal());
}
worldIn.removeBlockEntity(pos);
}
Expand All @@ -101,19 +102,19 @@ public InteractionResult useWithoutItem(BlockState state, Level worldIn, BlockPo
InteractionResult p = super.useWithoutItem(state, worldIn, pos, player, hit);
if (p.consumesAction())
return p;
if (worldIn.getBlockEntity(pos) instanceof DishBlockEntity dish &&dish.internal != null && dish.internal.getItem() instanceof DishItem
&& dish.internal.getFoodProperties(null)!=null) {
FoodProperties fp = dish.internal.getFoodProperties(player);
if (worldIn.getBlockEntity(pos) instanceof DishBlockEntity dish &&dish.getInternal() != null && dish.getInternal().getItem() instanceof DishItem
&& dish.getInternal().getFoodProperties(null)!=null) {
FoodProperties fp = dish.getInternal().getFoodProperties(player);
if (dish.isInfinite) {
if (player.canEat(fp.canAlwaysEat())) {
player.eat(worldIn, dish.internal.copy());
player.eat(worldIn, dish.getInternal().copy());
dish.syncData();
}
} else {
if (player.canEat(fp.canAlwaysEat())) {
ItemStack iout = player.eat(worldIn, dish.internal);
dish.internal = iout;
if (dish.internal.is(Items.BOWL)) {
ItemStack iout = player.eat(worldIn, dish.getInternal());
dish.setInternal(iout);
if (dish.getInternal().is(Items.BOWL)) {
worldIn.setBlockAndUpdate(pos, CPBlocks.DISH.get().defaultBlockState());
} else {
worldIn.removeBlock(pos, false);
Expand All @@ -131,18 +132,18 @@ public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEn
super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack);
if (pLevel.getBlockEntity(pPos) instanceof DishBlockEntity dish) {
dish.setComponents(DataComponentMap.EMPTY);
dish.internal = pStack.copyWithCount(1);
dish.setInternal(pStack.copyWithCount(1));
}
}

public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos,
Player player) {
if (level.getBlockEntity(pos) instanceof DishBlockEntity dish) {
if (dish.internal == null)
if (dish.getInternal() == null)
return ItemStack.EMPTY;
return dish.internal.copy();
return dish.getInternal().copy();
}
return this.getCloneItemStack(state, target, level, pos, player);
return super.getCloneItemStack(state, target, level, pos, player);
}

@Override
Expand All @@ -153,7 +154,7 @@ public boolean hasAnalogOutputSignal(BlockState pState) {
@Override
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
if (pLevel.getBlockEntity(pPos) instanceof DishBlockEntity dish)
if (dish.internal != null && !dish.internal.isEmpty() && dish.internal.getFoodProperties(null)!=null)
if (dish.getInternal() != null && !dish.getInternal().isEmpty() && dish.getInternal().getFoodProperties(null)!=null)
return 15;

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.minecraft.world.level.block.state.BlockState;

public class DishBlockEntity extends CPBaseBlockEntity implements IInfinitable,IFoodContainer {
public ItemStack internal = ItemStack.EMPTY;
private ItemStack internal = ItemStack.EMPTY;
boolean isInfinite = false;

public DishBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
Expand Down Expand Up @@ -94,4 +94,16 @@ public boolean accepts(int num, ItemStack is) {
return is.getItem() instanceof DishItem||is.is(Items.BOWL);
}

public ItemStack getInternal() {
return internal;
}

public void setInternal(ItemStack internal) {
this.internal = internal;
this.syncData();
}
@Override
public boolean isInfinite() {
return isInfinite;
}
}
Loading

0 comments on commit b57e9d2

Please sign in to comment.