Skip to content

Commit

Permalink
Further porting of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Aug 19, 2024
1 parent d601821 commit 7e71e6a
Show file tree
Hide file tree
Showing 57 changed files with 842 additions and 771 deletions.
1 change: 0 additions & 1 deletion src/main/java/cf/witcheskitchen/api/WKApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cf.witcheskitchen.api;

import cf.witcheskitchen.api.entity.WKCreatureTypeEnum;
import cf.witcheskitchen.common.item.TaglockItem;
import cf.witcheskitchen.common.registry.WKTags;
import net.minecraft.entity.EntityGroup;
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/cf/witcheskitchen/api/block/crop/WKCropBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cf.witcheskitchen.api.block.crop;

import cf.witcheskitchen.common.component.WKComponents;
import cf.witcheskitchen.common.component.item.SeedTypeData;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.CropBlock;
Expand All @@ -9,14 +11,13 @@
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.random.RandomGenerator;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos)
* @return The current age at the given crop BlockState
*/
@Override
protected int getAge(BlockState state) {
public int getAge(BlockState state) {
return super.getAge(state);
}

Expand Down Expand Up @@ -169,7 +170,7 @@ public boolean isMature(BlockState state) {
* </p>
* <p>
* This is triggered in {@link ServerWorld#tickChunk(WorldChunk, int)} and
* if this returns false, {@link WKCropBlock#randomTick(BlockState, ServerWorld, BlockPos, RandomGenerator)}
* if this returns false, {@link WKCropBlock#randomTick(BlockState, ServerWorld, BlockPos, Random)}
* will never get executed.
* </p>
*/
Expand All @@ -194,13 +195,13 @@ public boolean hasRandomTicks(BlockState state) {
* </p>
*/
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, RandomGenerator random) {
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.randomTick(state, world, pos, random);
}

/**
* Updates the crop {@link BlockState}, by checking {@link CropBlock#getAge(BlockState)} is < {@link CropBlock#getMaxAge()}.
* <strong>NOTE:</strong> THIS METHOD IS ONLY TRIGGERED BY {@link WKCropBlock#grow(ServerWorld, RandomGenerator, BlockPos, BlockState)}
* <strong>NOTE:</strong> THIS METHOD IS ONLY TRIGGERED BY {@link WKCropBlock#grow(ServerWorld, Random, BlockPos, BlockState)}
*/
@Override
public void applyGrowth(World world, BlockPos pos, BlockState state) {
Expand All @@ -210,14 +211,14 @@ public void applyGrowth(World world, BlockPos pos, BlockState state) {

/**
* <p>
* This method is a filter for {@link #grow(ServerWorld, RandomGenerator, BlockPos, BlockState)} and the BoneMeal grow method.
* This method is a filter for {@link #grow(ServerWorld, Random, BlockPos, BlockState)} and the BoneMeal grow method.
* It is only used by {@link net.minecraft.item.BoneMealItem#useOnFertilizable(ItemStack, World, BlockPos)},
* although when extending this class it will also be triggered by {@link #grow(ServerWorld, RandomGenerator, BlockPos, BlockState)}.
* although when extending this class it will also be triggered by {@link #grow(ServerWorld, Random, BlockPos, BlockState)}.
* </p>
* It is always returning true by the parent class unless overridden.
*/
@Override
public boolean canGrow(World world, RandomGenerator random, BlockPos pos, BlockState state) {
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
return super.canGrow(world, random, pos, state);
}

Expand All @@ -233,7 +234,7 @@ public boolean canGrow(World world, RandomGenerator random, BlockPos pos, BlockS
* {@link BeeEntity.GrowCropsGoal#tick()}
*/
@Override
public void grow(ServerWorld world, RandomGenerator random, BlockPos pos, BlockState state) {
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
if (canGrow(world, random, pos, state)) {
super.grow(world, random, pos, state);
}
Expand Down Expand Up @@ -269,15 +270,15 @@ protected ItemConvertible getSeedsItem() {
}

@Override
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
return getSeedsItemStack();
}

protected abstract ItemStack getSeedsItemStack();

public void getNextSeed(World world, BlockPos pos, NbtCompound nbtCompound) {
public void getNextSeed(World world, BlockPos pos, SeedTypeData data) {
ItemStack itemStack2 = getSeedsItemStack();
itemStack2.getOrCreateNbt().copyFrom(nbtCompound);
itemStack2.set(WKComponents.SEED_TYPE, data);
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), itemStack2);
}
}
19 changes: 0 additions & 19 deletions src/main/java/cf/witcheskitchen/api/entity/WKCreatureTypeEnum.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/cf/witcheskitchen/api/fluid/FluidTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public boolean isEmpty() {
/**
* @return Current {@link FluidStack} in the tank
*/
@Nonnull
@NotNull
public FluidStack getStack() {
return stack;
}
Expand Down
47 changes: 12 additions & 35 deletions src/main/java/cf/witcheskitchen/api/util/SeedTypeHelper.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cf.witcheskitchen.api.util;

import cf.witcheskitchen.common.component.WKComponents;
import cf.witcheskitchen.common.component.item.SeedTypeData;
import cf.witcheskitchen.common.registry.WKBlocks;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
Expand All @@ -16,17 +15,14 @@
public class SeedTypeHelper {

/**
* Gets the block corresponding to the present nbt
* Gets the block corresponding to the present data
*
* @param nbt the nbt to test for a block
* @param data the data to test for a block
* @return optional block depending on if the nbt was valid for a block to be returned
*/
public static Optional<Block> getBlockFromNbt(NbtCompound nbt) {
NbtList nbtList = nbt.getList("Variant", NbtElement.COMPOUND_TYPE);
if (!nbtList.isEmpty()) {
NbtCompound nameNbt = nbtList.getCompound(0);
NbtCompound typeNbt = nbtList.getCompound(1);
String fullName = nameNbt.getString("Name") + "_" + typeNbt.getString("Type");
public static Optional<Block> getBlockFromComponent(SeedTypeData data) {
if (data != null) {
String fullName = data.getBlockId();
for (Map.Entry<String, Block> entry : WKBlocks.getTypeBlocks().entrySet()) {
String nameMap = entry.getKey();
Block blockMap = entry.getValue();
Expand All @@ -38,33 +34,14 @@ public static Optional<Block> getBlockFromNbt(NbtCompound nbt) {
return Optional.empty();
}

public static NbtCompound toNbt(NbtCompound nbt, String plantName, String typeName, int variantColor) {
NbtList list = new NbtList();

NbtCompound name = new NbtCompound();
name.putString("Name", plantName);
NbtCompound type = new NbtCompound();
type.putString("Type", typeName);
NbtCompound color = new NbtCompound();
color.putInt("Color", variantColor);

list.add(name);
list.add(type);
list.add(color);

nbt.put("Variant", list);
return nbt;
public static SeedTypeData toComponent(String plantName, String typeName, int variantColor) {
return new SeedTypeData(plantName, typeName, variantColor);
}

public static MutableText getSeedTypeText(ItemStack stack) {

NbtList nbtList = stack.getOrCreateNbt().getList("Variant", NbtElement.COMPOUND_TYPE);
if (!nbtList.isEmpty() && !nbtList.getCompound(1).isEmpty() && !nbtList.getCompound(2).isEmpty()) {
String name = nbtList.getCompound(1).getString("Type");
String formatName = TextUtils.capitalizeString(name);
NbtCompound colorNbt = nbtList.getCompound(2);
int color = colorNbt.getInt("Color");
return Text.translatable(formatName).setStyle(Style.EMPTY.withColor(color));
if (stack.contains(WKComponents.SEED_TYPE)) {
var seedType = stack.get(WKComponents.SEED_TYPE);
return Text.translatable(TextUtils.capitalizeString(seedType.type())).setStyle(Style.EMPTY.withColor(seedType.color()));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite()).with(Properties.WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite()).with(Properties.WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.random.RandomGenerator;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public class CopperTeapotBlock extends TeapotBlock implements Oxidizable {
private final Oxidizable.OxidizationLevel oxidizationLevel;
private final Oxidizable.OxidationLevel oxidizationLevel;

public CopperTeapotBlock(Settings settings, Oxidizable.OxidizationLevel oxidizationLevel) {
public CopperTeapotBlock(Settings settings, Oxidizable.OxidationLevel oxidizationLevel) {
super(settings);
this.oxidizationLevel = oxidizationLevel;
}

@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, RandomGenerator random) {
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
this.tickDegradation(state, world, pos, random);
}

Expand All @@ -43,7 +43,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}

@Override
public OxidizationLevel getDegradationLevel() {
public OxidationLevel getDegradationLevel() {
return this.oxidizationLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.random.RandomGenerator;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public class CopperWitchesOvenBlock extends WitchesOvenBlock implements Oxidizable {
private final Oxidizable.OxidizationLevel oxidizationLevel;
private final Oxidizable.OxidationLevel oxidizationLevel;

public CopperWitchesOvenBlock(Settings settings, Oxidizable.OxidizationLevel oxidizationLevel) {
public CopperWitchesOvenBlock(Settings settings, Oxidizable.OxidationLevel oxidizationLevel) {
super(settings);
this.oxidizationLevel = oxidizationLevel;
}

@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, RandomGenerator random) {
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
this.tickDegradation(state, world, pos, random);
}

Expand All @@ -43,7 +43,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}

@Override
public OxidizationLevel getDegradationLevel() {
public OxidationLevel getDegradationLevel() {
return this.oxidizationLevel;
}
}
5 changes: 2 additions & 3 deletions src/main/java/cf/witcheskitchen/common/block/GlyphBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -38,11 +37,11 @@ public GlyphBlock(Settings settings) {
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (world.getBlockEntity(pos) instanceof GlyphBlockEntity be) {
be.onUse(world, state, pos, player, hit);
}
return super.onUse(state, world, pos, player, hand, hit);
return super.onUse(state, world, pos, player, hit);
}

@Nullable
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/cf/witcheskitchen/common/block/SaltBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -28,7 +27,6 @@
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;

import java.util.Iterator;
import java.util.Map;
Expand All @@ -48,7 +46,7 @@ public class SaltBlock extends Block {

private final BlockState dotState;

public SaltBlock(QuiltBlockSettings settings) {
public SaltBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(WIRE_CONNECTION_NORTH, WireConnection.NONE).with(WIRE_CONNECTION_EAST, WireConnection.NONE).with(WIRE_CONNECTION_SOUTH, WireConnection.NONE).with(WIRE_CONNECTION_WEST, WireConnection.NONE));
this.dotState = this.getDefaultState().with(WIRE_CONNECTION_NORTH, WireConnection.SIDE).with(WIRE_CONNECTION_EAST, WireConnection.SIDE).with(WIRE_CONNECTION_SOUTH, WireConnection.SIDE).with(WIRE_CONNECTION_WEST, WireConnection.SIDE);
Expand Down Expand Up @@ -154,7 +152,7 @@ public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos
if (spiritual && !WKApi.isGreaterDemon(livingEntity)) {
boolean onSalt = world.getBlockState(livingEntity.getBlockPos().add(0, 0, 0)).getBlock() instanceof SaltBlock;
if (!onSalt) {
return getSaltShape(livingEntity.stepHeight);
return getSaltShape(livingEntity.getStepHeight());
} else {
livingEntity.setOnFireFor(1);
}
Expand Down Expand Up @@ -343,7 +341,7 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (player.getAbilities().allowModifyWorld) {
if (isFullyConnected(state) || isNotConnected(state)) {
BlockState blockState = isFullyConnected(state) ? this.getDefaultState() : this.dotState;
Expand Down
Loading

0 comments on commit 7e71e6a

Please sign in to comment.