Skip to content

Commit

Permalink
1.21-V1.131-B-004 Update
Browse files Browse the repository at this point in the history
Crashes on NeoForge, but other then that its up and running. more work is needed.
  • Loading branch information
x-j0nnay-x committed Nov 5, 2024
1 parent 1364cb7 commit 0c950ac
Show file tree
Hide file tree
Showing 97 changed files with 1,120 additions and 379 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.x_j0nnay_x.simpeladd.blocks;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.piston.MovingPistonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.x_j0nnay_x.simpeladd.core.ModTags;

import java.util.Random;

import static net.minecraft.world.level.block.SweetBerryBushBlock.AGE;

public class SimpelFarmLand extends FarmBlock {

public SimpelFarmLand() {
super(Properties.of()
.sound(SoundType.GRASS)
.strength(3.0f)
.randomTicks()
);

}

@Override
public boolean canSurvive(BlockState blockState, LevelReader levelReader, BlockPos blockPos) {
super.canSurvive(blockState, levelReader, blockPos);
BlockState blockstate = levelReader.getBlockState(blockPos.above());
if (blockstate.is(ModTags.Blocks.PLANTABLECROPS))
return true;
return !blockstate.isSolid() || blockstate.getBlock() instanceof FenceGateBlock || blockstate.getBlock() instanceof MovingPistonBlock;
}

@Override
public void fallOn(Level $$0, BlockState $$1, BlockPos $$2, Entity $$3, float $$4) {
$$3.causeFallDamage($$4, 1.0F, $$3.damageSources().fall());
}

@Override
public void tick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) {
super.tick(pState, pLevel, pPos, pRandom);
}

@Override
public void randomTick(BlockState blockState, ServerLevel level, BlockPos blockPos, RandomSource randomSource) {
super.randomTick(blockState, level, blockPos, randomSource);
for (int i = 0; i < 3; i++) {
growBlocks(level, blockPos);
// turnToFarmLand(level, blockPos);
}
}

public void turnToFarmLand(Level level, BlockPos blockPos){
int blockValue = level.getBlockState(blockPos).getValue(MOISTURE);
Random rand = new Random();
int outOfChance = 75;
int chance = rand.nextInt(outOfChance);
if(chance == 0) {
level.setBlockAndUpdate(blockPos, Blocks.FARMLAND.defaultBlockState().setValue(FarmBlock.MOISTURE, blockValue));
}
}

public void growBlocks(ServerLevel level, BlockPos blockPos){
BlockState blockState = level.getBlockState(blockPos);
if (blockState.getBlock() instanceof SimpelFarmLand) {
BlockPos cropPos = blockPos.above();
BlockState crop = level.getBlockState(cropPos);
BlockState crop1 = null;
if (crop.getBlock() instanceof CropBlock cropblock) {
if (!cropblock.isMaxAge(crop)) {
this.turnToFarmLand(level, blockPos);
crop1 = cropblock.getStateForAge(cropblock.getAge(crop) + 1);
}
} else if (crop.is(Blocks.SWEET_BERRY_BUSH) || crop.is(Blocks.NETHER_WART)) {
int bushBlock = crop.getValue(AGE);
if (bushBlock < 3) {
this.turnToFarmLand(level, blockPos);
crop1 = crop.setValue(AGE, bushBlock + 1);
}
}
if (crop1 != null) {
level.setBlockAndUpdate(cropPos, crop1);
}
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FarmBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.x_j0nnay_x.simpeladd.blocks.SimpelBlock;
import net.x_j0nnay_x.simpeladd.blocks.SimpelXPBlock;
import net.x_j0nnay_x.simpeladd.blocks.*;


public class ModBlocks {
public static final Block DEEPSLATE_DEBRI_ORE = new SimpelXPBlock(UniformInt.of(2, 6), BlockBehaviour.Properties.ofFullCopy(Blocks.DEEPSLATE_DIAMOND_ORE));
public static final Block UNOBTANIUM_ORE = new SimpelBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.DEEPSLATE_DIAMOND_ORE));
public static final FarmBlock SIMPELFARMLAND = new SimpelFarmLand();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ModItems {
public static final Item REPAIRTOOL = new SimpelRepairTool(1000);
public static final Item FIREPROOFTOOL = new SimpelFireProofTool(600);
public static final Item FEEDINGTOOL = new SimpelFeedingTool(450);
public static final Item GROWSTAFF = new GrowStaff(380);
//upgrades
public static final Item SPEEDUPGRADE_1 = new SimpelItem(new Item.Properties());
public static final Item SPEEDUPGRADE_2 = new SimpelItem(new Item.Properties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ModTags {

public static class Blocks {
public static final TagKey<Block> OBSIDIANTOOL = tag("needs_obsidiantool");
public static final TagKey<Block> PLANTABLECROPS = tag("plantablecrops");
private static TagKey<Block> tag(String name) {
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(SimpelAddMod.MOD_ID, name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ public GrinderHeadItem(int maxuses) {
}

public static ItemStack brakeItem(ItemStack itemstack) {
ItemStack retval = itemstack.copy();
retval.setDamageValue(retval.getDamageValue() + 1);
if (retval.getDamageValue() >= retval.getMaxDamage()) {
ItemStack grinder = itemstack.copy();
grinder.setDamageValue(grinder.getDamageValue() + 1);
if (grinder.getDamageValue() >= grinder.getMaxDamage()) {
return ItemStack.EMPTY;
}
return retval;
return grinder;
}

public static ItemStack getRemainderItem(ItemStack itemStack) {
return brakeItem(itemStack);
}

@Override
public boolean isValidRepairItem(ItemStack $$0, ItemStack $$1) {
Expand Down
82 changes: 82 additions & 0 deletions common/src/main/java/net/x_j0nnay_x/simpeladd/item/GrowStaff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.x_j0nnay_x.simpeladd.item;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.FarmBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.x_j0nnay_x.simpeladd.blocks.SimpelFarmLand;
import net.x_j0nnay_x.simpeladd.core.ModBlocks;
import java.util.Map;


public class GrowStaff extends Item {


private static final Map<Block, Block> FARMLAND_MAP =
Map.of(
Blocks.FARMLAND, ModBlocks.SIMPELFARMLAND
);

public GrowStaff(int maxuses){
super(new Item.Properties()
.stacksTo(1)
.durability(maxuses)
);
}
public static ItemStack damageItem(ItemStack itemstack) {
ItemStack growstaf = itemstack.copy();
if(growstaf.getDamageValue() > growstaf.getMaxDamage()){
return itemstack;
}else {
growstaf.setDamageValue(growstaf.getDamageValue() + 1);
return growstaf;
}
}

@Override
public InteractionResult useOn(UseOnContext context) {
int blockValue;
Level level = context.getLevel();
if (!level.isClientSide) {
ItemStack staf = context.getItemInHand();
BlockPos blockPos = context.getClickedPos();
BlockState blockState = context.getLevel().getBlockState(blockPos);
Block block = blockState.getBlock();
if(staf.getDamageValue() > staf.getMaxDamage()){
return InteractionResult.FAIL;
}
if (block instanceof CropBlock) {
CropBlock cropBlock = (CropBlock) block;
if (cropBlock.isMaxAge(blockState)) {
return InteractionResult.FAIL;
}
cropBlock.growCrops((ServerLevel) context.getLevel(), blockPos, blockState);
level.playSound(context.getPlayer(), blockPos, SoundEvents.BONE_MEAL_USE, SoundSource.PLAYERS, 1.0f, 1.0f);
staf.setDamageValue(staf.getDamageValue() + 1);
return InteractionResult.SUCCESS;
}

if(block instanceof FarmBlock && block != ModBlocks.SIMPELFARMLAND){
blockValue = blockState.getValue(FarmBlock.MOISTURE);
level.setBlockAndUpdate(blockPos, FARMLAND_MAP.get(block).defaultBlockState().setValue(SimpelFarmLand.MOISTURE, blockValue));
level.playSound(context.getPlayer(), blockPos, SoundEvents.HOE_TILL, SoundSource.PLAYERS, 1.0f, 1.0f);
staf.setDamageValue(staf.getDamageValue() + 3);
return InteractionResult.SUCCESS;
}

}
return InteractionResult.PASS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.x_j0nnay_x.simpeladd.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.x_j0nnay_x.simpeladd.blocks.SimpelFarmLand;
import net.x_j0nnay_x.simpeladd.core.ModBlocks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(CropBlock.class)
public class CropBlockMixin {

@Inject(method = "mayPlaceOn", at = @At("HEAD"), cancellable = true)
protected void mayPlaceOn(BlockState $$0, BlockGetter $$1, BlockPos $$2, CallbackInfoReturnable<Boolean> cir) {
// if ($$0.is(ModBlocks.SIMPELFARMLAND)) {
// cir.setReturnValue(true);
// }
if ($$0.getBlock() instanceof SimpelFarmLand){
cir.setReturnValue(true);
}
}

@Inject(method = "getGrowthSpeed", at = @At("HEAD"), cancellable = true)
private static void getGrowthSpeed(Block $$0, BlockGetter $$1, BlockPos $$2, CallbackInfoReturnable<Float> cir) {
float flot1 = 1.0F;
BlockPos blockPos = $$2.below();
for (int i1 = -1; i1 <= 1; ++i1) {
for (int i2 = -1; i2 <= 1; ++i2) {
float flot2 = 0.0F;
BlockState $$8 = $$1.getBlockState(blockPos.offset(i1, 0, i2));
if ($$8.is(ModBlocks.SIMPELFARMLAND)) {
flot2 = 3.0F;
}

if (i1 != 0 || i2 != 0) {
flot2 /= 4.0F;
}

flot1 += flot2;
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.x_j0nnay_x.simpeladd.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.NetherWartBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.x_j0nnay_x.simpeladd.blocks.SimpelFarmLand;
import net.x_j0nnay_x.simpeladd.core.ModBlocks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(NetherWartBlock.class)
public class NetherWartMixin {

@Inject(method = "mayPlaceOn", at = @At("HEAD"), cancellable = true)
protected void mayPlaceOn(BlockState $$0, BlockGetter $$1, BlockPos $$2, CallbackInfoReturnable<Boolean> cir) {
// if($$0.is(ModBlocks.SIMPELFARMLAND)){
// cir.setReturnValue(true);
// }
if ($$0.getBlock() instanceof SimpelFarmLand){
cir.setReturnValue(true);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public NonNullList<ItemStack> getRemainingItems(CraftingInput $$0) {
for(int $$2 = 0; $$2 < $$1.size(); ++$$2) {
Item $$3 = $$0.getItem($$2).getItem();
if ($$3.getDefaultInstance().is(ModTags.Items.GRINDERS)) {
$$1.set($$2, GrinderHeadItem.getRemainderItem(grinder));
$$1.set($$2, GrinderHeadItem.brakeItem(grinder));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"variants": {
"moisture=0": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=1": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=2": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=3": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=4": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=5": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=6": {
"model": "simpeladdmod:block/simpel_farmland"
},
"moisture=7": {
"model": "simpeladdmod:block/simpel_farmland_moist"
}
}
}
Loading

0 comments on commit 0c950ac

Please sign in to comment.