Something something porting go brr...

This commit is contained in:
Flanks255 2024-07-22 18:42:48 -05:00
parent ac320235a2
commit 98ef8e8332
6 changed files with 42 additions and 41 deletions

View file

@ -6,7 +6,7 @@ mod_version=1.2.14
# Forge # Forge
game_version=1.21 game_version=1.21
neo_version=21.0.76-beta neo_version=21.0.79-beta
# mods.toml # mods.toml
loader=4 loader=4

View file

@ -28,7 +28,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.common.PlantType;
import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.ItemHandlerHelper;
import java.util.List; import java.util.List;
@ -52,10 +51,10 @@ public class BlockPlant extends CropBlock {
// this.returnMeta = returnMeta; // this.returnMeta = returnMeta;
} }
@Override /* @Override
public PlantType getPlantType(BlockGetter world, BlockPos pos) { public PlantType getPlantType(BlockGetter world, BlockPos pos) {
return PlantType.CROP; return PlantType.CROP;
} }*/
// //
// @Override // @Override
// public int damageDropped(BlockState state) { // public int damageDropped(BlockState state) {

View file

@ -9,14 +9,15 @@ import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantment;
import net.neoforged.neoforge.common.ItemAbilities; import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.common.ToolAction; import net.neoforged.neoforge.common.ItemAbility;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
public class AllInOneTool extends DiggerItem { public class AllInOneTool extends DiggerItem {
private final Tier tier; private final Tier tier;
private static List<ToolAction> ACTIONS = List.of( private static List<ItemAbility> ACTIONS = List.of(
ItemAbilities.AXE_DIG, ItemAbilities.AXE_DIG,
ItemAbilities.HOE_DIG, ItemAbilities.HOE_DIG,
ItemAbilities.PICKAXE_DIG, ItemAbilities.PICKAXE_DIG,
@ -28,8 +29,8 @@ public class AllInOneTool extends DiggerItem {
public AllInOneTool(Tier tier) { public AllInOneTool(Tier tier) {
super( super(
4.0f, /* 4.0f,
-2f, -2f,*/
tier, tier,
ActuallyTags.Blocks.MINEABLE_WITH_AIO, ActuallyTags.Blocks.MINEABLE_WITH_AIO,
new Properties() new Properties()
@ -41,12 +42,13 @@ public class AllInOneTool extends DiggerItem {
} }
@Override @Override
public boolean canPerformAction(ItemStack stack, ToolAction toolAction) { public boolean canPerformAction(@Nonnull ItemStack stack, @Nonnull ItemAbility toolAction) {
if (ACTIONS.contains(toolAction)) if (ACTIONS.contains(toolAction))
return true; return true;
return super.canPerformAction(stack, toolAction); return super.canPerformAction(stack, toolAction);
} }
@Nonnull
@Override @Override
public InteractionResult useOn(UseOnContext context) { public InteractionResult useOn(UseOnContext context) {
// How, no idea, possible, most likely :cry: // How, no idea, possible, most likely :cry:
@ -64,8 +66,8 @@ public class AllInOneTool extends DiggerItem {
return Items.IRON_HOE.useOn(context); return Items.IRON_HOE.useOn(context);
} }
@Override /* @Override //TODO help, enchantments are weird now.
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment.category.canEnchant(Items.DIAMOND_SWORD); return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment.category.canEnchant(Items.DIAMOND_SWORD);
} }*/
} }

View file

@ -37,7 +37,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.common.IPlantable; import net.neoforged.neoforge.common.SpecialPlantable;
import net.neoforged.neoforge.common.util.FakePlayerFactory; import net.neoforged.neoforge.common.util.FakePlayerFactory;
import java.util.ArrayList; import java.util.ArrayList;
@ -148,10 +148,10 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
} }
private BlockState getPlantablePlantFromStack(ItemStack stack, Level world, BlockPos pos) { private BlockState getPlantablePlantFromStack(ItemStack stack, Level world, BlockPos pos) {
if (StackUtil.isValid(stack)) { if (!stack.isEmpty()) {
IPlantable plantable = this.getPlantableFromStack(stack); SpecialPlantable plantable = this.getPlantableFromStack(stack);
if (plantable != null) { if (plantable != null) {
BlockState state = plantable.g(world, pos); BlockState state = plantable.getPlantType(world, pos);
if (state != null && state.getBlock() instanceof BonemealableBlock) { if (state != null && state.getBlock() instanceof BonemealableBlock) {
return state; return state;
} }
@ -160,14 +160,14 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
return null; return null;
} }
private IPlantable getPlantableFromStack(ItemStack stack) { private SpecialPlantable getPlantableFromStack(ItemStack stack) {
Item item = stack.getItem(); Item item = stack.getItem();
if (item instanceof IPlantable) { if (item instanceof SpecialPlantable plantable) {
return (IPlantable) item; return plantable;
} else if (item instanceof BlockItem) { } else if (item instanceof BlockItem) {
Block block = Block.byItem(item); Block block = Block.byItem(item);
if (block instanceof IPlantable) { if (block instanceof SpecialPlantable plantable) {
return (IPlantable) block; return plantable;
} }
} }
return null; return null;

View file

@ -27,7 +27,6 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.common.IPlantable;
import java.util.List; import java.util.List;

View file

@ -40,6 +40,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemDisplayContext;
@ -59,7 +60,7 @@ public final class AssetUtil {
public static final int MAX_LIGHT_Y = 0xF000F0; public static final int MAX_LIGHT_Y = 0xF000F0;
public static final ResourceLocation GUI_INVENTORY_LOCATION = getGuiLocation("gui_inventory"); public static final ResourceLocation GUI_INVENTORY_LOCATION = getGuiLocation("gui_inventory");
private static final ResourceLocation FORGE_WHITE = ResourceLocation.tryParse("forge", "white"); private static final ResourceLocation FORGE_WHITE = ResourceLocation.tryBuild("forge", "white");
public static ResourceLocation getGuiLocation(String file) { public static ResourceLocation getGuiLocation(String file) {
return ActuallyAdditions.modLoc("textures/gui/" + file + ".png"); return ActuallyAdditions.modLoc("textures/gui/" + file + ".png");
@ -224,7 +225,7 @@ public final class AssetUtil {
// GlStateManager._popMatrix(); // GlStateManager._popMatrix();
// } // }
public static void spawnLaserWithTimeServer(Level world, double startX, double startY, double startZ, double endX, double endY, double endZ, int color, int maxAge, double rotationTime, float size, float alpha) { public static void spawnLaserWithTimeServer(ServerLevel world, double startX, double startY, double startZ, double endX, double endY, double endZ, int color, int maxAge, double rotationTime, float size, float alpha) {
if (!world.isClientSide) { if (!world.isClientSide) {
CompoundTag data = new CompoundTag(); CompoundTag data = new CompoundTag();
data.putDouble("StartX", startX); data.putDouble("StartX", startX);
@ -238,7 +239,7 @@ public final class AssetUtil {
data.putFloat("Size", size); data.putFloat("Size", size);
data.putInt("MaxAge", maxAge); data.putInt("MaxAge", maxAge);
data.putFloat("Alpha", alpha); data.putFloat("Alpha", alpha);
PacketDistributor.NEAR.with(new PacketDistributor.TargetPoint(startX, startY, startZ, 96, world.dimension())).send(new PacketServerToClient(data, PacketHandler.LASER_HANDLER)); PacketDistributor.sendToPlayersNear(world, null, startX, startY, startZ, 96, new PacketServerToClient(data, PacketHandler.LASER_HANDLER));
} }
} }
@ -292,25 +293,25 @@ public final class AssetUtil {
for (int i = 1; i < 4; i++) { for (int i = 1; i < 4; i++) {
float width = beamWidth * (i / 4.0f); float width = beamWidth * (i / 4.0f);
//top //top
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, width, 0.0f).setColor(r, g, b, a).setUv(minU, maxV).setLight(lightmap);//.endVertex(); //TODO ?!
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);//.endVertex();
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, width, -length).setColor(r, g, b, a).setUv(maxU, minV).setLight(lightmap);
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
//bottom //bottom
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(minU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, -width, 0.0f).setColor(r, g, b, a).setUv(minU, maxV).setLight(lightmap);
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, -width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(maxU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, -width, -length).setColor(r, g, b, a).setUv(maxU, minV).setLight(lightmap);
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, -width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);
//left //left
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, -width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, -width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, -width, width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
//right //right
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv(maxU, maxV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, -width, 0.0f).setColor(r, g, b, a).setUv(maxU, maxV).setLight(lightmap);
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, -width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv(minU, minV).uv2(lightmap).endVertex(); builder.addVertex(matrix, width, width, -length).setColor(r, g, b, a).setUv(minU, minV).setLight(lightmap);
} }
@ -362,7 +363,7 @@ public final class AssetUtil {
Matrix4f matrix = matrixStack.last().pose(); Matrix4f matrix = matrixStack.last().pose();
RenderSystem.setShader(GameRenderer::getPositionColorLightmapShader); RenderSystem.setShader(GameRenderer::getPositionColorLightmapShader);
Tesselator.getInstance().getBuilder().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP); Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP);
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(FORGE_WHITE); TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(FORGE_WHITE);
float minU = sprite.getU0(); float minU = sprite.getU0();